Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

java - JavaFX WebView can't load certain sites

I'm trying to use JavaFX's WebView to load this site, but all I get is a blank screen. The WebView is working perfectly fine on other sites; it gets 100/100 on ACID3 and loads other HTTPS sites without any problems whatsoever.

I can't find anything particularly wrong with the site either. It has a proper, non-expired certificate signed by proper CA, and SSL Labs report a B grade. I tried all the major browsers on it and none report any certificate or SSL related issues; the site renders fine on all of them.

Any help would be greatly appreciated. Even a simple "yeah the site's broken for me too" or "no problems here" would help a lot.

I'm using Java SDK 1.8.0_45-b14 on Windows 8.1 64-bit.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Reason is java.lang.Throwable: SSL handshake failed

One solution can be: from this post https://stackoverflow.com/a/5671038/1032167:

     TrustManager trm = new X509TrustManager() {
        public X509Certificate[] getAcceptedIssuers() {return null;}
        public void checkClientTrusted(X509Certificate[] certs, String authType) {}
        public void checkServerTrusted(X509Certificate[] certs, String authType) {}
    };

    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, new TrustManager[] { trm }, null);
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());

There is also post, probably about similar case: JavaFx Webview JDK 8 can not load self signed certificate

How do i know that it was SSL handshake failed

webView.getEngine().getLoadWorker().stateProperty().addListener(
            new ChangeListener<Worker.State>() {
                public void changed(ObservableValue ov, 
                      Worker.State oldState, Worker.State newState) {
            System.out.println(webView.getEngine().getLoadWorker().exceptionProperty());
             ...

also adding add -Djavax.net.debug=all to VMOption shows

URL-Loader-1, handling exception: 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...