2

we have the following case in the code which causes tests to fail when running with JAVA_HOME set to JDK7 instead of JDK6 (maven with source/target = 1.6)

javax.xml.stream.FactoryConfigurationError: Provider for com.sun.xml.internal.stream.XMLInputFactoryImpl cannot be found
        at javax.xml.stream.XMLInputFactory.newFactory(XMLInputFactory.java:239)

the code itself

private static final String SUN_XML_INPUT_FACTORY = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
private final XMLInputFactory xmlInputFactory;

public theConstructor() {
    // When deployed to WebLogic 10.3.5 it will use "weblogic.xml.stax.XMLStreamInputFactory" which will
    // cause a StreamReader exception as it requires some input stream other than null.
    xmlInputFactory = XMLInputFactory.newFactory(SUN_XML_INPUT_FACTORY, this.getClass().getClassLoader());
}

I suppose I should use something else than private static final String SUN_XML_INPUT_FACTORY = "com.sun.xml.internal.stream.XMLInputFactoryImpl"; but i don't know what.

Viktor Mellgren
  • 4,318
  • 3
  • 42
  • 75
  • u r saying that if at JAVA_HOME enviromental you set JDK 6 , the app is running normally? – AntJavaDev Oct 02 '14 at 10:55
  • It's almost never good to use java internal classes. The point of "internal" is that the implementation can change without notice. – Samuel Åslund Oct 02 '14 at 10:55
  • Have a look at the documentation for "newFactory", it might give you an Idea for how to find a reasonable replacement. http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html#newFactory() – Samuel Åslund Oct 02 '14 at 10:59
  • Are you still deploying to WebLogic 10.3.5, otherwise it might be worth trying the "newFactory" without parameters. – Samuel Åslund Oct 02 '14 at 11:02

1 Answers1

1

I found after JDK6, the method:

javax.xml.stream.XMLInputFactory.newFactory(String factoryId,ClassLoader classLoader)

change it's program.

The parameter factoryId is not a classpath, but a key.

So I put a stax.properties file into my $java.home/jre/lib/ file and the context is:

com.bea.xml.stream.MXParserFactory=com.bea.xml.stream.MXParserFactory

then my problem solved.

XMLInputFactory factory = XMLInputFactory.newFactory("com.bea.xml.stream.MXParserFactory", this.getClass().getClassLoader());
techraf
  • 64,883
  • 27
  • 193
  • 198
Steven
  • 11
  • 1