Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX - Open Url in chrome browser [duplicate]

I have an Url that will work only under chrome browser. I opened an url in webview but it doesn't work in it. I got the following error. So I would like to open it in chrome browser. Is it possible? if yes, Please help me.

Code
 WebView browser = new WebView();

 WebEngine webEngine = browser.getEngine();

 System.out.println(webEngine);
 webEngine.load(url);

 Scene scene = new Scene(browser);
 stage.setScene(scene);
 stage.show();

Error

Jun 13, 2014 3:43:06 PM com.sun.webpane.webkit.network.URLLoader doRun
WARNING: Unexpected error
javax.net.ssl.SSLProtocolException: Extensions not allowed in v2 certificate
    at sun.security.ssl.HandshakeMessage$CertificateMsg.<init>(HandshakeMessage.java:451)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:515)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
    at com.sun.webpane.webkit.network.URLLoader.sendRequest(URLLoader.java:322)
    at com.sun.webpane.webkit.network.URLLoader.doRun(URLLoader.java:141)
    at com.sun.webpane.webkit.network.URLLoader.access$000(URLLoader.java:44)
    at com.sun.webpane.webkit.network.URLLoader$1.run(URLLoader.java:106)
    at com.sun.webpane.webkit.network.URLLoader$1.run(URLLoader.java:103)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.webpane.webkit.network.URLLoader.run(URLLoader.java:103)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.security.cert.CertificateParsingException: Extensions not allowed in v2 certificate
    at sun.security.x509.X509CertInfo.parse(X509CertInfo.java:736)
    at sun.security.x509.X509CertInfo.<init>(X509CertInfo.java:169)
    at sun.security.x509.X509CertImpl.parse(X509CertImpl.java:1788)
    at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:202)
    at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:97)
    at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
    at sun.security.ssl.HandshakeMessage$CertificateMsg.<init>(HandshakeMessage.java:449)
    ... 23 more
like image 844
naresh Avatar asked Jun 13 '14 09:06

naresh


1 Answers

Yeah, you can launch the user's default browser from within Java. It may not be Chrome though. Here's an example launching the browser using a button:

Button button = new Button("Example Button");

button.setOnAction(new EventHandler<ActionEvent>() {
   @Override public void handle(ActionEvent e) {
        try {
            Desktop.getDesktop().browse(new URI("http://www.example.com"));
        } catch (IOException e1) {
            e1.printStackTrace();
        } catch (URISyntaxException e1) {
            e1.printStackTrace();
        }
        }
    }
);
like image 74
Kevin Reynolds Avatar answered Oct 06 '22 10:10

Kevin Reynolds