开发者

Can't catch the exception - Java with HtmlUnit?

开发者 https://www.devze.com 2023-03-25 12:40 出处:网络
I don\'t understand what\'s going on ??? I have the following code : public static void main(String[] args){

I don't understand what's going on ???

I have the following code :

public static void main(String[] args){ 

    WebClient wc = null;
    HtmlPage hp = null;
    ArrayList<Product> allProducts;
    try{
        wc = new WebClient(BrowserVersion.FIREFOX_3_6);
        hp = wc.getPage("http://www.mega.co.il/");
    }catch (Exception e) {

    }
    finally{
        allProducts = getProducts(wc, hp);
        for (Product product : allProducts) {
            System.out.println(product);
        }
    }
}

and still the console shows an javax.net.ssl.SSLPeerUnverifiedException being thrown in the hp = wc.getPage("http://www.mega.co.il/"); line :

    Aug 3, 2011 10:45:19 PM com.gargoylesoftware.htmlunit.html.BaseFrame loadInnerPageIfPossible
SEVERE: IOException when getting content for iframe: url=[http://www.mega.co.il/jsfweb/logins/rightLoginHPIframe.jsf]
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
    at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(Unknown Source)
    at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
    at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:339)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:1开发者_如何学运维23)
    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147)
    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:597)
    at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:133)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1405)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1459)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1324)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:303)
    at com.gargoylesoftware.htmlunit.html.BaseFrame.loadInnerPageIfPossible(BaseFrame.java:141)
    at com.gargoylesoftware.htmlunit.html.BaseFrame.loadInnerPage(BaseFrame.java:100)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.loadFrames(HtmlPage.java:1763)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:204)
    at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:436)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:369)
    at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:354)
    at DBSniffer.main(DBSniffer.java:107)

can someone explain me what's going on?

P.S

Somehow the application proceed to run !?

Thanks in advance, Dan


The exception printed is never propagated to your catch clause. It is caught internally, and printed on standard error.

To suppress the warnings you need to tell the API not to print them.

Try the following:

webClient.setThrowExceptionOnScriptError(false);
webClient.setPrintContentOnFailingStatusCode(false);
webClient.setThrowExceptionOnScriptError(false);
0

精彩评论

暂无评论...
验证码 换一张
取 消