cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Java desktop DbxWebAuth with withRedirectUri NPE

Java desktop DbxWebAuth with withRedirectUri NPE

ChriCC
New member | Level 2

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 1

Greg-DB
Dropbox Staff

[ Cross-linking for reference: https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Java-desktop-DbxWebAuth-with-withRedire... ]

 

This DbxWebAuth flow is meant for use with web apps, via whatever web framework you might be using. The request and response objects in this basic sample initially aren't set, and instead are just null as a placeholder. Without setting them, the NPE is expected.

 

We do have a working example with these set here:

 

https://github.com/dropbox/dropbox-sdk-java/blob/c710ef80f1c2700031baad7c615dc9934162c090/examples/w...

 

 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?