java-8cxfmaven-shade-pluginuberjarjava-21

How to prevent Java21 to forcibly add 'ns2' to namespace?


I have a Java application doing SOAP requests to a WebService (which I have no control of). It is currently running on Java8 and I need to make it compatible for both, Java8 and Java21 (not only Java21).

Otherwise I have been able to make the app compatible on both, but I am facing this weird problem where this SOAP request seems to be invalid and with JRE21. For now, I think the reason is that 'ns2' is forcibly added to the soap requests:

Also: When I run this in Eclipse with JRE21, it works but when I make JAR package, then it won't.

I have tried these solutions (most common suggestions for this type of problem): (eg. these)

But no luck... Any suggestions where to go next and what to try? Is this just something that comes as a gift with javax -> jakarta stuff and it is not possible to support both jre 8/21?

Here is some debug log from working scenario (with jre8):

INFO: Outbound Message
---------------------------
ID: 1
Address:  https://foo.bar.com/wsapp/atp
Encoding: UTF-8
Http-Method: POST
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:ea54dfe5-04ca-4460-9ff4-ad610267c77d"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Headers: {Accept=[*/*], Connection=[Keep-Alive], SOAPAction=["SendAction"]}
Payload: 
--uuid:ea54dfe5-04ca-4460-9ff4-ad610267c77d
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><DDataSendReq xmlns="http://www.cust.com/xmlschema/AT"><Language>en</Language><ReportingMaterial><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:0191e9ad-1a47-4fe6-aa1f-e6ddc53d6018-1@www.cust.com"/></ReportingMaterial></DDataSendReq></soap:Body></soap:Envelope>
--uuid:ea54dfe5-04ca-4460-9ff4-ad610267c77d
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <0191e9ad-1a47-4fe6-aa1f-e6ddc53d6018-1@www.cust.com>
Content-Disposition: attachment;name="VENU.txt"

VENU    231278........

--uuid:ea54dfe5-04ca-4460-9ff4-ad610267c77d--



INFO: Inbound Message
----------------------------
ID: 1
Response-Code: 200
Encoding: ISO-8859-1
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:d2089dd1-82a3-4ec2-86ed-b4a61864b116"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Headers: {connection=[keep-alive], content-type=[multipart/related; type="application/xop+xml"; boundary="uuid:d2089dd1-82a3-4ec2-86ed-b4a61864b116"; start="<root.message@cxf.apache.org>"; start-info="text/xml"], ........}
Payload: 
--uuid:d2089dd1-82a3-4ec2-86ed-b4a61864b116
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><DDataSendResp xmlns="http://www.cust.com/xmlschema/AT"><Result><Filing>VENU.txt</Filing><Accepted>true</Accepted><Timestamp>2025-03-04T16:13:19.560+02:00</Timestamp></Result><CheckupResult><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:8d00cc51-8583-4805-9ff8-1b1339021c7c-316@www.cust.com"/></CheckupResult></DDataSendResp></soap:Body></soap:Envelope>
--uuid:d2089dd1-82a3-4ec2-86ed-b4a61864b116
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <8d00cc51-8583-4805-9ff8-1b1339021c7c-316@www.cust.com>
Content-Disposition: attachment;name="7015949_Result_8005669487209363021.xml"

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?><TMResult xmlns="http://www.cust.com/xmlschema/TMR"><CheckupResult filing="VENU.txt" reports="2" correct="2" errors="0">Ok</CheckupResult></TMResult>
--uuid:d2089dd1-82a3-4ec2-86ed-b4a61864b116--
--------------------------------------

Here is some debug log from non-working scenario (with jre21):

INFO: Outbound Message
---------------------------
ID: 1
Address: https://foo.bar.com/wsapp/atp
Encoding: UTF-8
Http-Method: POST
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:9c5f8d34-c322-4517-a9d1-7e5be0144211"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Headers: {Accept=[*/*], Connection=[Keep-Alive], SOAPAction=["SendAction"]}
Payload: 
--uuid:9c5f8d34-c322-4517-a9d1-7e5be0144211
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:DDataSendReq xmlns:ns2="http://www.cust.com/xmlschema/AT"><Language>en</Language><ReportingMaterial><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:41398cb7-2fc8-4433-9129-62f3e5cf0de8-1@cxf.apache.org"/></ReportingMaterial></ns2:DDataSendReq></soap:Body></soap:Envelope>
--uuid:9c5f8d34-c322-4517-a9d1-7e5be0144211
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <41398cb7-2fc8-4433-9129-62f3e5cf0de8-1@cxf.apache.org>
Content-Disposition: attachment;name="VENU.txt"

VENU    231278........

--uuid:9c5f8d34-c322-4517-a9d1-7e5be0144211--



INFO: Inbound Message
----------------------------
ID: 1
Response-Code: 500
Encoding: ISO-8859-1
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:47ab21a0-b580-4c36-92ad-f0f24f8e13ba"; start="<root.message@cxf.apache.org>"; start-info="text/xml"
Headers: {connection=[close], content-type=[multipart/related; type="application/xop+xml"; boundary="uuid:47ab21a0-b580-4c36-92ad-f0f24f8e13ba"; start="<root.message@cxf.apache.org>"; start-info="text/xml"], ........}
Payload: 
--uuid:47ab21a0-b580-4c36-92ad-f0f24f8e13ba
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Client</faultcode><faultstring>Unmarshalling Error: unexpected text "VkVST05VTU.......gDQo=" </faultstring></soap:Fault></soap:Body></soap:Envelope>
--uuid:47ab21a0-b580-4c36-92ad-f0f24f8e13ba--
--------------------------------------

EDIT: Starting to think that this might have something to do with how the app is built and run with JRE9+ that the package-info.java has no effect at all what so ever -> will try to investigate this idea more. Or maybe this is just javax/jakarta mess that might not be resolvable to work on both JRE.

EDIT2: Getting clueless... Just spent few weeks to update Hibernate from 4 -> 6 as there were some dependencies and I thought that it would cause some javax-dependencies to exist there. No more javax but still the same issue.. I'm clueless now.

EDIT3: Problem figured !! After this I accidentally came across some problem someone had with CXF and fat-JAR -type config where the CXF's META-INF content is not handled correctly. There the occuring problem was a bit different but I gave it a shot and voilá!!! Suddenly started working after I converted my JAR with maven-shade-plugin into different kind of monolitchic JAR. I don't have a final solution yet, but seems at least 95% to be the reason behind this. I will post an answer for this issue when this is all done.

This quite sums the problem and solution: https://coderanch.com/t/744751/java/SOAP-WS-client-fails-command (I will try to sum the solution here as well when I have appropriate moment)


Solution

  • Answering my own question...

    The problem was 'fat JAR' or 'uber JAR' used in combination with CXF libraries. I had dependent libraries included in 'lib' folder and used custom class loader (com.jdotsoft.jarloader.JarClassLoader). Unfortunately for some reason I did not mention of using 'fat JAR' approach in my OP.

    For the actual answer I'm going to quote "Rob Spoor" from Coderanch site (here):

    The problem is that some frameworks use a plugable system that allows separate JAR files to each provide implementations. These all use a file with the exact same path. In this case the file is META-INF/cxf/bus-extensions.txt. For a fat JAR to work, the contents of all these files need to combined into one file. What instead happens is that one file wins, and the contents of all others are discarded.

    Solution is to merge/append those files / or some of those / or at least one (META-INF/cxf/bus-extensions.txt).

    I think this could be done in various ways but ended up using Apache Shade, which actually had solution for just the case here.

    I would be still curious on how this could be done with the JDotSoft JarClassLoader but didn't have the time to orient to this task.

    In the end, here is how I did my Maven configuration that has lots of dependencies (did some cleaning for unnecessary files, not relevant to answer but still left those here):

                <plugin>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.6.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <filters>
                                    <filter>
                                        <artifact>*:*</artifact>
                                        <excludeDefaults>false</excludeDefaults>
                                        <includes>
                                            <include>META-INF/MANIFEST.MF</include>
                                        </includes>
                                        <excludes>
                                            <exclude>META-INF/**/**.SF</exclude>
                                            <exclude>META-INF/**/**.DSA</exclude>
                                            <exclude>META-INF/**/**.RSA</exclude>
                                            <exclude>META-INF/**/**README**</exclude>
                                            <exclude>META-INF/**/**LICENSE**</exclude>
                                            <exclude>META-INF/**/**HISTORY**</exclude>
                                            <exclude>META-INF/**/**FAQ**</exclude>
                                            <exclude>META-INF/*</exclude>
                                            <exclude>*</exclude>
                                        </excludes>
                                    </filter>
                                </filters>
                                <createDependencyReducedPom>false</createDependencyReducedPom>
                                <transformers>
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <mainClass>my.own.mainclass</mainClass>
                                    </transformer>
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                        <resource>META-INF/cxf/bus-extensions.txt</resource>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>