我按照以下步骤为 Java 部署 DrEdit:
https://github.com/googledrive/dredit/tree/master/java
当我访问该应用程序时,我在 AppEngine 日志控制台中收到此错误!
2013-10-02 12:51:08.404
/start
java.lang.NullPointerException
at com.google.drive.samples.dredit.DrEditServlet.loginIfRequired(DrEditServlet.java:149)
at com.google.drive.samples.dredit.StartPageServlet.doGet(StartPageServlet.java:46)
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)
这是第 149 行。credentialManager 为空。
protected void loginIfRequired(HttpServletRequest req,
HttpServletResponse resp) {
Credential credential = getCredential(req, resp);
if (credential == null) {
// redirect to authorization url
try {
resp.sendRedirect(credentialManager.getAuthorizationUrl()); // line 149
它应该在 init() 中设置
public void init() throws ServletException {
super.init();
// init credential manager
credentialManager = new CredentialManager(
getClientSecrets(), TRANSPORT, JSON_FACTORY);
}
我无法使用 System.out.println,因为它永远不会显示在日志中,即使我选择了“所有请求”。
我也收到 NoSuchMethodError:
Error for /
java.lang.NoSuchMethodError: com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.load(Lcom/google/api/client/json/JsonFactory;Ljava/io/InputStream;)Lcom/google/api/client/googleapis/auth/oauth2/GoogleClientSecrets;
at com.google.drive.samples.dredit.DrEditServlet.getClientSecrets(DrEditServlet.java:249)
at com.google.drive.samples.dredit.DrEditServlet.init(DrEditServlet.java:88)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
这恰好是这条线:
249 return GoogleClientSecrets.load(JSON_FACTORY, stream);
我应该提一下,当我访问 localhost:8888/start 时,它在本地工作正常,因为它只是将我发送到 Google 进行身份验证,但是当它尝试重定向到 appspot.com/oauth2callback 时当然会失败。