title: Classloader issue in WebSphere Application server 7.x
body: <blockquote>
    <p>com.ibm.xml.xlxp2.api.stax.XMLOutputFactoryImpl incompatible with
    javax.xml.stream.XMLOutputFactory</p>
    
    <p>com.ibm.xml.xlxp2.api.stax.XMLOutputFactoryImpl incompatible with
    javax.xml.stream.XMLInputFactory</p>
  </blockquote>
  
  <p>Removed "jsr173_1.0_api.jar", "stax-api-1.0-2.jar" that has "XMLOutputFactory" and "XMLInputFactory" classes from APP(Web-inf/lib) to avoid any collision with server versions. </p>
  
  <p>Also changed the war class loader order to "parent last" and
  policy to "Single class loader for application" in WebSphere admin
  console. Have made this change to give priority to application jars <code>WebInf/lib</code> than server jars.</p>
  
  <p>Below is the stack-trace. </p>
  
  <pre><code>java.lang.ClassCastException: com.ibm.xml.xlxp2.api.stax.XMLOutputFactoryImpl incompatible with javax.xml.stream.XMLOutputFactory
                                   javax.faces.FacesException: #{tBean.persist}: java.lang.ClassCastException: com.ibm.xml.xlxp2.api.stax.XMLOutputFactoryImpl incompatible with javax.xml.stream.XMLOutputFactory
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
      at javax.faces.component.UICommand.broadcast(UICommand.java:315)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1655)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1595)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131)
      at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
      at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
      at com.testtech.myapp.admin.authentication.UrlAuthorization.doFilter(Unknown Source)
      at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
      at com.testtech.myapp.admin.authentication.UrlAuthentication.doFilter(Unknown Source)
      at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
      at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:114)
      at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:895)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:932)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:500)
      at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
      at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864)
      at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:183)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384)
      at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
      at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
      at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
      at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
      at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
      at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
      at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
      at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
  Caused by: javax.faces.el.EvaluationException: java.lang.ClassCastException: com.ibm.xml.xlxp2.api.stax.XMLOutputFactoryImpl incompatible with javax.xml.stream.XMLOutputFactory
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      ... 42 more
  Caused by: java.lang.ClassCastException: com.ibm.xml.xlxp2.api.stax.XMLOutputFactoryImpl incompatible with javax.xml.stream.XMLOutputFactory
      at javax.xml.stream.XMLOutputFactory.newInstance(XMLOutputFactory.java:98)
      at com.thoughtworks.xstream.io.xml.StaxDriver.getOutputFactory(StaxDriver.java:157)
      at com.thoughtworks.xstream.io.xml.StaxDriver.createWriter(StaxDriver.java:109)
      at com.thoughtworks.xstream.XStream.toXML(XStream.java:802)
      at com.thoughtworks.xstream.XStream.toXML(XStream.java:792)
      at com.testtech.UI.z.service.zService.createz(Unknown Source)
      at com.testtech.UI.z.web.zBean.persist(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
      at java.lang.reflect.Method.invoke(Method.java:600)
      at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
      at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
      ... 43 more
  </code></pre>
  
  <p>JSF2.1.2<br />
  Spring 3.1.0<br />
  Prettyfaces-jsf2-3.3.2<br />
  Primefaces 3.2 <br />
  WebSphere Application Server 7.0.0.9 <br /></p>
  
  <blockquote>
    <p><a href="http://pic.dhe.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Fttrb_classload_viewer.html" rel="nofollow">ibm page</a> <br />
    When troubleshooting class loading problems, you might need to
    override classes visible to a parent class loader. To override such
    classes with those specific to an application, set the Class loader
    mode to Parent last on the class loader that contains the application
    classes on its classpath. An application can override classes visible
    to a parent class loader, but doing so can result in a
    ClassCastException or UnsatisfiedLinkError if there is a mixed use of
    overridden classes and non-overridden classes.</p>
  </blockquote>