2

我正在尝试使用托管在 AppEngine (SDK 1.8.4) 上的 JAVA API V3 通过 OAuth 连接到 Intuit Quickbooks。首先,我只是按照他们的说明运行他们的示例代码:http: //ippdocs.intuit.com/0025_QuickBooksAPI/0055_DevKits/0201_IPP_Java_DevKit_3.0

它在 TomCat 上运行良好,但是当我调整代码以在 AppEngine 上运行时,出现此错误:

OauthHelper.java 提取,在最后一行引发异常:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthConsumer;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.exception.OAuthNotAuthorizedException;
import oauth.signpost.http.HttpParameters;

[...]
URL url;
url = new URL(signedRequestTokenUrl);
HttpURLConnection httpconnection = (HttpURLConnection) url
httpconnection.setRequestMethod("GET");
httpconnection.setRequestProperty("Content-type", "application/xml");
httpconnection.setRequestProperty("Content-Length", "0");
if (httpconnection != null) {
    BufferedReader rd = new BufferedReader(new InputStreamReader(
                    httpconnection.getInputStream()));
[...]

导致此错误:

javax.net.ssl.SSLHandshakeException: Could not verify SSL certificate for URL: https://oauth.intuit.com/oauth/v1/get_request_token?oauth_signature=VzStL8UcIoDrgKdcU7jJAWaux5Y%3D&oauth_callback=http%3A%2F%2Flocalhost%3A8888%2Faccesstoken.htm&oauth_consumer_key=qyprdulFn7zfTw5ewpZhkPxSo4q27X&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1379761817&oauth_nonce=5706619579888946790
at com.google.appengine.api.urlfetch.URLFetchServiceImpl.convertApplicationException(URLFetchServiceImpl.java:144)
at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:43)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.fetchResponse(URLFetchServiceStreamHandler.java:417)
at com.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getInputStream(URLFetchServiceStreamHandler.java:296)
at com.intuit.utils.OauthHelper.getRequestTokenSignPost(OauthHelper.java:167)

网址如下:

https://oauth.intuit.com/oauth/v1/get_request_token?oauth_signature=xxxx&oauth_callback=http%3A%2F%2Flocalhost%3A8888%2Faccesstoken.htm&oauth_consumer_key=xxxx&oauth_version=1.0&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1379768671&oauth_nonce=-78989043

完全相同的一段代码在 TomCat 7 上完美运行。

路标

我还尝试通过以下方式替换 DefaultOAuthConsumer 和 DefaultOAuthProvider:

oauth.signpost.commonshttp.CommonsHttpOAuthProvider;
oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;

,但它会产生完全相同的异常。

有任何想法吗?

4

1 回答 1

2

And right after I say that I tried something that to me makes little sense, but seems to work, try this:

        URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
        FetchOptions lFetchOptions = FetchOptions.Builder.validateCertificate();
        HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET, lFetchOptions);
        HTTPResponse response = fetcher.fetch(request);

For me it was the FetchOptions.Builder and explicitly setting "validateCertificate()"; See if this solve it for you.

于 2013-10-31T17:12:52.383 回答