X509TrustManager htmlunit implementation available

For some reason, my code with everything imported correctly using Htmlunit throws an error.

package htmlunittesting; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlDivision; import com.gargoylesoftware.htmlunit.html.HtmlPage; public class httpunittest { public static void main(String[] args) throws Exception{ final WebClient webClient = new WebClient(); final HtmlPage page = webClient.getPage("https://blockchain.info/address/17iyEdbcG3G6RrDHYsi2MzG6RY8vRYvjXm"); final HtmlDivision div = page.getHtmlElementById("final_balance"); // final HtmlAnchor anchor = page.getAnchorByName("anchor_name"); System.out.println(div); webClient.closeAllWindows(); } } 

My mistake:

  Caused by: java.security.cert.CertificateException: No X509TrustManager implementation available at sun.security.ssl.DummyX509TrustManager.checkServerTrusted(Unknown Source) ... 27 more 

All I want to do is print the final balance on this test wallet.

Whole StackTrace on request:

 Exception in thread "main" javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No X509TrustManager implementation available 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 org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:275) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:254) at com.gargoylesoftware.htmlunit.HtmlUnitSSLConnectionSocketFactory.connectSocket(HtmlUnitSSLConnectionSocketFactory.java:155) at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:117) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:178) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1313) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1230) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:338) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:392) at htmlunittet.httpunittest.main(httpunittest.java:12) Caused by: java.security.cert.CertificateException: No X509TrustManager implementation available at sun.security.ssl.DummyX509TrustManager.checkServerTrusted(Unknown Source) ... 27 more 

And yes, this is all my code, no other classes.

0
java htmlunit
source share
1 answer

You must add these parameters to the java virtual machine:

  System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); System.setProperty("javax.net.ssl.trustStoreType", "JKS"); System.setProperty("javax.net.ssl.trustStore", "../path/yourtruststore.jks"); System.setProperty("javax.net.ssl.trustStorePassword", "yourpasswordfortruststore"); 

If you need mutual authentication:

  System.setProperty("javax.net.ssl.keyStore","../path../yourkeystore.jks"); System.setProperty("javax.net.ssl.keyStorePassword","yourpasswordforkeystore"); System.setProperty("javax.net.ssl.keyStoreType", "JKS"); 
0
source share

All Articles