[英]Java Dropbox HttpServletRequest ( java.lang.UnsupportedOperationException: Not supported yet.)
in my java SWING app, the user can transfer files to his DropBox space, I have successfully implemented the library and I'm trying to get the user's access token without having to copy and paste it into my app.在我的 java SWING 应用程序中,用户可以将文件传输到他的 DropBox 空间,我已经成功实现了该库,我正在尝试获取用户的访问令牌,而无需将其复制并粘贴到我的应用程序中。 According to the documentation , I have to use HttpServletRequest to get what I want, but I get an exception, as written in the title.
根据文档,我必须使用 HttpServletRequest 来获取我想要的东西,但是我得到了一个异常,如标题中所写。
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);
}
@Override
public HttpSession getSession(boolean bln) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public HttpSession getSession() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
and in Main class并在主班
LoginServlet request = new LoginServlet();
// Fetch the session to verify our CSRF token
HttpSession session = request.getSession(true);
String sessionKey = "dropbox-auth-csrf-token";
DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(session, sessionKey);
DbxRequestConfig config = new DbxRequestConfig("User"); //Client name can be whatever you like
DbxAppInfo appInfo = new DbxAppInfo(App key, App secret);
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);
//...
full stack全栈
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:404)
at cloud_new.Main.main(Main.java:103)
the row at cloud_new.Main.main(Main.java:103)
is this HttpSession session = request.getSession(true);
at cloud_new.Main.main(Main.java:103)
的行是这个HttpSession session = request.getSession(true);
This is not a solution for the main java question relate to some http error.这不是与某些 http 错误相关的主要 java 问题的解决方案。
This is a proposed approach based or inspired in how heroku auth and google container registry auth works.这是一种基于 heroku 身份验证和谷歌容器注册表身份验证工作方式的建议方法。
Also dropbox and other platforms does not offer a kind of special admin api_key to consume the final user resources. Dropbox 和其他平台也没有提供一种特殊的 admin api_key 来消耗最终用户资源。 Due to that a web login in a real browser is required and this cannot be easily replaced or emulated with web_views or internal browsers in android or ios.
由于需要在真实浏览器中进行网络登录,并且这不能轻易替换或模拟为 web_views 或 android 或 ios 中的内部浏览器。 Source
来源
Develop a web application which exposes two functionalities: receive the redirect from dropbox authorization platform and a rest endpoint to query if user is authenticated.开发一个 Web 应用程序,它公开两个功能:接收来自 Dropbox 授权平台的重定向和一个用于查询用户是否通过身份验证的休息端点。
my-oauth2-helper.com/validate/auth
sending user email.my-oauth2-helper.com/validate/auth
发送用户电子邮件的桌面应用程序查询。my-oauth2-helper.com/validate/auth
returns a field which indicate that user does not have a valid authentication and other field with the dropbox login url. my-oauth2-helper.com/validate/auth
返回一个字段,该字段指示用户没有有效的身份验证和其他带有保管箱登录 URL 的字段。redirect_uri
, etc. redirect_uri
等。my-oauth2-helper.com/redirect
which is the classic field called redirect_uri
my-oauth2-helper.com/redirect
,这是一个名为redirect_uri
的经典字段my-oauth2-helper.com/redirect
receive the auth_code and exchange it for a valid access_token
for this user and store it in a kind of database. my-oauth2-helper.com/redirect
接收 auth_code 并将其交换为该用户的有效access_token
并将其存储在一种数据库中。 After that could shows a message like: "Now, you can close this page and returns to the desktop application"my-oauth2-helper.com/token
sending the email as request parametermy-oauth2-helper.com/token
了有效的身份验证,将电子邮件作为请求参数发送access_token
generation , the my-oauth2-helper.com/token
endpoint returns a valid access_token for this user.access_token
后, my-oauth2-helper.com/token
端点会为此用户返回有效的 access_token。access_token
is ready to use in order to consume any dropbox api feature, which user accepted in consent page.access_token
已准备好使用,以使用用户在同意页面中接受的任何 Dropbox api 功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.