cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you an educator? Well we want to hear from you, so check out some tools we think might help you out here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

IllegalStateException while finishFromRedirect in API v3

IllegalStateException while finishFromRedirect in API v3

saurabhmittal19
Explorer | Level 3

I am using dropbox-core-sdk version 3.0.5, and I am getting "Already Connected" while trying to authorise account (and get access token) to be associated with our application.

 

I am using the the following code snippet :

 

final DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(request.getSession(true), "dropbox-auth-csrf-token");
 
//While testing I am using the hardcoded redirection URL for now.
final DbxAuthFinish authFinish = dbxWebAuth.finishFromRedirect("http://localhost:8080/authentication-finish", csrfTokenStore, request.getParameterMap());

 

1 Accepted Solution

Accepted Solutions

Re: IllegalStateException while finishFromRedirect in API v3

Greg-DB
Dropboxer
Thanks! Based on that stack trace, it looks like this is actually occurring in getCurrentAccount. Can you confirm you're running on Google App Engine, and can you share your code for constructing your DbxRequestConfig and calling getCurrentAccount?

View solution in original post

6 Replies 6

Re: IllegalStateException while finishFromRedirect in API v3

Greg-DB
Dropboxer
Can you post the full error/stack trace? Thanks in advance!

Re: IllegalStateException while finishFromRedirect in API v3

saurabhmittal11
New member | Level 2

Code Snippet before authorization call

 

 

final OAuthRequest state = new OAuthRequest();
state.setXYZId(String.valueOf(XYZId));
myDAO.save(state);
 
 
final DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(request.getSession(true), "dropbox-auth-csrf-token");
DbxWebAuth.Request webAuthRequest = DbxWebAuth.newRequestBuilder()
.withRedirectUri("http://localhost:8080/authentication-finish", csrfTokenStore).withState(state.getId().toString())
.build();
oauthUrl = this.dbxWebAuth.authorize(webAuthRequest);

 

Code Snipper in redirection URL:

 

final DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(request.getSession(true), "dropbox-auth-csrf-token");
final DbxAuthFinish authFinish = dbxWebAuth.finishFromRedirect("http://localhost:8080/authentication-finish", csrfTokenStore, request.getParameterMap());

  

StackTrace:-

[INFO] java.lang.IllegalStateException: Already connected
[INFO] at java.net.URLConnection.setDoOutput(URLConnection.java:909)
[INFO] at com.garble.drive.utils.AppEngineHttpRequestor$Uploader.getBody(AppEngineHttpRequestor.java:129)
[INFO] at com.dropbox.core.http.HttpRequestor$Uploader.upload(HttpRequestor.java:105)
[INFO] at com.dropbox.core.DbxRequestUtil.startPostRaw(DbxRequestUtil.java:239)
[INFO] at com.dropbox.core.v2.DbxRawClientV2$1.execute(DbxRawClientV2.java:107)
[INFO] at com.dropbox.core.v2.DbxRawClientV2.executeRetriable(DbxRawClientV2.java:284)
[INFO] at com.dropbox.core.v2.DbxRawClientV2.rpcStyle(DbxRawClientV2.java:102)
[INFO] at com.dropbox.core.v2.users.DbxUserUsersRequests.getCurrentAccount(DbxUserUsersRequests.java:120)
[INFO] at com.garble.drive.security.oauth.provider.DropboxOauthProvider.getProfileData(DropboxOauthProvider.java:57)
[INFO] at com.garble.drive.security.signup.GarbleCloudRegistration.dropboxSignInFinish(GarbleCloudRegistration.java:280)
[INFO] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[INFO] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[INFO] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[INFO] at java.lang.reflect.Method.invoke(Method.java:606)
[INFO] at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:128)
[INFO] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
[INFO] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
[INFO] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
[INFO] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
[INFO] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
[INFO] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
[INFO] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
[INFO] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
[INFO] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
[INFO] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
[INFO] at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
[INFO] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
[INFO] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[INFO] at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
[INFO] at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
[INFO] at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
[INFO] at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
[INFO] at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
[INFO] at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
[INFO] at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
[INFO] at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
[INFO] at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:95)
[INFO] at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
[INFO] at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
[INFO] at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
[INFO] at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
[INFO] at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
[INFO] at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
[INFO] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
[INFO] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
[INFO] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
[INFO] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
[INFO] at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
[INFO] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
[INFO] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[INFO] at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
[INFO] at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
[INFO] at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
[INFO] at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
[INFO] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:134)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:48)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
[INFO] at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
[INFO] at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
[INFO] at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO] at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
[INFO] at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
[INFO] at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
[INFO] at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
[INFO] at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
[INFO] at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:95)
[INFO] at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO] at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:508)
[INFO] at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO] at org.mortbay.jetty.Server.handle(Server.java:326)
[INFO] at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
[INFO] at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
[INFO] at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
[INFO] at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
[INFO] at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
[INFO] at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
[INFO] at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

Re: IllegalStateException while finishFromRedirect in API v3

Greg-DB
Dropboxer
Thanks! Based on that stack trace, it looks like this is actually occurring in getCurrentAccount. Can you confirm you're running on Google App Engine, and can you share your code for constructing your DbxRequestConfig and calling getCurrentAccount?

View solution in original post

Re: IllegalStateException while finishFromRedirect in API v3

saurabhmittal19
Explorer | Level 3

Thanks for mentioning the method where the issue is coming. And yes it is a Google Cloud project running on AppEngine. I have actually resolved the issue after debugging this getCurrentAccount() method.

 

And this was the code snippet which we were using for calling getCurrentAccount

 

String clientIdentifier = "abc/1.0";
String userLocale = Locale.getDefault().toString();
DbxRequestConfig config = new DbxRequestConfig(clientIdentifier, userLocale, AppEngineHttpRequestor.Instance);
DbxClientV2 client = new DbxClientV2(config, accessToken);
client.users().getCurrentAccount().getEmail();

 

Now I changed this to:

 

 

String clientIdentifier = "abc/1.0";
DbxRequestConfig config = new DbxRequestConfig(clientIdentifier);
DbxClientV2 client = new DbxClientV2(config, accessToken);
client.users().getCurrentAccount().getEmail();

 

And the code started working. Thanks for all the support. One last question, de we need to have this clientIdentifier as "abc/1.0" hardcoded?

Re: IllegalStateException while finishFromRedirect in API v3

saurabhmittal19
Explorer | Level 3

Just need one more help. I couldn't find any documentation which can telll us about new features and fixes in DropBox v3. Could you provide me some link for the documentation.

 

Thanks in Advance 🙂

Re: IllegalStateException while finishFromRedirect in API v3

Greg-DB
Dropboxer

Thanks for following up. I'm glad to hear you got this working.

 

Your "clientIdentifier" should identify your app and the current version number of your app. This is used in the User-Agent header when making API calls, which can be useful to identify and when debugging your app. You can find more information on that here:

 

https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/DbxRequestConfig.html#ge...

 

Exactly how you build that string is up to you though. It can be entirely static, or you can dynamically build it with the version number automatically added based on the version of the app, for example.

 

Also, to clarify, there isn't a Dropbox API v3. The current version of the Dropbox API is API v2. The v3 number you're likely referring to is for the Dropbox Java SDK itself, which is currently at v3.0.5. That SDK uses Dropbox API v2.

 

You can find some more information on the new features API v2 added in the original launch blog post here:

 

https://blogs.dropbox.com/developers/2015/11/dropbox-api-v2-launches-today/

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    saurabhmittal19 Explorer | Level 3
  • User avatar
    saurabhmittal11 New member | Level 2
What do Dropbox user levels mean?
Need more support?