I have the following code:
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader xmlStreamReader = inputFactory.createXMLStreamReader(inStream);
this.encoding = xmlStreamReader.getEncoding();
...
This code runs fine in both JBoss and Websphere, however in a particular JBoss throws the following exception:
java.lang.ClassCastException: com.ctc.wstx.stax.WstxInputFactory cannot be cast to javax.xml.stream.XMLInputFactory
at javax.xml.stream.XMLInputFactory.newInstance(XMLInputFactory.java:136)
at es.gema.core.shared.dim.data.XFacturaE.detectVersion(XFacturaE.java:115)
at es.gema.core.shared.dim.data.XFacturaE.<init>(XFacturaE.java:67)
at es.gema.core.shared.dim.bc.InvoiceLoader.readXMLInvoice(InvoiceLoader.java:544)
at es.gema.core.shared.dim.bc.InvoiceLoader.loadInvoiceFACE(InvoiceLoader.java:137)
at es.gema.core.expenses.fac.bc.InvoiceServicesBC.execute(InvoiceServicesBC.java:127)
at es.gema.core.expenses.fac.bc.InvoiceServicesBC.execute(InvoiceServicesBC.java:92)
Checking WstxInputFactory I see that it extends XMLInputFactory2 instead of XMLInputFactory.
What's the recommended approach in this case? Create an instance of WstxInputFactory without using the factory, or configure the Java container to return a parser that extends XMLInputFactory ?