Base64DecoderException错误谷歌应用程序引擎

您好,我在谷歌应用程序引擎中得到这个错误:

HTTP错误500

访问/上传测试问题。 原因:

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

引起:

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)

抛出java.lang.ClassNotFoundException:由造成com.google.gdata.util.common.util.Base64DecoderException在java.net.URLClassLoader的$ 1.run(URLClassLoader.java:202)在java.security.AccessController.doPrivileged(本机方法)在java.net.URLClassLoader.findClass(URLClassLoader.java:190)在java.lang.ClassLoader.loadClass(ClassLoader.java:306)在com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:176 )在java.lang.ClassLoader.loadClass(ClassLoader.java:247)... 37更多引起:

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://

这是我在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){



    }




}

请帮我解决同样的问题......谢谢桑迪


好。 我可能会有点苛刻,但每当你在任何论坛上发布问题时,都要尽量让它易于阅读。 发布整个堆栈跟踪和代码是可以的,但您应该随附一份简短的摘要以及迄今为止尝试的内容。 我敢打赌,如果你这样做了,你会得到更好的回应(注意你得到的赞成票和密切的投票,显然至少有一些人有同样的感受)。

无论如何,你没有通过谷歌找到解决方案的原因可能是因为你专注于Base64DecoderException 。 如果你搜索了“ClassNotFoundException jetty”,你可能找到了一个解决方案。

“ClassNotFoundException”是什么意思? 这意味着, The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found

正如你所说,你正确地导入了这个类,但是直截了当地说,当你启动jetty时,你并没有将这个类的jar文件给JVM。 换句话说,确保在构建战争时包含这个类的jar。

如果你觉得超级懒惰,并希望这个错误立即消失,你可以在这里下载jar并把它放在$jetty.home/lib 。 然而,这通常被认为是不好的做法。 正确/可接受的解决方法是在战争档案中加入必要的罐子。

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

上一篇: Base64DecoderException error google app engine

下一篇: Trying to use java 1.6 with app engine gives runtime errors