DFP with Google App Engine

See the code
*************************************************************************************
package com.lin.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.logging.Logger;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.api.ads.common.lib.exception.ValidationException;
import com.google.api.ads.dfp.appengine.oauth.CredentialException;
import com.google.api.ads.dfp.jaxws.factory.DfpServices;
import com.google.api.ads.dfp.jaxws.v201302.ApiException_Exception;
import com.google.api.ads.dfp.jaxws.v201302.Network;
import com.google.api.ads.dfp.jaxws.v201302.NetworkServiceInterface;
import com.google.api.ads.dfp.lib.client.DfpSession;
import com.lin.web.util.ClientLoginAuth;
import com.lin.web.util.LinMobiileProperties;
import com.lin.web.util.LinMobileConstants;


@SuppressWarnings("serial")
public class DfpV302Servlet extends HttpServlet {
 
  private static final Logger log = Logger.getLogger(DfpV302Servlet.class.getName());
  
  private String clientLoginToken = null;

 public void init(ServletConfig config) throws ServletException {
      super.init(config);     
      try {
        clientLoginToken = regenerateAuthToken();
        log.info(" clientLoginToken : "+clientLoginToken);
      } catch (Exception exception) {
       log.severe("init(), Exception.."+exception);
       exception.printStackTrace();        
      }
 }
 

  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException {
     log.info("started.......");
     PrintWriter out=resp.getWriter();
     resp.setContentType("text/plain");
     out.println("============================================================");
     
     try {
   log.info("going to make DfpSession instance...");
   DfpSession session = new DfpSession.Builder()
     .withClientLoginToken(clientLoginToken)     
     .withNetworkCode(LinMobileConstants.DFP_NETWORK_CODE)
     .build();
   System.out.println("session:"+session.getNetworkCode());
   log.info("going to make DfpServices instance...");
   DfpServices dfpServices = new DfpServices();
   
   log.info("going to make networkService instance...");
   
   log.info("loading networks.......");
   List<Network> networks = loadNetworks(dfpServices, session);
      
      for (Network network : networks) {
       out.println(
            "Network with network code"+network.getNetworkCode()+"  and display name "+
             network.getDisplayName());
      }
   
      log.warning("done....");
   
  } catch (ValidationException e) {
   log.severe("ValidationException :"+e.getMessage());
   e.printStackTrace();
  } catch (ApiException_Exception e) {
   log.severe("ApiException_Exception:"+e.getMessage());
   e.printStackTrace();
  } catch (CredentialException e) {
   log.severe("CredentialException:"+e.getMessage());
   e.printStackTrace();
  }

  out.println("============================================================");
  }
  
  private List<Network> loadNetworks(DfpServices dfpServices,DfpSession session) throws ValidationException, ApiException_Exception,
  CredentialException{   
   NetworkServiceInterface networkService =
         dfpServices.get(session, NetworkServiceInterface.class);
 log.info("Fetching networks.......");
 List<Network> networks = networkService.getAllNetworks();
 return networks;
  }
  public String regenerateAuthToken() throws Exception {
   String clientLoginToken=LinMobiileProperties.getAuthToken();
   if(clientLoginToken ==null){
    ClientLoginAuth clientLoginAuth = new ClientLoginAuth(LinMobileConstants.EMAIL_ADDRESS, LinMobileConstants.EMAIL_PASSWORD);
    clientLoginToken =clientLoginAuth.getAuthToken();
    LinMobiileProperties.setAuthToken(clientLoginToken);
   }     
     return clientLoginToken;
 }
  
}

*************************************************************************************

See error comes at line:(List<Network> networks = networkService.getAllNetworks();)

***************************************************************************
Jun 26, 2013 10:50:57 AM com.lin.web.servlet.DfpV302Servlet doGet
INFO: going to make networkService instance...
Jun 26, 2013 10:50:57 AM com.lin.web.servlet.DfpV302Servlet doGet
INFO: loading networks.......
Jun 26, 2013 10:51:04 AM com.lin.web.servlet.DfpV302Servlet loadNetworks
INFO: Fetching networks.......
Jun 26, 2013 10:51:04 AM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: Error for /dfpLatest.do
java.lang.AbstractMethodError: com.google.api.ads.common.lib.soap.jaxws.JaxWsHandler.putAllHttpHeaders(Ljava/lang/Object;Ljava/util/Map;)V
 at com.google.api.ads.dfp.lib.soap.DfpHttpHeaderHandler.setHttpHeaders(DfpHttpHeaderHandler.java:53)
 at com.google.api.ads.dfp.jaxws.DfpJaxWsHeaderHandler.setHeaders(DfpJaxWsHeaderHandler.java:86)
 at com.google.api.ads.dfp.jaxws.DfpJaxWsHeaderHandler.setHeaders(DfpJaxWsHeaderHandler.java:1)
 at com.google.api.ads.common.lib.client.AdsServiceClient.setHeaders(AdsServiceClient.java:111)
 at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:92)
 at $Proxy55.getAllNetworks(Unknown Source)
 at com.lin.web.servlet.DfpV302Servlet.loadNetworks(DfpV302Servlet.java:112)
 at com.lin.web.servlet.DfpV302Servlet.doGet(DfpV302Servlet.java:83)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
 at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
 at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
 at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
 at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
 at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
 at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
 at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
 at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 at com.google.appengine.tools.development.DevAppServerServersFilter.doDirectRequest(DevAppServerServersFilter.java:369)
 at com.google.appengine.tools.development.DevAppServerServersFilter.doDirectServerRequest(DevAppServerServersFilter.java:352)
 at com.google.appengine.tools.development.DevAppServerServersFilter.doFilter(DevAppServerServersFilter.java:115)
 at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
 at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
 at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
 at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
 at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
 at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
 at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
 at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:438)
 at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
 at org.mortbay.jetty.Server.handle(Server.java:326)
 at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
 at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
 at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
 at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
 at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
 at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
 at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
--------------------------------------------------------------------------------------------------------

Popular posts from this blog

Android: where to run keytool command in android

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Upload file on Google cloud storage using Java servlet on google app engine