title: Launching DrEdit gives 500 server error - application logs says "Can't handle the OAuth2 callback"
body: <p>I am new to Google Drive API and recently have done two small projects using drive API. I am now implementing DrEdit and have followed instructions mentioned in -
  <a href="https://github.com/googledrive/dredit/blob/master/java/README.md" rel="nofollow">https://github.com/googledrive/dredit/blob/master/java/README.md</a>
  After successful deployment in Eclipse, when the application launches, I see the consent screen and after accepting that, I am getting following error:
  Error: Server Error
  The server encountered an error and could not complete your request.
  Please try again in 30 seconds.</p>
  
  <p>Here is the log trace of google app engine.</p>
  
  <pre><code>Uncaught exception from servlet
  java.lang.RuntimeException: Can't handle the OAuth2 callback, make sure that code is valid.
      at edu.csus.dredit.DrEditServlet.handleCallbackIfRequired(DrEditServlet.java:178)
      at edu.csus.dredit.StartPageServlet.doGet(StartPageServlet.java:43)
      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.handle(ServletHandler.java:390)
      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 org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
      at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
      at com.google.apphosting.runtime.jetty.ResourceFileServlet.serveWelcomeFileAsForward(ResourceFileServlet.java:342)
      at com.google.apphosting.runtime.jetty.ResourceFileServlet.maybeServeWelcomeFile(ResourceFileServlet.java:281)
      at com.google.apphosting.runtime.jetty.ResourceFileServlet.doGet(ResourceFileServlet.java:142)
      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.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
      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 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.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:254)
      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 com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
      at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:527)
      at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
      at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
      at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
      at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
      at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
      at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
      at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
      at java.lang.Thread.run(Thread.java:724)
  </code></pre>
  
  <p>I saw many posts here but no success. I am not sure, what went wrong. I read this document to enable Passwordless Login with OAuth2: <a href="https://cloud.google.com/appengine/docs/java/tools/uploadinganapp" rel="nofollow">https://cloud.google.com/appengine/docs/java/tools/uploadinganapp</a>
  and here it goes -</p>
  
  <pre><code>C:\Program Files (x86)\eclipse luna 4.4\eclipse\plugins\com.google.appengine.ecl
  ipse.sdkbundle_1.9.18\appengine-java-sdk-1.9.18\bin&gt;appcfg --oauth2 update C:\Us
  ers\Pilluda\git\dredit\war
  Mar 07, 2015 5:39:19 PM com.google.appengine.repackaged.com.google.api.client.ex
  tensions.java6.auth.oauth2.FileCredentialStore &lt;init&gt;
  WARNING: unable to change file permissions for everybody: C:\Users\Pilluda\.appc
  fg_oauth2_tokens_java
  Please enter code: 4/5Wft2ANn7R7RiheUSOuCM_gQ_wsl6fiwRU6Ie7sICKQ.wvQzIOeFCgAdEnp
  6UAPFm0F0jRXulwI
  Reading application configuration data...
  Mar 07, 2015 5:40:59 PM com.google.apphosting.utils.config.AppEngineWebXmlReader
   readAppEngineWebXml
  INFO: Successfully processed C:/Users/Pilluda/git/dredit/war\WEB-INF/appengine-w
  eb.xml
  Mar 07, 2015 5:40:59 PM com.google.apphosting.utils.config.AbstractConfigXmlRead
  er readConfigXml
  INFO: Successfully processed C:/Users/Pilluda/git/dredit/war\WEB-INF/web.xml
  
  
  Beginning interaction for module default...
  0% Created staging directory at: 'C:\Users\Pilluda\AppData\Local\Temp\appcfg2174
  618651168391922.tmp'
  5% Scanning for jsp files.
  20% Scanning files on local disk.
  25% Initiating update.
  28% Cloning 2 static files.
  31% Cloning 59 application files.
  40% Uploading 0 files.
  52% Initializing precompilation...
  90% Deploying new version.
  95% Closing update: new version is ready to start serving.
  98% Uploading index definitions.
  
  Update for module default completed successfully.
  Success.
  Cleaning up temporary files for module default...
  </code></pre>
  
  <p>If anybody know how to correct this problem, please let me know.</p>