Issue
-
When trying to call a SOAP web service from a 7.2 Spring/Faces WAR portlet, the following ServiceConfigurationError is thrown:
java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: com.sun.xml.ws.spi.ProviderImpl not a subtype
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:588)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1236)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1264)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1299)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1384)
at javax.xml.ws.spi.ServiceLoaderUtil.firstByServiceLoader(ServiceLoaderUtil.java:33)
at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:59)
at javax.xml.ws.spi.Provider.provider(Provider.java:66)
at javax.xml.ws.Service.<init>(Service.java:82)
at org.oorsprong.websamples.CountryInfoService.<init>(CountryInfoService.java:44)
at com.test.SOAPProcessor.processSOAPRequest(SOAPProcessor.java:12)
at com.test.ModePhaseListener.afterPhase(ModePhaseListener.java:23)
at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189)
Environment
- DXP 7.2
Resolution
-
This problem can be caused by an instance of type com.sun.xml.ws.spi.ProviderImpl not being "assignable" from class javax.xml.ws.spi.Provider. When this type of problem happens, it almost always means there is a problem of duplicate class definitions in the classpath. As an example, this can occur if the WAR has WEB-INF/jaxws-api.jar and WEB-INF/jaxws-rt.jar but the API is provided out-of-the-box in Liferay DXP's classpath, and the implementation is also available out-of-the-box.
-
As a proof-of-concept, attached are two sample artifacts:
-
sample-faces-portlet-src.zip: This is the source code of the project
-
SampleFacesPortlet.war: This is a slimmed-down 16MB version built from the source code
-
-
Note, this sample only works with Java 8. Java 11 has changed some of the out-of-the-box classpath configurations associated with XML parsing and/or SOAP execution.
-
When the portlet is deployed to a page, you should see:
Check the console log for a list of continents from the SOAP processor
And when you check the console log, you should see:
Continents found: 6
Africa
Antarctica
Asia
Europe
Ocenania
The Americas