Getting below exception while running my application :
I am using jboss : 5.1.1 and jdk 1.6.
01:50:04,828 ERROR [[HelloWorld]] Servlet.service() for
Try to switch class loaders.
Grab classloader from your Service class and reset 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.
I had the same problem deploying a USSD gateway with Mobicents Jain Slee, that runs on top of a JBoss AS 5.1.0 GA. The gateway has to connect to a server via SOAP, so I chose JAX-WS and generated the source code from a WSDL with wsimport. By the way, I used a similar procedure to this one to create a child Maven project and generate the java files for JAX-WS.
My first approach was to include all the dependencies in the .war file that is deployed in JBoss.
I think this is achieved by default in Maven, and mvn install
will do it.
In the long run, this approach failed, but at least I needed to know the list of jar files that were included in the .war file, to copy them later in a JBoss directory.
I made a lot of troubleshooting with this approach, and had many different log errors, though the main one was this:
java.util.ServiceConfigurationError: javax.xml.ws.spi.Provider: Provider org.jboss.ws.core.jaxws.spi.ProviderImpl not a subtype
So insted, I added <scope>provided</scope>
to the JAX-WS dependencies. Something like:
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.istack</groupId>
<artifactId>istack-commons-runtime</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
This produced a much lighter .war file.
Now, after deploying the .war file, when my SOAP client tried to connect to the Web Service, and it throwed the exception:
org.jboss.ws.metadata.wsdl.WSDLException: Invalid default namespace: null
at org.jboss.ws.tools.wsdl.WSDLDefinitionsFactory.parse(WSDLDefinitionsFactory.java:134)
at org.jboss.ws.metadata.umdm.ServiceMetaData.getWsdlDefinitions(ServiceMetaData.java:293)
at org.jboss.ws.metadata.builder.jaxws.JAXWSClientMetaDataBuilder.buildMetaData(JAXWSClientMetaDataBuilder.java:84)
at org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.<init>(ServiceDelegateImpl.java:138)
at org.jboss.ws.core.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:63)
at javax.xml.ws.Service.<init>(Service.java:79)
at org.ortelius.UssdServiceImplementation.<init>(UssdServiceImplementation.java:42)
at org.ortelius.OrteliusClient.sendUssdRequestToWs(OrteliusClient.java:28)
It seems that javax.xml.ws.Service
calls org.jboss.ws.core.jaxws.spi.ProviderImpl
, but it should be calling com.sun.xml.ws.spi.ProviderImpl
, so it seems there is a conflict with jar dependencies.
To avoid this problem, it was necessary to:
$JBOSS_HOME/lib/endorsed/
directory.$JBOSS_HOME/lib/endorsed/
directory.
all the jars bundled in my .war file.That basically made it.
I have to confess that to find this out was a real pain, and it took me about four days to get this up & running. I made a lot of troubleshooting with the jar dependencies, checking JBoss logs, remote debugging, comparing Java packages & classes versions, searching for jars online and reading many articles from JBoss manuals, blogs, StackOverflow, JavaRanch, etc...
The SOAP client was really simple, but the deployment in JBoss was pretty problematic. My solution is not very orthodox, since it depends greatly on the jar files dependencies. So I'm not sure if it will work for everyone.
Regards.