2

I have a class that invokes a WEB SERVICE deployed on the Jboss 5. And my Java enviornment is JDK1.6. Here is a code portion:

System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration","org.apache.xerces.parsers.XIncludeAwareParserConfiguration");
final Document doc = this.generateXMLDoc((List) listData);
final String strXMLData = "TestString";
final String endpointURL = PropertyHandler.getValue("printWebServiceEndPoint");
final TestWebService testWebService = new TestWebService(new URL(endpointURL), new QName( "http://test.webservice.xyz/", "TestWebService"));
final TestService tservice = testWebService.getTestServicePort();
final String msg = tservice.print(strXMLData);
if (msg.equals("Abc"))
{
   return false;
}
return true;

I have following jar in my JBOSS_HOME/lib/endorsed directory.

activation.jar, resolver.jar, serializer.jar, stax-api.jar, xalan.jar, xercesImpl.jar, jaxb-api.jar

This webservice is working fine on JBoss4.2.2GA but its breaking on JBoss 5 and throws error given below.

01:50:46,760 INFO  [STDOUT] ERROR 01:50:46,759 (TestServiceInputXMLParser) - com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl cannot be cas to com.sun.xml.bind.api.JAXBRIContext
java.lang.ClassCastException: com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.bind.api.JAXBRIContext
at org.jboss.ws.metadata.umdm.EndpointMetaData.eagerInitializeAccessors(EndpointMetaData.java:665)
at org.jboss.ws.metadata.umdm.EndpointMetaData.initializeInternal(EndpointMetaData.java:545)
at org.jboss.ws.metadata.umdm.EndpointMetaData.eagerInitialize(EndpointMetaData.java:533)
at org.jboss.ws.metadata.builder.jaxws.JAXWSClientMetaDataBuilder.rebuildEndpointMetaData(JAXWSClientMetaDataBuilder.java:312)
at org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.getPortInternal(ServiceDelegateImpl.java:269)
at org.jboss.ws.core.jaxws.spi.ServiceDelegateImpl.getPort(ServiceDelegateImpl.java:200)
at javax.xml.ws.Service.getPort(Service.java:99)
at edu.wustl.webservice.catissuecore.test.TestWebService.getTestServicePort(TestWebService.java:50)
at edu.wustl.catissuecore.testservicemodule.TestServiceInputXMLParser.callTestService(TestServiceInputXMLParser.java:81)
at edu.wustl.catissuecore.action.TestAction.executeXSS(TestAction.java:159)
at edu.wustl.common.action.XSSSupportedAction.checkForXSSViolation(XSSSupportedAction.java:170)
at edu.wustl.common.action.XSSSupportedAction.execute(XSSSupportedAction.java:76)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:320)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.owasp.stinger.StingerFilter.doStinger(StingerFilter.java:365)
at org.owasp.stinger.StingerFilter.doStingerFilter(StingerFilter.java:293)
at org.owasp.stinger.StingerFilter.doFilter(StingerFilter.java:122)

Any pointer will be of great use.

suhas khot
  • 85
  • 1
  • 12

2 Answers2

1

I also had a lot of similar problems with JBoss before. Building your webapp for minimalistic containers e.g. Tomcat requires packing a lot of jar files into your war. However, JBoss already has tons of jars already built in. When the same classes are present in several jars, a classloader usually finds your packed classes first (typically implementation, e.g. jaxb-impl and also loading your jaxb-api), then loads the builtin classes (typically api classes, e.g. builtin jaxb-api) and tries to use your implementation objects with the builtin api. This will fail since they are considered to be very distinct classes from distinct sources despite they may be exactly the same. I've even seen errors stating that "class X cannot be cast to class X" which is very counterintuitive until you understand the reasons.

Consequently, you should always avoid packing jars into your war that are built in to JBoss. Probably there's a better way ( in which case I'm also interested ;-) ), but the only reliable strategy we found was:

  • Check builtin JBoss jar files and match them against your jars packed into your war
  • In case of a match, exclude the jar from your war
  • If matching jars have different versions, change your implementation to use the builtin JBoss version

You can use e.g. a separate JBoss maven profile and the packagingExclude configuration option with the maven-war-plugin to exclude the unnecessary war files.

Zólyomi István
  • 2,401
  • 17
  • 28
  • Yes there is true for JBoss class loader. But I don't have any Jaxbimpl.jar in my war package, since my application is build on Jdk 1.6 which by default has jaxb jars in it. I am deploying my application Jboss 5.x which has jaxb impl jar with different version. If I tries to remove it, Jboss wont start. The same application works with Jboss 7.x with jdk 6 and Jboss 4.2.2 with Jdk 5.0 – suhas khot Aug 12 '13 at 18:20
0

Don't put jaxb/jaxws jars in the endorsed directory - they should already be included in the JBoss container. What has likely happened is that the jaxb-api jar you put in the endorsed directory is a different version of jaxb from the jaxb-impl jar within JBoss.

tdrury
  • 2,307
  • 1
  • 22
  • 25
  • AS I already mentioned above, the endorsed directory contains following jars activation.jar, resolver.jar, serializer.jar, stax-api.jar, xalan.jar, xercesImpl.jar, jaxb-api.jar Also i have tried downloading JAXB 2.1 libs and has replaced in their jboss lib directory and jaxb-api.jar in endorsed lib. This also doesnt solved my problem. – suhas khot Aug 06 '13 at 18:29
  • Also I tried putting jboss-classloading.xml in my war/WEB-INF direcotory. For what i googled it seems like JBoss 5.x doesnt support webservices with jdk 6 I tried every permutation and combinations that I got after googling. But none of them works – suhas khot Aug 06 '13 at 18:34
  • 1
    Does this help: http://stackoverflow.com/questions/14162159/supplying-a-different-version-of-jaxb-for-jax-ws-in-java-1-6 – tdrury Aug 06 '13 at 19:04
  • Thanks for all that but setting System.setProperty("javax.xml.bind.JAXBContext", "com.sun.xml.internal.bind.v2.ContextFactory"); as well I tried specifyign command line arguement Djavax.xml.bind.JAXBContext=com.sun.xml.internal.bind.v2.ContextFactory both this solution didnt worked out. MY webservice request isnt reaching till the actual webservice code. I get the class cast exception at very first few lines. – suhas khot Aug 06 '13 at 19:28
  • I think jbossws-native-core jar under seb service deployer is causing a problem. – suhas khot Aug 06 '13 at 19:31