Javafx - 在webview组件中打开login.microsoftonline.com页面 [英] Javafx - open login.microsoftonline.com page in webview component

查看:344
本文介绍了Javafx - 在webview组件中打开login.microsoftonline.com页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javafx的webview组件中打开login.microsoftonline.com页面时遇到问题。我只是应该打开这个页面的代码没有任何问题:

I have problem with opening login.microsoftonline.com page in webview component from javafx. I have simply code that should open this page without any trouble:

   WebView webView = new WebView();
    WebEngine webEngine = webView.getEngine();
    var url = "https://login.microsoftonline.com/";
    webEngine.load(url);

    VBox root = new VBox();
    root.getChildren().add(webView);
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();

    webEngine.getLoadWorker().stateProperty().addListener((obs, oldValue, newValue) -> { 
     System.out.println(webEngine.getLocation());
    });

当我尝试在带有Windows操作系统的机器上执行此代码时,我收到空白页:

当我在macbook上执行相同的代码时,网站正在打开:

When I try to execute this code on machine with windows operating system I receive blank page: When I execute the same code on macbook, site is opening:

我正在使用java 10而且真的不知道出了什么问题。有没有人有同样的问题?知道如何解决这个问题吗?也许有其他组件而不是webview,我可以用来做我的东西?

I'm using java 10 and really no idea what's wrong. Does anybody have the same issue? Any idea how to solve this problem? maybe there is other component instead of webview that I can use to do my stuff?

推荐答案

有同样的问题,我想我发现关键点:外部脚本/链接完整性失败。
这不是平台浏览器问题,JavaFX(OpenJFK)依赖于嵌入式webkit引擎。

Had the same issue and I think I found the critical point: external script/link integrity fails. This is not a platform browser issue, JavaFX (OpenJFK) relies on an embedded webkit engine.

在Windows JDK上版本40和版本172之间发生回归8.
它适用于Oracle JDK 9.0.4
它不适用于Oracle JDK 11

The regression happened between version 40 and version 172 on windows JDK 8. It's working fine with Oracle JDK 9.0.4 It's not working with Oracle JDK 11

更多详细信息:
< a href =https://github.com/mguessan/davmail/issues/12 =nofollow noreferrer> https://github.com/mguessan/davmail/issues/12

类似的问题: Javafx - 在webview组件中打开login.microsoftonline.com页面

=>更新的答案:已实施以覆盖Microsoft表单内容并禁用完整性校验。这不是webkit错误的修复,只是解决方法

=> Updated answer: implemented to override Microsoft form content and disable integrity check. This is not a fix of the webkit bug, just a workaround

try {
    URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
        @Override
        public URLStreamHandler createURLStreamHandler(String protocol) {
            if ("https".equals(protocol)) {
                return new sun.net.www.protocol.https.Handler() {
                    @Override
                    protected URLConnection openConnection(URL url, Proxy proxy) throws IOException {
                        System.out.println("openConnection " + url);

                        if (url.toExternalForm().endsWith("/common/handlers/watson")) {
                            System.out.println("Failed: form calls watson");
                        }
                        final HttpsURLConnectionImpl httpsURLConnection = (HttpsURLConnectionImpl) super.openConnection(url, proxy);
                        if ("login.microsoftonline.com".equals(url.getHost())
                                && "/common/oauth2/authorize".equals(url.getPath())) {

                            return new URLConnection(url) {
                                @Override
                                public void connect() throws IOException {
                                    httpsURLConnection.connect();
                                }

                                public InputStream getInputStream() throws IOException {
                                    byte[] content = readFully(httpsURLConnection.getInputStream());
                                    String contentAsString = new String(content, "UTF-8");
                                    System.out.println(contentAsString);
                                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                    baos.write(contentAsString.replaceAll("integrity", "integrity.disabled").getBytes("UTF-8"));
                                    return new ByteArrayInputStream(baos.toByteArray());
                                }

                                public OutputStream getOutputStream() throws IOException {
                                    return httpsURLConnection.getOutputStream();
                                }

                            };

                        } else {
                            return httpsURLConnection;
                        }
                    }

                };
            }
            return null;
        }
    });
} catch (Throwable t) {
    System.out.println("Unable to register custom protocol handler");
}

这篇关于Javafx - 在webview组件中打开login.microsoftonline.com页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆