Today I stumbled upon a Java system property that, when set to one, cause JAXP to output information about which factory implementations is used to instantiate different kinds of factories and where the information is found that these decisions are based upon. The system property is set like this:
-Djaxp.debug=1
In Eclipse, you add the above to the VM arguments of the appropriate launch configuration. In NetBeans, the system property can be added to the project VM Options in the Run category of the project’s properties.
I found the information about this system property in the documentation of the method newInstance of the class SAXParserFactory in the Java SE 7 API documentation.
If I add the above to a Mule project, I obtain the following console output when the project is run. The text in red is the JAXP log output:
INFO: 2013-07-16 19:56:32,459 [main] org.mule.MuleServer: Mule Server initializing...
JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using ClassLoader: null
INFO: 2013-07-16 19:56:32,646 [main] org.mule.lifecycle.AbstractLifecycleManager: Initialising RegistryBroker
INFO: 2013-07-16 19:56:32,834 [main] org.mule.config.spring.MuleApplicationContext: Refreshing org.mule.config.spring.MuleApplicationContext@90ff2a1: startup date [Tue Jul 16 19:56:32 CEST 2013]; root of context hierarchy
JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory
JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl using ClassLoader: null
...
WARN: 2013-07-16 19:56:33,942 [main] org.mule.config.spring.parsers.assembly.DefaultBeanAssembler: Cannot assign class java.lang.Object to interface org.mule.api.AnnotatedObject
JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory
JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl using ClassLoader: null
JAXP: find factoryId =javax.xml.parsers.SAXParserFactory
JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using ClassLoader: null
...
JAXP: find factoryId =javax.xml.stream.XMLOutputFactory
JAXP: found jar resource=META-INF/services/javax.xml.stream.XMLOutputFactory using ClassLoader: sun.misc.Launcher$AppClassLoader@1f517997
JAXP: found in resource, value=com.ctc.wstx.stax.WstxOutputFactory
JAXP: created new instance of class com.ctc.wstx.stax.WstxOutputFactory using ClassLoader: sun.misc.Launcher$AppClassLoader@1f517997
JAXP: find factoryId =javax.xml.stream.XMLInputFactory
JAXP: found jar resource=META-INF/services/javax.xml.stream.XMLInputFactory using ClassLoader: sun.misc.Launcher$AppClassLoader@1f517997
JAXP: found in resource, value=com.ctc.wstx.stax.WstxInputFactory
JAXP: created new instance of class com.ctc.wstx.stax.WstxInputFactory using ClassLoader: sun.misc.Launcher$AppClassLoader@1f517997
JAXP: find factoryId =javax.xml.stream.XMLOutputFactory
JAXP: found jar resource=META-INF/services/javax.xml.stream.XMLOutputFactory using ClassLoader: sun.misc.Launcher$AppClassLoader@1f517997
JAXP: found in resource, value=com.ctc.wstx.stax.WstxOutputFactory
JAXP: created new instance of class com.ctc.wstx.stax.WstxOutputFactory using ClassLoader: sun.misc.Launcher$AppClassLoader@1f517997
...
INFO: 2013-07-16 19:56:34,988 [main] org.mule.lifecycle.AbstractLifecycleManager: Initialising model: _muleSystemModel
...
The above log was generated when an instance Mule ESB is started up and reads one configuration file.
Note that:
- Lines containing “find factoryId” tells us which factory is requested.
- Lines containing “found jar resource” show that a resource specifying which factory type to use has been found in a JAR file.
If the resource resides in META-INF/services then it has the filename indicated after the “META-INF/services/” part, for instance “javax.xml.stream.XMLInputFactory”. - The requested factory id and the filename of the file in META-INF/services are identical.
Actually, the factory id is used to determine the filename to search for. - Lines containing “found in resource, value=” indicate the value of the resource discussed above.
This is the name of the class that will be instantiated in request for the factory.
Happy coding!