We are excited to start discussing how to use the DFP API  from within the Google App Engine  (Java) environment. This first blog post in the series focuses on setting up your environment and understanding how to use the API from App Engine. Future posts in this series will build upon the same project to create a sample application. Ultimately, you will be able to make DFP information more accessible within your organization, while also leveraging the ease of scale and deployability that comes with creating applications on Google App Engine.
Setting up your environment here . If you prefer a different environment setup, you can always view the Getting Started Guide for App Engine  for more information.Create an App Engine project 
Note: If you would like to download all of the source code in this blog post to follow along you can do so as a tarball  or you can browse the code base from our svn repository .
Dependencies client library . You’ll need to download this client login auth file  to help with authentication. Place this file in your project’s src directory. Next, you’ll need a jar  and a wsdl  file that we’ve compiled with JAX-WS; place them in the WEB-INF/lib and WEB-INF directory, respectively. See the files highlighted in their respective locations below.
Write some code 
  /**
   * Perform initialization of servlet and cached resources used to
   * access DFP API.
   */
  @Override
  public void init(ServletConfig config) throws ServletException {
    super.init(config);
    // Generate an authToken.
    try {
      authToken = regenerateAuthToken();
    } catch (Exception exception) {
      throw new ServletException("Could not generate an Auth Token.",
          exception);
    }
  }
  /**
   * Regenerate the client login auth token that the servlet uses.
   * 
   * @throws Exception
   */
  public synchronized String regenerateAuthToken() throws Exception {
    ClientLoginAuth clientLoginAuth = new ClientLoginAuth(EMAIL_ADDRESS, 
        EMAIL_ADDRESS_PASSWORD);
    return clientLoginAuth.getAuthToken();
  }
 
This next snippet of code handles the actual web browser requests.
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) 
      throws ServletException {
    try {
      // Retrieve an object handle to our network service.
      NetworkService networkService = new NetworkService();
      NetworkServiceInterface networkServiceInterface =
          networkService.getNetworkServiceInterfacePort();
      // Prepare header object to make server call
      SoapRequestHeader requestHeader = new SoapRequestHeader();
      requestHeader.setApplicationName("Hello World");
      ClientLogin clientLogin = new ClientLogin();
      clientLogin.setToken(authToken);
      requestHeader.setAuthentication(clientLogin);
      // Make protected call to the server.
      String rootAdUnitId = "";
      Network currentNetwork = networkServiceInterface.getCurrentNetwork(
          requestHeader, null);
      // Extract data from object returned from server.
      rootAdUnitId = currentNetwork.getEffectiveRootAdUnitId();
      resp.setContentType("text/plain");
      resp.getWriter().println("Hello, world. Your root ad unit id is: "
          + rootAdUnitId);
    } catch (Exception e) {
      // Perform exception handling.
      e.printStackTrace();
      throw new ServletException("Error occurred. Check logs for specific "
          " details about the error.");
    }
  }
 
This particular code snippet retrieves the root ad unit for our network whenever someone accesses the application. You can view the full sample servlet code here .Testing http://localhost:8888/ ). Clicking on this link and then the subsequent servlet link should return a page similar to this.
Next Time Troubleshooting sample code .
Let us know  if you have any questions, and happy holidays!
Paul Rashidi , DFP API Team