JDK-8159447 : JavaFX does not resolve resources for WebView when packaged in OSGI bundles
  • Type: Enhancement
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8u91,9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2016-06-14
  • Updated: 2019-03-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux core 3.19.0-51-generic #58~14.04.1-Ubuntu SMP Fri Feb 26 22:02:58 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
I packaged JavaFX in an OSGI bundle and using the WebView from and JFXPanel. 
Loading external URLs with 
webEngine.load(externalURL)
works without problems.

When trying to load bundled HTML resources in the webEngine only an empty scene is displayed, i.e. the resources from the bundle cannot be resolved.
I assume the problem is that the webview cannot resolve resource urls of the form
bundle://117.0:1/info.html
which are a result of the OSGI packaging.

No error message, just empty scene.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- package javafx in an osgi bundle (required to provide access to the javafx components for class loader)
- package an html resource in the package (/src/main/resources/info.html)
- use the JavaFX tutorial/example for WebView and Browser
- try to loadPage from bundle in browser
URL queryURL = getClass().getResource("/info.html");
loadPage(queryURL.toString());
- white scene

Everything works when running same example as application without packaging as OSGI bundle.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The HTML resource should be displayed and referenced resources in the HTML should be resolved, i.e. if an image is referenced relative to the bundle HTML resource it should be resolved from the bundle also.
ACTUAL -
empty scene, nothing displayed

ERROR MESSAGES/STACK TRACES THAT OCCUR :
no error messages, not crash logs.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class Browser extends Region {

	final WebView browser = new WebView();
	final WebEngine webEngine = browser.getEngine();

	public Browser() {
		//apply the styles
		getStyleClass().add("browser");
		
		// external URLs work
		// webEngine.load("http://sabiork.h-its.org/newSearch/index");
		
		// String content works
                // webEngine.loadContent("<html><h1>Hello world</h1></html>");
		
		// Resource content does not work
		URL queryURL = getClass().getResource("/info.html");
		System.out.println(queryURL);    
        loadPage(queryURL.toString());
    
		
		//add the web view to the scene
		getChildren().add(browser);

	}
	
	private void loadPage(String url) {

        Platform.runLater(new Runnable() {
            @Override
            public void run() {

                webEngine.load(url);

            }
        });

    }
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Required to extract all resources from jar in temporary folder on filesystem and reference the resources from there.


Comments
Currently "bundle://" scheme is not supported. Needs an enhancement on the URLLoader to read "bundle://" resource.
22-06-2016

Related to, and possibly a duplicate of, JDK-8152420
14-06-2016