java - 应用引擎 : Could not verify SSL certificate for URL

标签 java google-app-engine ssl oauth intuit-partner-platform

我正在尝试使用 OAuth 连接到 Intuit Quickbooks,使用其托管在 AppEngine (SDK 1.8.4) 上的 JAVA API V3。首先,我只是按照此处的说明运行示例代码: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;

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

有什么想法吗?

最佳答案

在我说我尝试了一些对我来说毫无意义但似乎有效的方法之后,请尝试以下操作:

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

对我来说,它是 FetchOptions.Builder 并显式设置“validateCertificate()”;看看这是否能解决您的问题。

关于java - 应用引擎 : Could not verify SSL certificate for URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18932751/

相关文章:

java - 如何绑定(bind)带有文件输入的 HTML 表单和后端的 Spring RestController(无 JS)

google-app-engine - Google App Engine 中生产和测试环境的最佳实践

python - 需要帮助创建 GAE 数据存储加载器类?

ssl - 当我们使用 Microsoft Stoage (CloudStorageAccount) 将文件上传到 Azure 文件存储时,AspnetCore 2.0 是否使用 TLS 2.0

java - 在 Java 中创建 JSON 对象的方法

java - 从rest服务以json格式返回Map

java - Google App Engine appcfg.py 引发值错误

qt - SSL。没有 OPENSSL_Applink

python - SSL 错误 TLSV1_ALERT_INTERNAL_ERROR 与 aiohttp 库

java - 如何在 wicket 框架中渲染 <base> 标签