Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

ChriCC's avatar
ChriCC
New member | Level 2
5 years ago

Java desktop DbxWebAuth with withRedirectUri NPE

Hi everyone, as I wrote in the object, I get an NPE on the line:

 HttpSession session = request.getSession(true);

Hi everyone, as I wrote in the object, I get an NPE on the line:

I'm using this code to prevent the user from manually entering the verification code into my app. from the example codes I found HttpServletRequest is not initialized (null). Do you have any examples examples? Thank you
This is the complete code

public static void main(String[] args) throws DbxException, IOException, URISyntaxException {

        HttpServletRequest request = null;
        HttpServletResponse response = null;

        DbxRequestConfig config = new DbxRequestConfig("berry120_dropbox_example"); //Client name can be whatever you like

        DbxAppInfo appInfo = new DbxAppInfo("my_code", "my_code");
        DbxWebAuth webAuth = new DbxWebAuth(config, appInfo);

        //redirect URL 
        String redirectUri = "http://localhost:8080";
        HttpSession session = request.getSession(true);

        DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(session, "vj38b0mkkxnnbjg");

        DbxWebAuth.Request authRequest = DbxWebAuth.newRequestBuilder()
                .withRedirectUri(redirectUri, csrfTokenStore)
                .build();

        String authorizePageUrl = webAuth.authorize(authRequest);
        try {
            response.sendRedirect(authorizePageUrl);

        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

1 Reply

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!