0
我一直在開發一個應用程序,它可以解析關於三個網站頁面的信息,然後向用戶顯示解析的信息。自從這個工作以來,我幾個星期以來都沒有遇到任何例外情況。然後,今天當我再次測試解析函數時,我沒有收到任何結果,logcat發出SSLHandshakeException以及一系列系統錯誤。以下錯誤來自logcat:Android SSL握手例外
03-05 17:59:39.834: W/System.err(5525): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
03-05 17:59:39.834: W/System.err(5525): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:374)
03-05 17:59:39.834: W/System.err(5525): at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
03-05 17:59:39.834: W/System.err(5525): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
03-05 17:59:39.834: W/System.err(5525): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
03-05 17:59:39.834: W/System.err(5525): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
03-05 17:59:39.834: W/System.err(5525): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
03-05 17:59:39.834: W/System.err(5525): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
03-05 17:59:39.834: W/System.err(5525): at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:165)
03-05 17:59:39.834: W/System.err(5525): at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:425)
03-05 17:59:39.834: W/System.err(5525): at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:446)
03-05 17:59:39.839: W/System.err(5525): at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
03-05 17:59:39.839: W/System.err(5525): at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
03-05 17:59:39.839: W/System.err(5525): at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
03-05 17:59:39.839: W/System.err(5525): at com.example.queryApp.QueryActivity.onCreate(QueryActivity.java:50)
03-05 17:59:39.839: W/System.err(5525): at android.app.Activity.performCreate(Activity.java:5206)
03-05 17:59:39.839: W/System.err(5525): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-05 17:59:39.839: W/System.err(5525): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-05 17:59:39.839: W/System.err(5525): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-05 17:59:39.844: W/System.err(5525): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-05 17:59:39.844: W/System.err(5525): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-05 17:59:39.844: W/System.err(5525): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 17:59:39.844: W/System.err(5525): at android.os.Looper.loop(Looper.java:137)
03-05 17:59:39.844: W/System.err(5525): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-05 17:59:39.844: W/System.err(5525): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 17:59:39.844: W/System.err(5525): at java.lang.reflect.Method.invoke(Method.java:511)
03-05 17:59:39.844: W/System.err(5525): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-05 17:59:39.849: W/System.err(5525): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-05 17:59:39.849: W/System.err(5525): at dalvik.system.NativeStart.main(Native Method)
03-05 17:59:39.849: W/System.err(5525): Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
03-05 17:59:39.849: W/System.err(5525): at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:192)
03-05 17:59:39.854: W/System.err(5525): at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:163)
03-05 17:59:39.854: W/System.err(5525): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:573)
03-05 17:59:39.854: W/System.err(5525): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
03-05 17:59:39.854: W/System.err(5525): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:371)
03-05 17:59:39.854: W/System.err(5525): ... 27 more
03-05 17:59:39.854: W/System.err(5525): Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
03-05 17:59:39.859: W/System.err(5525): ... 32 more
以下是我的QueryActivity的部分代碼,它負責解析網頁。我將另一個活動的三個網站的url傳遞給QueryActivity,然後我使用Jsoup連接並獲取解析的html。
public class QueryActivity extends Activity
{
String fWebsite = getIntent().getStringExtra("fURL");
String sWebsite = getIntent().getStringExtra("sURL");
String tWebsite = getIntent().getStringExtra("tURL");
try{
Document doc1 = Jsoup.connect(fWebsite).timeout(0).get();
Document doc2 = Jsoup.connect(sWebsite).timeout(0).get();
Document doc3 = Jsoup.connect(tWebsite).timeout(0).get();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
有人能解釋爲什麼會出現這種情況和對這個問題的任何解決方案,並就我知道我沒有在這個活動(QueryActivity)更改任何代碼? 謝謝。
嗨,感謝您的回覆,我檢查了我的設備上的日期/時間,這似乎是正確的。自兩週前以來沒有任何固件更新。我在我應該工作的設備上安裝了這個應用程序的舊版本,它給了我相同的系統錯誤。 – user1832478 2013-03-05 19:21:49
這解決了我的問題。謝謝。否則我不會考慮檢查。 – 2013-05-10 07:42:25