2014-01-21 70 views
0

我正在嘗試使用twitter4j 3.0.5的簡單twitter搜索示例。當我運行這個樣本沒有代理這是工作,但在代理它如下拋出一個異常:twitter4j 3.0.5:sun.security.validator.ValidatorException:PKIX路徑構建失敗

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 sentiment.main(sentiment.java:33) 
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 

請讓我知道是否有這個問題的解決方案。

回答

1

該問題與twitter4J中的SSL支持有關。 Twitter已棄用2014年1月14日對普通HTTP請求的支持。您必須在每個請求中使用HTTPS。當您在Tomcat服務器中添加CA證書時,您的問題就會解決。

+0

你能告訴如何? – saplingPro

1

DeepakGangore是正確的

這花了我組織了幾個試驗在我們的督促預ENVS以確定我們的n層堆棧上的所有運動部件,屬於根CA和第三方庫。

對於我的組織......的解決辦法是:

1)更新twitter4j庫是版本3.0.5
2)更新應用程序服務器JDK安裝的JRE cacerts文件,與JDK JRE7版本。

這個組合,解決了我們的應用程序能夠與api.twitter.com端點交談的能力。

相關問題