title: StAX parser determination at runtime
body: <p>I have the following code:</p>
  
  <pre><code>XMLInputFactory inputFactory = XMLInputFactory.newInstance();
  XMLStreamReader xmlStreamReader = inputFactory.createXMLStreamReader(inStream);
  this.encoding = xmlStreamReader.getEncoding();
  </code></pre>
  
  <p>...</p>
  
  <p>This code runs fine in both JBoss and Websphere, however in a particular JBoss throws the following exception:</p>
  
  <pre><code>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.&lt;init&gt;(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)
  </code></pre>
  
  <p>Checking WstxInputFactory I see that it extends XMLInputFactory2 instead of XMLInputFactory. </p>
  
  <p>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 ? </p>