Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 335
petersaints Avatar asked Apr 25 '13 13:04

petersaints


1 Answers

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

like image 193
Ilya Buziuk Avatar answered Sep 16 '22 11:09

Ilya Buziuk