带有GWT身份验证问题的Dropbox Java API [英] Dropbox Java API with GWT Authentication problems

查看:189
本文介绍了带有GWT身份验证问题的Dropbox Java API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里使用的Dropbox API版本1.6使用: https:// www.dropbox.com/developers/core/sdks/java



我也在Eclipse 3.7中使用GWT 2.5.1



我有以下代码在Java Applcation中运行时:

  DbxRequestConfig requestConfig = new DbxRequestConfig(type,locale); 
DbxAppInfo appInfo = new DbxAppInfo(APP_ID,APP_SECRET);
DbxWebAuthNoRedirect webauth = new DbxWebAuthNoRedirect(requestConfig,appInfo);
String result = webauth.start();
System.out.println(result);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String code = reader.readLine();

webauth = new DbxWebAuthNoRedirect(requestConfig,appInfo);
DbxAuthFinish finish = webauth.finish(code);

DbxClient client = new DbxClient(requestConfig,finish.accessToken);
DbxAccountInfo info = client.getAccountInfo();
long total = info.quota.total;
long used = info.quota.normal;

System.out.println(total:+ total);
System.out.println(used:+ used);

当我将它作为Java应用程序运行时,但是,当我尝试在RemoteServiceServlet中使用GWT进行类似的操作时。我尝试做的时候收到一个异常


我收到的异常如下:

 导致:java.lang.ClassCastException:com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler $ Connection无法转换为javax.net.ssl.HttpsURLConnection 
at com.dropbox.core.http.StandardHttpRequestor.prepRequest(StandardHttpRequestor.java:160)
at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:87)
at com。 dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:21)
at com.dropbox.core.DbxRequestUtil.startPostNoAuth(DbxRequestUtil.java:156)
at com.dropbox.core.DbxRequestUtil。 (DbxWebAuthNoRedirect.java:84)
at com.dropbox.core.DbxWebAuthNoRedirect.finish(DbxWebAuthNoRedirect.java:84)
at com.cloudshare.server.DropboxPlayground.getFinish(DropboxPlayground.java:21)
at com.cloudshare.server.Dr opboxServiceImpl.authenticate(DropboxServiceImpl.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
位于java.lang.reflect.Method.invoke(Method.java:606)
位于com.google.appengine.tools.development。 agent.runtime.Runtime.invoke(Runtime.java:115)
,位于com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
... 40更多

在过去的几个小时里,我一直在撞墙,试图弄清楚发生了什么事上。我原本想使用DbxWebAuth,但其API中的文档包含了不存在的类的说明(我假设他们曾经做过)。



I感觉像DbxWebAuthNoRedirect正在做一些动态加载基于可用类的连接。但是我一直无法弄清楚。



预先感谢您的帮助!



EDITS:



好的,我查看了Dropbox API的源代码,发现错误在这里:

 网址urlObject =新网址(url); 
HttpsURLConnection conn =(HttpsURLConnection)urlObject.openConnection(this.proxy);

由于我使用的是Google App Engine,因此它使用自己的URL对象而不是由App Engine API。解决方案的任何想法都不涉及为Dropbox API写入GWT包装。 解决方案

您是否使用了安全的 https:// 要连接的网址?我的猜测是,如果您使用 http:// ,您将得到不能转换为安全连接的不安全连接器。



- 编辑 -



它看起来像 HttpsURLConnection 类GAE根本不支持它,因此它不会像GAE文档所说的那样工作。 使用HttpsURLConnection(doc issue)。这意味着你可能不在使用它直接使用它。


I am using version 1.6 of the Dropbox API for Java found here: https://www.dropbox.com/developers/core/sdks/java

I am also using GWT 2.5.1 in Eclipse 3.7

I have the following code which works when run as a Java Applcation:

    DbxRequestConfig requestConfig = new DbxRequestConfig(type, locale);
    DbxAppInfo appInfo = new DbxAppInfo(APP_ID, APP_SECRET);
    DbxWebAuthNoRedirect webauth = new DbxWebAuthNoRedirect(requestConfig, appInfo);
    String result = webauth.start();
    System.out.println(result);
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String code = reader.readLine();

    webauth = new DbxWebAuthNoRedirect(requestConfig, appInfo);
    DbxAuthFinish finish = webauth.finish(code);

    DbxClient client = new DbxClient(requestConfig, finish.accessToken);
    DbxAccountInfo info = client.getAccountInfo();
    long total = info.quota.total;
    long used = info.quota.normal;

    System.out.println("total: " + total);
    System.out.println("used: " + used);

This works just fin when I run it as a Java Application. However, when I try to do something similar with GWT within a RemoteServiceServlet. I get an exception when I try to do

webauth = new DbxWebAuthNoRedirect(requestConfig, appInfo);

The exception I am getting is the following:

Caused by: java.lang.ClassCastException: com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection cannot be cast to javax.net.ssl.HttpsURLConnection
at com.dropbox.core.http.StandardHttpRequestor.prepRequest(StandardHttpRequestor.java:160)
at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:87)
at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:21)
at com.dropbox.core.DbxRequestUtil.startPostNoAuth(DbxRequestUtil.java:156)
at com.dropbox.core.DbxRequestUtil.doPostNoAuth(DbxRequestUtil.java:289)
at com.dropbox.core.DbxWebAuthHelper.finish(DbxWebAuthHelper.java:40)
at com.dropbox.core.DbxWebAuthNoRedirect.finish(DbxWebAuthNoRedirect.java:84)
at com.cloudshare.server.DropboxPlayground.getFinish(DropboxPlayground.java:21)
at com.cloudshare.server.DropboxServiceImpl.authenticate(DropboxServiceImpl.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
... 40 more

I have been banging my head against a wall for last couple of hours trying to figure out what is going on. I originally wanted to use a DbxWebAuth but the documentation in their API includes instructions that have classes that don't exist (I am assuming they did at one time).

I feel like the DbxWebAuthNoRedirect is doing something where it is dynamically loading a connection based on the classes that are available. But I have not been able to figure it out.

Thanks in advance for the help!

EDITS:

Okay, so I looked at the Dropbox API source and the error is occurring here:

    URL urlObject = new URL(url);
    HttpsURLConnection conn = (HttpsURLConnection) urlObject.openConnection(this.proxy);

Because I am using Google App Engine, it is using its own URL object rather than the one imported by the App Engine API. Any ideas on a solution that doesn't involve writting a GWT wrapper for the Dropbox API.

解决方案

Did you use a secure https:// url to connect? My guess is if you use a http:// you get the unsecured connector that can't be cast to a secure connection.

--edit--

It looks the HttpsURLConnection class is simply not supported on GAE, therefor it will not work unlike the GAE documentation says. Using HttpsURLConnection (doc issue). This means you're probably out of luke using it directly.

这篇关于带有GWT身份验证问题的Dropbox Java API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆