We're trying to migrate from JExplorer to JXBrowser. We're injecting a javascript function in the webpage context. That function in turn calls a webservice and does some processing with the result.
The webservice call works fine on its own but fails when called by JXBrowser. The same code worked fine with JExplorer. We're using jaxws-rt (Metro) as our SOAP library (our own supplied version, not the JDK bundled version).
Here's an SSCCE:
Main.java
public class Main {
public static void main(String[] args) {
System.out.println("calling service from main");
callService();
Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
JFrame frame = new JFrame("JxBrowser - Hello World");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(500, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.addScriptContextListener(new ScriptContextAdapter() {
@Override
public void onScriptContextCreated(ScriptContextEvent event) {
Browser browser = event.getBrowser();
JSValue window = browser.executeJavaScriptAndReturnValue("window");
window.asObject().setProperty("call", (JSFunctionCallback) args -> callService());
}
});
System.out.println("calling service from web page");
browser.loadHTML("<html><head></head><body onload='call()'><h1>Hello World!</h1></body></html>");
}
private static Object callService() {
System.out.println("entering callService()");
Object result = null;
try {
URL wsdlSource = new URL("http://www.dneonline.com/calculator.asmx?WSDL");
QName serviceName = new QName("http://tempuri.org/", "Calculator");
ServiceDelegate delegate = com.sun.xml.ws.spi.ProviderImpl.INSTANCE.createServiceDelegate(wsdlSource, serviceName, Service.class);
CalculatorSoap port = delegate.getPort(CalculatorSoap.class);
result = port.add(2, 3);
System.out.println("result: " + result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sscce</groupId>
<artifactId>sscce</artifactId>
<version>1.0.0</version>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>wsimport</id>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlUrls>
<wsdlUrl>http://www.dneonline.com/calculator.asmx?WSDL</wsdlUrl>
</wsdlUrls>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>
<dependency>
<groupId>com.teamdev.jxbrowser</groupId>
<artifactId>jxbrowser-win32</artifactId>
<version>6.22</version>
</dependency>
<dependency>
<groupId>com.teamdev.jxbrowser</groupId>
<artifactId>jxbrowser-license</artifactId>
<version>6.0</version>
</dependency>
</dependencies>
</project>
The program prints the following:
calling service from main
entering callService()
result: 5
calling service from web page
entering callService()
janv. 15, 2019 3:19:53 PM com.sun.xml.ws.spi.db.BindingContextFactory$1 hasNext
WARNING: skipping factory: ServiceConfigurationError: com.sun.xml.ws.spi.db.BindingContextFactory: Provider com.sun.xml.ws.db.glassfish.JAXBRIContextFactory is specified in jar:file:/C:/Users/xxx/.m2/repository/com/sun/xml/ws/jaxws-rt/2.2.10/jaxws-rt-2.2.10.jar!/META-INF/services/com.sun.xml.ws.spi.db.BindingContextFactory but not found
janv. 15, 2019 3:19:53 PM [com.sun.xml.ws.assembler.MetroConfigLoader] init
WARNING: MASM0010: Unable to unmarshall metro config file from location [ jar:file:/C:/Users/xxx/.m2/repository/com/sun/xml/ws/jaxws-rt/2.2.10/jaxws-rt-2.2.10.jar!/META-INF/jaxws-tubes-default.xml ]
java.lang.NullPointerException
at javax.xml.bind.ContextFinder.find(ContextFinder.java:326)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:431)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:394)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:298)
at com.sun.xml.ws.assembler.MetroConfigLoader.createJAXBContext(MetroConfigLoader.java:280)
at com.sun.xml.ws.assembler.MetroConfigLoader.loadMetroConfig(MetroConfigLoader.java:256)
at com.sun.xml.ws.assembler.MetroConfigLoader.init(MetroConfigLoader.java:146)
at com.sun.xml.ws.assembler.MetroConfigLoader.<init>(MetroConfigLoader.java:119)
at com.sun.xml.ws.assembler.TubelineAssemblyController.getTubeCreators(TubelineAssemblyController.java:93)
at com.sun.xml.ws.assembler.MetroTubelineAssembler.createClient(MetroTubelineAssembler.java:118)
at com.sun.xml.ws.client.Stub.createPipeline(Stub.java:343)
at com.sun.xml.ws.client.Stub.<init>(Stub.java:310)
at com.sun.xml.ws.client.Stub.<init>(Stub.java:243)
at com.sun.xml.ws.client.Stub.<init>(Stub.java:258)
at com.sun.xml.ws.client.sei.SEIStub.<init>(SEIStub.java:98)
at com.sun.xml.ws.client.WSServiceDelegate.getStubHandler(WSServiceDelegate.java:829)
at com.sun.xml.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:818)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:451)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:419)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:474)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:478)
at sscce.Main.callService(Main.java:57)
at sscce.Main.access$0(Main.java:50)
at sscce.Main$1.lambda$0(Main.java:42)
at com.teamdev.jxbrowser.chromium.JSContext.a(SourceFile:1613)
at com.teamdev.jxbrowser.chromium.JSContext$a.onMessageReceived(SourceFile:666)
at com.teamdev.jxbrowser.chromium.internal.ipc.q.a(SourceFile:1084)
at com.teamdev.jxbrowser.chromium.internal.ipc.r.run(SourceFile:68)
at com.teamdev.jxbrowser.chromium.internal.r.run(SourceFile:79)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Any ideas?
Thanks!
I contacted the JXBrowser support team. They suggested the use of the jxbrowser.threads.configureContextClassLoader
system property as described here https://jxbrowser.support.teamdev.com/support/discussions/topics/9000044535.
Setting it to true fixed the issue.