Log4J JAXB Impact
I am migrating SOAP WS application from WL10 to WL12. We are having a problem with how JAXB interprets this XML element:
<sch:testVar xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
In WL10, JAXB maps this to a null object correctly. In WL12, JAXB will convert this to an empty string.
After a lot of research about classpaths and data binding providers, we finally tracked down the problem ... Log4J.
We are using Maven and adding Log4J 1.2.16 dependency. When Log4J is in the application, the XML above is displayed as an empty string. By only removing Log4J's pom dependency, JAXB renders the XML above as null.
Does anyone know why Log4J will affect JAXB?
A few notes:
- We know how WL12 changed JAXB implementations. We spent a few days changing the classes and dependencies.
- We are working with a very stripped down application. Our other dependencies include Spring (core, context support, web, tx, ws-core). 3.1.1. It's him.
- Our testing endpoint does nothing other than infer what the object is.
- Log4J2 works great.
- Log4J 1.2.16 dependency does not contain any other dependencies
The dependency tree from maven assembly is below:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ RJM-Training-SOAP-WS ---
[INFO] com.mycompany:RJM-Training-SOAP-WS:war:0.0.1-SNAPSHOT
[INFO] +- org.springframework:spring-core:jar:3.1.1.RELEASE:compile
[INFO] | +- org.springframework:spring-asm:jar:3.1.1.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-context-support:jar:3.1.1.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:3.1.1.RELEASE:compile
[INFO] | \- org.springframework:spring-context:jar:3.1.1.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:3.1.1.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:3.1.1.RELEASE:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-tx:jar:3.1.1.RELEASE:compile
[INFO] | \- org.springframework:spring-aop:jar:3.1.1.RELEASE:compile
[INFO] +- org.springframework.ws:spring-ws-core:jar:2.1.2.RELEASE:compile
[INFO] | +- org.springframework.ws:spring-xml:jar:2.1.2.RELEASE:compile
[INFO] | +- org.springframework:spring-oxm:jar:3.1.3.RELEASE:compile
[INFO] | | \- commons-lang:commons-lang:jar:2.5:compile
[INFO] | +- org.springframework:spring-webmvc:jar:3.1.3.RELEASE:compile
[INFO] | \- wsdl4j:wsdl4j:jar:1.6.1:compile
[INFO] \- log4j:log4j:jar:1.2.16:compile
The JAXB context we are using is below:
[user@server logs]$ grep JAXBContext WSServer01.log.out
[Loaded javax.xml.bind.JAXBContext from /opt/weblogic/wl12.1.2.0/wlserver/../oracle_common/modules/endorsed/javax-xml-bind.jar]
[Loaded com.sun.xml.bind.v2.runtime.JAXBContextImpl from file:/opt/weblogic/wl12.1.2.0/oracle_common/modules/com.sun.xml.bind.jaxb-impl_2.2.jar]
[Loaded com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder from file:/opt/weblogic/wl12.1.2.0/oracle_common/modules/com.sun.xml.bind.jaxb-impl_2.2.jar]
[Loaded com.sun.xml.bind.v2.runtime.JAXBContextImpl$5 from file:/opt/weblogic/wl12.1.2.0/oracle_common/modules/com.sun.xml.bind.jaxb-impl_2.2.jar]
[Loaded com.sun.xml.bind.v2.runtime.JAXBContextImpl$6 from file:/opt/weblogic/wl12.1.2.0/oracle_common/modules/com.sun.xml.bind.jaxb-impl_2.2.jar]
[Loaded com.sun.xml.bind.v2.runtime.JAXBContextImpl$3 from file:/opt/weblogic/wl12.1.2.0/oracle_common/modules/com.sun.xml.bind.jaxb-impl_2.2.jar]
[Loaded com.sun.xml.bind.v2.runtime.JAXBContextImpl$7 from file:/opt/weblogic/wl12.1.2.0/oracle_common/modules/com.sun.xml.bind.jaxb-impl_2.2.jar]
[Loaded com.sun.xml.bind.v2.runtime.JAXBContextImpl$1 from file:/opt/weblogic/wl12.1.2.0/oracle_common/modules/com.sun.xml.bind.jaxb-impl_2.2.jar]
[Loaded com.sun.xml.bind.v2.runtime.JAXBContextImpl$2 from file:/opt/weblogic/wl12.1.2.0/oracle_common/modules/com.sun.xml.bind.jaxb-impl_2.2.jar]
I went into the code and registered the JAXB class used. It's the same in both cases.
file:/opt/weblogic/wl12.1.2.0/oracle_common/modules/endorsed/javax-xml-bind.jar!/javax/xml/bind/JAXBContext.class
source to share
Someone has internally figured out the root cause of the problem. The solution is to change the implementation of the messageFactory that Spring WS uses. I added this bean definition to my project:
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="messageFactory">
<bean class="com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl"/>
</property>
</bean>
When Log4J 1.x was loaded, it was loading a new version of the SAAJ API which was causing nillable issues. Log4J 2.x worked because it was running the old SAAJ implementation by default.
We can use Log4J 1.x if we specify the above messageFactory.
source to share