JavaFX WebView disable Same origin policy (allow cross domain requests)


Question

I'm developing a JavaFX application that is mostly a glorified web page. It's a desktop application (it's no embedded into a web page) and it has a Web View for the main UI. The application itself serves the sole purpose of accessing Bluetooth devices using Bluecove because that's not possible directly with JavaScript on a web browser.

The proof of concept works ok (I was able to call JavaScript code from Java and vice-versa) but I have one extra requirement of calling arbitrary web services/API from within JavaScript but this violates the same origin policy (similar to this on Android: Allow remote ajax calls in an Android Webview + jquery mobile). Is this possible on JavaFX? Any tips?

P.S.: I'm using JavaFX 2.2.

1
7
5/23/2017 12:10:49 PM

Basically, javaFx has the issue which is coupled with CORS - https://javafx-jira.kenai.com/browse/RT-35868. Assuming that web services which you are using, have CORS enabled you can try the following approach:

  • System.setProperty("sun.net.http.allowRestrictedHeaders", "true")

OR

  • java -Dsun.net.http.allowRestrictedHeaders=true <your main class here>

Hope it will help you

6
9/29/2014 1:38:48 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon