nella mia app java SWING, l'utente può trasferire i file nel suo spazio DropBox, ho implementato con successo la libreria e sto cercando di ottenere il token di accesso dell'utente senza doverlo copiare e incollare nella mia app. Secondo la documentazione, devo usare HttpServletRequest per ottenere il token dal campo, ma ottengo un'eccezione, come scritto nel titolo.


codice:
public class LoginServlet implements HttpServletRequest {


    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {


        // read form fields
        String token = request.getParameter("data-token");


        // get response writer
        PrintWriter writer = response.getWriter();


        // build HTML code
        String htmlRespone = "<html>";
        htmlRespone += "<h2>token: " + token + "<br/>";
        htmlRespone += "</html>";


        // return response
        writer.println(htmlRespone);


        response.sendRedirect(Main.redirectUri);


    }
la classe Main

codice:
 LoginServlet request = new LoginServlet();
           


            
            HttpSession session = request.getSession(true);
            String sessionKey = "dropbox-auth-csrf-token";
            DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(session, sessionKey);


            DbxRequestConfig config = new DbxRequestConfig("User");  
            DbxAppInfo appInfo = new DbxAppInfo(mioKey, mioSecret);
            DbxWebAuth webAuth = new DbxWebAuth(config, appInfo);
            DbxWebAuth.Request authRequest = DbxWebAuth.newRequestBuilder()
                    .withRedirectUri(redirectUri, csrfTokenStore)
                    .build();


            String url = webAuth.authorize(authRequest);


            Desktop.getDesktop().browse(new URL(url).toURI());


            DbxAuthFinish authFinish;
            try {
                authFinish = webAuth.finishFromRedirect(redirectUri, csrfTokenStore, request.getParameterMap());
            } catch (DbxWebAuth.BadRequestException ex) {
                //log("On /dropbox-auth-finish: Bad request: " + ex.getMessage());
                //response.sendError(400);
                return;
            } catch (DbxWebAuth.BadStateException ex) {
                // Send them back to the start of the auth flow.
                //response.sendRedirect(redirectUri);
                return;
            } catch (DbxWebAuth.CsrfException ex) {
                //log("On /dropbox-auth-finish: CSRF mismatch: " + ex.getMessage());
                //response.sendError(403, "Forbidden.");
                return;
            } catch (DbxWebAuth.NotApprovedException ex) {
                // When Dropbox asked "Do you want to allow this app to access your
                // Dropbox account?", the user clicked "No".


                return;
            } catch (DbxWebAuth.ProviderException ex) {
                //log("On /dropbox-auth-finish: Auth failed: " + ex.getMessage());
                //response.sendError(503, "Error communicating with Dropbox.");
                return;
            } catch (DbxException ex) {
                //log("On /dropbox-auth-finish: Error getting token: " + ex.getMessage());
                //response.sendError(503, "Error communicating with Dropbox.");
                return;
            }
            String accessToken = authFinish.getAccessToken();


            // Save the access token somewhere (probably in your database) so you
            // don't need to send the user through the authorization process again.
            // Now use the access token to make Dropbox API calls.
            DbxClientV2 client = new DbxClientV2(config, accessToken);
            //...
di seguito l'output
codice:
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:873)
Caused by: java.lang.UnsupportedOperationException: Not supported yet.
    at cloud.LoginServlet.getSession(LoginServlet.java:401)
    at Main.main(Main.java:100)
la riga 100 è questa
codice:
 HttpSession session = request.getSession(true);