JDK 11; JAX-WS; Provider com.sun.xml.internal.ws.spi.ProviderImpl not found

Viewed 43185

I Need to access legacy SOAP webservices in JDK 11. But I am suffering "ProviderImpl not found."

The JDK 11 implementation is: zulu11.2.3-jdk11.0.1-win_x64.

In my build.gradle, I have the following dependency:

compile group: 'com.sun.xml.ws', name: 'jaxws-rt', version: '2.3.1', ext: 'pom', { force = true }

My WAR file's WEB-INF/lib contains enter image description here

I am seeing:

javax.xml.ws.WebServiceException: Provider com.sun.xml.internal.ws.spi.ProviderImpl not found
    at javax.xml.ws.spi.FactoryFinder$1.createException(FactoryFinder.java:61) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.FactoryFinder$1.createException(FactoryFinder.java:58) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.ServiceLoaderUtil.newInstance(ServiceLoaderUtil.java:103) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:112) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.Provider.provider(Provider.java:96) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.Service.<init>(Service.java:112) ~[jaxws-api-2.3.1.jar:na]

Following https://github.com/javaee/metro-jax-ws/issues/1247 I have tried setting:

-Djavax.xml.ws.spi.Provider=com.sun.xml.ws.spi.ProviderImpl

But I still get:

javax.xml.ws.WebServiceException: Provider com.sun.xml.ws.spi.ProviderImpl not found
    at javax.xml.ws.spi.FactoryFinder$1.createException(FactoryFinder.java:61) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.FactoryFinder$1.createException(FactoryFinder.java:58) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.ServiceLoaderUtil.newInstance(ServiceLoaderUtil.java:103) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.FactoryFinder.fromSystemProperty(FactoryFinder.java:122) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:99) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.Provider.provider(Provider.java:96) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.Service.<init>(Service.java:112) ~[jaxws-api-2.3.1.jar:na]
    ...
Caused by: java.lang.ClassNotFoundException: com.sun.xml.ws.spi.ProviderImpl
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na]
    at javax.xml.ws.spi.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:90) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:123) ~[jaxws-api-2.3.1.jar:na]
    at javax.xml.ws.spi.ServiceLoaderUtil.newInstance(ServiceLoaderUtil.java:101) ~[jaxws-api-2.3.1.jar:na]
    ... 22 common frames omitted

I have verified that com.sun.xml.ws.spi.ProviderImpl IS available:

enter image description here

Is there a known working example of this combination available "out there"?

Thoughts/suggestions gratefully accepted.

3 Answers

I got the exact same error calling soap-webservices in java11. I finally got it to work in my testproject by adding the following dependency to pom.xml

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>rt</artifactId>
    <version>2.3.1</version>
</dependency>

As my production environment is not converted to maven yet, I then found out that I needed these jar-files on the classpath:

jaxb-runtime-2.3.1.jar
jaxws-api-2.3.1.jar
javax.xml.soap-api-1.4.0.jar
rt-2.3.1.jar
streambuffer-1.5.3.jar
policy-2.7.5.jar
stax-ex-1.8.jar
javax.jws-api-1.1.jar
saaj-impl-1.5.0.jar
gmbal-api-only-3.1.0-b001.jar 

I worked this out with this artifact:

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.3.5</version>
</dependency>

or gradle

implementation 'com.sun.xml.ws:jaxws-rt:2.3.5'

You can check other versions and which artifacts depends this one here: https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt/2.3.5 .

I got the same error as well. From a Spring application I called an OSGI bundle which did a SOAP request. Right before the call within that OSGI bundle a class loader switch solved the problem.

Use the classloader from your SOAP Service class and reset the classloader after the call.

    final ClassLoader targetClassLoader = ServiceXY.class.getClassLoader();
    final Thread currentThread = Thread.currentThread();
    final ClassLoader contextClassLoader = currentThread.getContextClassLoader();
    try {
           currentThread.setContextClassLoader(targetClassLoader);
           //here call your Service 
    } finally {
           currentThread.setContextClassLoader(contextClassLoader);
    }

JEE libs have been removed with Java 9, JEE-specific libs / implementations must now be made available by the application via thirdparty libraries - e.g. jaxws-api.jar and jaxws-rt.jar. This code of JEE libs often still expects to be part of the jre system library and with that of the application classloader - but it isn't anymore. So if service classloader ServiceXY.class.getClassLoader() and your application classloader Thread.currentThread().getContextClassLoader() are different you need to switch for the request.

Related