我正在尝试为我的Java项目使用twitter4j库获取推文。在我的第一次运行中,我得到了关于证书sun.security.validator.ValidatorException
和的错误sun.security.provider.certpath.SunCertPathBuilderException
。然后我通过以下方式添加了Twitter证书:
C:\Program Files\Java\jdk1.7.0_45\jre\lib\security>keytool -importcert -trustcacerts -file PathToCert -alias ca_alias -keystore "C:\Program Files\Java\jdk1.7.0_45\jre\lib\security\cacerts"
但是没有成功。这是获取推文的过程:
public static void main(String[] args) throws TwitterException {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("myConsumerKey")
.setOAuthConsumerSecret("myConsumerSecret")
.setOAuthAccessToken("myAccessToken")
.setOAuthAccessTokenSecret("myAccessTokenSecret");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
try {
Query query = new Query("iphone");
QueryResult result;
result = twitter.search(query);
System.out.println("Total amount of tweets: " + result.getTweets().size());
List<Status> tweets = result.getTweets();
for (Status tweet : tweets) {
System.out.println("@" + tweet.getUser().getScreenName() + " : " + tweet.getText());
}
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to search tweets: " + te.getMessage());
}
这是错误:
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=d35baff5 or
http://www.google.co.jp/search?q=1446302e
TwitterException{exceptionCode=[d35baff5-1446302e 43208640-747fd158 43208640-747fd158 43208640-747fd158], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.5}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:177)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:81)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1929)
at twitter4j.TwitterImpl.search(TwitterImpl.java:306)
at jku.cc.servlets.TweetsAnalyzer.main(TweetsAnalyzer.java:38)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
at twitter4j.internal.http.HttpResponseImpl.<init>(HttpResponseImpl.java:34)
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:141)
... 5 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
at sun.security.validator.Validator.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
... 20 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 26 more
Failed to search tweets: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
在你的firefox浏览器中转到URL,单击HTTPS证书链(URL地址旁边的锁定图标)。点击"more info" > "security" > "show certificate" > "details" > "export.."
。提取名称,然后选择文件类型example.cer
。现在,你有了带有密钥库的文件,并且必须将其添加到JVM中
确定cacerts
文件的位置,例如。 C:\Program Files (x86)\Java\jre1.6.0_22\lib\security\cacerts.
接下来,example.cer
在命令行中将文件导入到cacerts中:
keytool -import -alias example -keystore C:\Program Files (x86)\Java\jre1.6.0_22\lib\security\cacerts -file example.cer
系统将要求你输入密码,默认密码为 changeit
重新启动你的JVM / PC
。
我正在尝试使用twitter4j库为我的Java项目获取tweets,该项目使用(可以在stack trace中看到)。在第一次运行时,我收到一个关于证书和的错误。然后我通过以下方式添加了twitter证书: 但没有成功。下面是获取Tweets的程序: 这里有一个错误:
我正在使用WSO2 API管理器和Keyclope服务器进行API网关和用户身份验证。两者都在Openshift 3.11上运行。在浏览器上,尝试重定向到wso2 apim上的存储页面时出现以下错误。此外,我正在为这两个服务器使用一个使用keytool生成的自签名证书,它还分别导入到JVM cacerts中。Open JDK版本为1.8。 我在使用javax时遇到了致命的问题。网ssl。SSLEx
我在Glassfish上有一个使用GoDaddy SSL证书的JAVA EE webapp。HTTP侦听器重定向到HTTPS侦听器。 我正在尝试让从Googlebot爬虫的网络应用程序中获取页面。该代码在未启用SSL的暂存服务器上按预期工作。但是,在具有GoDaddy SSL证书的实时服务器上,当尝试获取网页时,我会收到以下错误。 我已经尝试了这里指定的解决方法(http://www.mkyong
我正在使用eclipse,在尝试执行此函数时,出现了以下错误。 我想发送一个GET请求以及证书和密钥。我可以下载任何格式的证书,所以这不是问题。我知道我需要将此添加到java keystone中,但在尝试了各种建议后,我仍然无法修复此问题。 下面是错误-
我已经创建了一个自定义密钥库文件xyz。jsk,当我试图使用这个文件时,我遇到了异常 org.springframework.web.client.资源访问异常: I/O错误的POST请求:sun.security.validator.Validator异常: PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderExc0019:无
连接Ex:javax.net.ssl.sslHandShakeException:Sun.Security.Validator.ValidatoreXception:PKIX路径构建失败:Sun.Security.Provider.CertPath.SunCertPathBuilderException:找不到请求目标的有效证书路径 代码: