0

我一直在开发一个应用程序,它可以解析三个网站页面的信息,然后将解析后的信息显示给用户。自从这工作以来,我在过去的几周里从来没有遇到过任何例外。然后今天当我再次测试解析功能时,我没有得到任何结果,并且 logcat 给出了 SSLHandshakeException 以及一堆系统错误。以下错误来自 logcat:

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)中的任何代码?谢谢你。

4

1 回答 1

2

如果您遇到此问题: 1. 检查您设备的日期/时间。2. 也许您更改了固件版本或安装了一些更新。

于 2013-03-05T19:10:39.427 回答