Apache CXF SOAP JAXB issue on WebLogic 12c
Asked Answered
F

4

6

We are using Java 8, Apache CXF as a SOAP client on top of Spring Boot to send SOAP messages to WS.

If the app is deployed as a WAR on Tomcat 8, the app works well and the SOAP client is sending the right XML messages with the right namespaces.

If the same app WAR is deployed on Weblogic 12c the SOAP message that is produced by the CXF SOAP client has missing namespaces.

We know that the WebLogic maybe uses some old JAXB jars that are responsible for creating the XML message from Java objects and they are different then the Tomcat server and this maybe the reason why we are seeing this issue.

We also know that we can specify in the weblogic.xml in the war file what jars the Weblogic needs to load from the war and what dependencies to load from directly from the Weblogic libraries, but every combination that we tried in the weblogic.xml does not work.

Any good advice will be fully appreciated

Sample XML output from Tomcat server with Apache CXF

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
    <event xmlns="http://www.test.com" xmlns:ns5="http://www.test2.com" xmlns:ns3="urn:test1:1423.15465:123123:namespace">
        <ns5:created-date-time>2020-08-12T08:02:35Z</ns5:created-date-time>
        <ns5:payload>
            <Test2>
                <ns3:ID>f14bb</ns3:ID>
                <ns3:createdDateTime>2020-08-12T08:02:35Z</ns3:createdDateTime>
            </Test2>
        </ns5:payload>
    </event>
</env:Body>

</env:Envelope>

Sample code from Weblogic 12c

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
    <event xmlns="http://www.test.com" xmlns:ns5="http://www.test2.com">
        <ns5:created-date-time>2020-08-12T08:02:35Z</ns5:created-date-time>
        <ns5:payload>
            <Test2>
                <ID>f14bb</ID>
                <createdDateTime>2020-08-12T08:02:35Z</createdDateTime>
            </Test2>
        </ns5:payload>
    </event>
</env:Body>

</env:Envelope>

The "urn:test1:1423.15465:123123:namespace" is completely ignored in the weblogic server making this XML message not valid by the consumer

weblogic.xml we are trying to tell weblogic to load our classes from the war file instead of the JaxB classes from the web logic but without success

<wls:container-descriptor>
    <wls:prefer-application-packages>
        <wls:package-name>java.xml.bind.*</wls:package-name>
        <wls:package-name>org.apache.cxf.*</wls:package-name>
        <wls:package-name>javax.xml.ws.*</wls:package-name>
        <wls:package-name>javax.wsdl.*</wls:package-name>
</wls:prefer-application-resources>
    </wls:container-descriptor>

Except this issue everything else is working fine, the Apache CXF is sending correct in multiple scenarios, just in one is it not adding the namespace we need

Flavin answered 12/8, 2020 at 15:30 Comment(6)
Please provide the error message from the log file, your deployment descriptor and your source code to check it. Also the version of Weblogic i.e. Weblogic 12.2.1.4Adara
It would be handy also to provide the combinations in weblogic.xml. I assume you tried already: benchresources.net/…Fluoroscope
@Fluoroscope the question is updatedFlavin
@Adara please review the update info in the questionFlavin
@Flavin by any chance did you find a solution not involving changing the package-info? I'm struggling too but neither combination of application packages seems to do the jobMisleading
@Misleading this issue created big problems for our production and this was the only thing i have found and implement, and i didn't spend any more time on this, sorry i didn't find better solution related to thisFlavin
F
1

This issue was solved by updating the package-info.java

@javax.xml.bind.annotation.XmlSchema(namespace = "urn:test1",
    xmlns = {@XmlNs(prefix = "",
         namespaceURI = "http://www.test.com")},
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)

This is the part of the package-info that was not been there before

xmlns = {@XmlNs(prefix = "", namespaceURI = "http://www.test.com")}

adding the namespace trick JavaXB to add the original namespace

Flavin answered 4/9, 2020 at 8:26 Comment(0)
A
1

It looks like you are describing a class loading problem here. Thus, kindly use the below tag in your weblogic.xml descriptor.

<prefer-web-inf-classes>false</prefer-web-inf-classes>

Some years ago I was struggling with class loading issues because I was missing it. Below you have an example about this extracted from this blog.

enter image description here

If after applying this you still are facing issues with the class loader, you should install Classloader Analysis Tool (CAT) to get the class loader, which is loading the conflicting classes. In this blog you will have some instructions about how to use CAT.

Importantly, in this document Oracle states about this

Note that in order to use prefer-application-packages or prefer-application-resources, prefer-web-inf-classes must be set to false.

Adara answered 13/8, 2020 at 5:50 Comment(2)
Thanks for the info, i was going on the same path as you are suggesting, but i have found out that this was not easy, a lot of other exceptions were thrown when we deploy the war on web logic and try to use the jar files in the war fileFlavin
If you want paste the stack trace.Adara
F
1

This issue was solved by updating the package-info.java

@javax.xml.bind.annotation.XmlSchema(namespace = "urn:test1",
    xmlns = {@XmlNs(prefix = "",
         namespaceURI = "http://www.test.com")},
    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)

This is the part of the package-info that was not been there before

xmlns = {@XmlNs(prefix = "", namespaceURI = "http://www.test.com")}

adding the namespace trick JavaXB to add the original namespace

Flavin answered 4/9, 2020 at 8:26 Comment(0)
F
0

Please check the mentioned page, which has a different Filtering classloading:

   <wls:prefer-application-packages>
        <wls:package-name>com.ctc.wstx.*</wls:package-name>
        <wls:package-name>javax.wsdl.*</wls:package-name>
        <wls:package-name>org.apache.cxf.*</wls:package-name>
        <!-- <wls:package-name>javax.jws.*</wls:package-name> -->
    </wls:prefer-application-packages>
Fluoroscope answered 12/8, 2020 at 21:11 Comment(2)
the list of prefer packaged defined under weblogic.xml in a war file like this does not do anything, i think i'm missing some packaged but the question is what packagesFlavin
this impacts at running time, not building time, therefore your war file would change any embedded jar files at all.Fluoroscope
C
0

My finding was that namespaces behave correctly or don't depending on which jaxb context is used for mashaller (com.sun.xml.bind.jaxb-impl.jar or eclipselink.jar by default) no amount of overriding WebLogic preferred packages to the com.sun.xml side of things from the application had the desired effect, only when using eclipselink.jar marshaller was producing namespaces correctly if debugging, this is the place to look at,

    BareOutInterceptor->AbstractOutDatabindingInterceptor->DataWriterImpl->JAXBEncoderDecoder
            writeObject(marshaller, source, newJAXBElement(elName, cls, elValue))
// marshaller.getClass().getProtectionDomain().getCodeSource() useful methods

to set the jaxb context to the desired one, Oracle proposes system properties to set the context https://docs.oracle.com/cd/E24329_01/web.1211/e24964/data_types.htm#WSGET348 which is not great as it affects everything then potentially breaking other functionalities

the more subtle override (found here http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html) is to create a jaxb.properties file and place it in WEB-INF/classes in the same folder structure as the package name of the generated classes

Clobber answered 29/3, 2023 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.