Base64DecoderException error google app engine

Hi I am getting this error in google app engine:

HTTP ERROR 500

Problem accessing /uploadtest. Reason:

com/google/gdata/util/common/util/Base64DecoderException

Caused by:

java.lang.NoClassDefFoundError: com/google/gdata/util/common/util/Base64DecoderException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
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:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
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.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:351)
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)

Caused by: java.lang.ClassNotFoundException: com.google.gdata.util.common.util.Base64DecoderException at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:176) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 37 more Caused by:

java.lang.ClassNotFoundException: com.google.gdata.util.common.util.Base64DecoderException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:176)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getConstructor0(Class.java:2699)
    at java.lang.Class.newInstance0(Class.java:326)
    at java.lang.Class.newInstance(Class.java:308)
    at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
    at org.mortbay.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:339)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
    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:122)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
    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.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:351)
    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)
Powered by Jetty://

This is my code in UploadTest.java:

package sharepro.java.todo;


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.spec.EncodedKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;


import java.io.IOException;

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


//import com.google.appengine.repackaged.com.google.common.util.Base64DecoderException;
//import com.google.appengine.repackaged.com.google.common.util.Base64;
import com.google.gdata.client.authn.oauth.GoogleOAuthHelper;
import com.google.gdata.client.authn.oauth.GoogleOAuthParameters;
import com.google.gdata.client.authn.oauth.OAuthRsaSha1Signer;
import com.google.gdata.util.common.util.Base64;
import com.google.gdata.util.common.util.Base64DecoderException;

@SuppressWarnings("serial")
public class Uploadtest extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws IOException {
     String CONSUMER_KEY = "shareject.appspot.com";

     resp.setContentType("text/html");
     resp.getWriter().println("Hello 1, we will use the following consumer key to obtain a OAuth Access Token:<br>" + CONSUMER_KEY);

     GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
     oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
     oauthParameters.setScope("https://docs.google.com/feeds/");
     oauthParameters.setOAuthCallback("http://shareject.appspot.com/UpgradeToken");
     //Update the above URL to match the domain name for your App Engine application
     System.out.print("sundi ");
     PrivateKey privKey = null;
    try {
        privKey = getPrivateKey("WEB-INF/rsakey.pk8");
    } catch (com.google.gdata.util.common.util.Base64DecoderException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

     //resp.getWriter().println(privKey.toString());

     GoogleOAuthHelper oauthHelper = null;
     try {

     oauthHelper = new GoogleOAuthHelper(new OAuthRsaSha1Signer(privKey));
     oauthHelper.getUnauthorizedRequestToken(oauthParameters);
     }
     catch (Exception e){
     resp.getWriter().println(e.toString());
     }

     String approvalPageUrl = oauthHelper.createUserAuthorizationUrl(oauthParameters);
     resp.getWriter().println("<br><br><br>");
     resp.getWriter().println("<a href="" + approvalPageUrl + "">Retrieve an OAuth Token</a>");



     /*resp.getWriter().println("<br><br><br>");
     resp.getWriter().println("<a href="" + CONSUMER_KEY+ "">Retrieve an OAuth Token</a>");*/


    }

    private PrivateKey getPrivateKey(String privKeyFilename) throws com.google.gdata.util.common.util.Base64DecoderException {
        // TODO Auto-generated method stub
          FileInputStream keyfis = null;
          try {
          keyfis = new FileInputStream(privKeyFilename);
          } catch (FileNotFoundException e2) {
          e2.printStackTrace();
          }
          byte[] encKey = null;
          try {
          encKey = new byte[keyfis.available()];
          } catch (IOException e3) {
          e3.printStackTrace();
          }
          try {
          keyfis.read(encKey);
          } catch (IOException e2) {
          e2.printStackTrace();
          }
          try {
          keyfis.close();
          } catch (IOException e2) {
          e2.printStackTrace();
          }

          PrivateKey privKey = null;
          KeyFactory keyFactory = null;

          String str = new String(encKey);


          String BEGIN = "-----BEGIN PRIVATE KEY-----";
          String END = "-----END PRIVATE KEY-----";

          if (str.contains(BEGIN) && str.contains(END)) {
              str = str.substring(BEGIN.length(), str.lastIndexOf(END));
          }


          KeyFactory fac = null;
          try {
          fac = KeyFactory.getInstance("RSA");
          } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
          }
          EncodedKeySpec privKeySpec = null;

          System.out.print("sundi debug 99");
         // privKeySpec = new PKCS8EncodedKeySpec(com.google.gdata.util.common.util.Base64.decode(str));
          try {
            privKeySpec = new PKCS8EncodedKeySpec(Base64.decode(str));
        } catch (Base64DecoderException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
          try {
          privKey = fac.generatePrivate(privKeySpec);
          } catch (InvalidKeySpecException e) {
          e.printStackTrace();
          } 

          return privKey;

    }

    public void doPost(HttpServletRequest req, HttpServletResponse resp){



    }




}

Please help me in resolving the same...Thanks Sundi


Ok. I might have been a bit harsh, but whenever you post questions on any forum, try to make it easy to read. It's ok to post the whole stack trace and code but you should accompany it with a quick summary and what you tried so far. I bet you would have gotten much better responses if you did that (note the downvotes and close votes you got. At least a few feel the same way, apparently).

Anyways, the reason you are not finding solution via google is probably because you are focused on Base64DecoderException . Had you googled "ClassNotFoundException jetty" you might have found a solution.

What does "ClassNotFoundException" mean? It means, The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found

As you say you correctly imported this class, but to put it bluntly, you are not giving the jar file for this class to the JVM when you are booting up jetty. In other words, make sure you include the jar for this class when you build your war.

If you feel super lazy and want this error to go away immediately, you can download the jar here and put this under $jetty.home/lib . This is however usually considered a bad practice. Correct/accepted way of solving this is to include necessary jars in the war file.

链接地址: http://www.djcxy.com/p/63570.html

上一篇: ResteasyBootstrap

下一篇: Base64DecoderException错误谷歌应用程序引擎