3

I'm deploying a Java EE 6 JAX-RS web service on JBoss 6, and I'd like to use Woodstox instead of whatever SAX/StAX parser is currently being used. Since some stack traces list classes in (among other packages):

  • org.apache.xerces.parsers
  • org.apache.xerces.impl
  • org.apache.xerces.jaxp

...I'm guessing that it's using Xerces.

I've tried adding the necessary JARs (woodstox-core-asl-4.1.1.jar and stax2-api-3.1.1.jar) into the EAR (deployed in /lib directory) and also in the WAR (in WEB-INF/lib) but this didn't seem to affect anything, as stack traces from exceptions in XML parsing still reference Xerces packages.

I've already read this question but I think that I've already tried the "add it to your classpath" option as above. I've also already tried adding the following VM args as per this thread:

-Djavax.xml.stream.XMLInputFactory=com.ctc.wstx.stax.WstxInputFactory
-Djavax.xml.stream.XMLOutputFactory=com.ctc.wstx.stax.WstxOutputFactory
-Djavax.xml.stream.XMLEventFactory=com.ctc.wstx.stax.WstxEventFactory
-Dcom.sun.xml.ws.api.streaming.XMLStreamReaderFactory.woodstox=true
-Dcom.sun.xml.ws.api.streaming.XMLStreamWriterFactory.woodstox=true

What am I doing wrong? How do I get JAXB to use Woodstox instead of (I think) Xerces?

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • This really depends on the JAXB implementation that ends up getting used in your environment. That SO thread that you posted a link to mentions that the JAXB implementation that comes with Oracle's JDK by default uses SAX alone to parse XML and won't look at any StAX settings. To use StAX you would need to use a different JAXB implementation such as MOXy (mentioned in that thread). – laz May 06 '11 at 19:16
  • @laz: I am using MOXy already. – Matt Ball May 06 '11 at 19:20

1 Answers1

0

When EclipseLink JAXB (MOXy) creates an XMLStreamReader it does so using the standard APIs, so it should get the one appropriate to your environment:

xmlInputFactory = XMLInputFactory.newInstance();
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(reader);

With that being said, that presupposes that the JBoss JAX-RS implemenation is calling a MOXy code path that allows it to create its own XMLStreamReader (such as unmarshalling an InputStream), and not passing it an actual XMLStreamReader (of JBoss's choosing).

bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • If it makes a difference, I'm using Jersey rather than RESTeasy (JBoss' default JAX-RS implementation). – Matt Ball May 06 '11 at 20:40