How to migrate wsimport and JAX-WS on Hybris 1905(Java 11)

In Java 11 was removed support of JAX-WS (JSR 224), and related classes like ant WsImport task, which are highly used in hybris installations for third-party SOAP integrations. For example, cybersource integration extension rely on both wsimport (generates cybersource client from wsdl during ant build) and JAX-WS to execute SOAP requests.

First of all must be migrated WsImport task to pass ant build with JDK 11 after that must be resolved JAX-WS reference implementation dependencies to deal with spring context initialization.

WsImport

Ant task implementation can be found in jaxws-tools library, which has implementation for WsImport task. Better to add it as maven dependency in external-dependencies.xml(don’t forget to switch usemaven="true" in extensioninfo.xml):

After that ant wsimport task definition must be changed in buildcallbacks.xml on usage of com.sun.tools.ws.ant.WsImport2 class (it is not a typo, must be WsImport2 with trailing 2).

But this changes would not be enough, because wsimport task will require JAXB (JSR 222) to generate java classes, which was also removed from Java 11. So we need to include them also as libraries. The latest version of jaxb is 3.0.0-M3, but unfortunately it has some compatibility issues and only old 2.3.3 version works as expected.

In case of cybersource extension it was also required to add part of JAX-WS implementation to generate classes with JAXB. Similar to JAXB latest version of JAX-WS has issues, so only 2.3.3 can be used.

P.S. Instead of com.sun.tools.ws.ant.WsImport2 can be used org.apache.axis2.tool.ant.AntCodegenTask provided by axis2. It replicates only basic functionality of WsImport task, which should be enough for most cases, but is not enough for cybersource extension.

JAX-WS

There are various implementations of JAX-WS API like javaee, jakarta, jboss, glassfish etc. The only working solution was achieved with latest axis2 implementation and with old deprecated javaee implementation. Hybris OOTB in core extension has partial replacement from deprecated javaee implementation, it has JAXB and javax.activation, javax.ws.rs etc.

Exists few pitfalls in axis2 implementation:

  • Axis2 implementation supports Usernametoken from WS-Security, in case you need extended trust and security policies rampart must be added and engaged as module into axis2. To automatically engage rampart module add corresponding .mar file into lib folder (it could be download as maven dependency, example could be found below).
  • Axis2 SAAJ implementation differs form JDK 8 implementation. envelope.getHeader().addChildElement(SOAPElement) is not recursively adding children elements of SOAPElement, it means that firstly must be added main parent element to header and only after that child elements must be added to returned element (Example implementation).
  • Axis2 implementation forwards XML marshalling to axiom library, so axiom libs must be present in classpath.

Sample files

Sample external-dependencies.xml with WsImport2 ant task and deprecated javaee JAX-WS, keep in mind that hybris core already contains a bunch of mandatory libs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.hybris.platform</groupId>
    <artifactId>cybersourcepayment</artifactId>
    <version>6.2.0.0-RC12</version>

    <packaging>jar</packaging>

    <dependencies>
        <!-- Ant wsimport task -->
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-tools</artifactId>
            <version>2.3.3</version>
        </dependency>

        <!-- javax implementation bindings -->
        <dependency>
            <groupId>javax.xml.ws</groupId>
            <artifactId>jaxws-api</artifactId>
            <version>2.3.1</version>
        </dependency>

        <dependency>
            <groupId>javax.xml.soap</groupId>
            <artifactId>javax.xml.soap-api</artifactId>
            <version>1.4.0</version>
        </dependency>

        <dependency>
            <groupId>javax.jws</groupId>
            <artifactId>javax.jws-api</artifactId>
            <version>1.1</version>
        </dependency>

        <!-- JAX-WS JavaEE/metro runtime -->
        <dependency>
            <groupId>org.glassfish.metro</groupId>
            <artifactId>webservices-rt</artifactId>
            <version>2.4.4</version>
        </dependency>

    </dependencies>
</project>

Sample external-dependencies.xml with WsImport2 ant task and axis2 replacement for JAX-WS:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.hybris.platform</groupId>
    <artifactId>cybersourcepayment</artifactId>
    <version>6.2.0.0-RC12</version>

    <packaging>jar</packaging>

    <properties>
        <axiom.api.version>1.2.22</axiom.api.version>
        <axis2.api.version>1.7.9</axis2.api.version>
        <jaxb.api.version>2.3.3</jaxb.api.version>
        <jaxws.api.version>2.3.3</jaxws.api.version>
    </properties>

    <dependencies>

        <!-- Ant wsimport task -->
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-tools</artifactId>
            <version>2.3.3</version>
        </dependency>

        <!-- JAXWS api -->
        <dependency>
            <groupId>javax.xml.soap</groupId>
            <artifactId>javax.xml.soap-api</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.ws</groupId>
            <artifactId>jaxws-api</artifactId>
            <version>2.3.1</version>
        </dependency>

        <!-- JAXB API -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>

        <!-- JAXB reference implementation -->
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-core</artifactId>
            <version>2.3.0.1</version>
        </dependency>

        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>${jaxb.api.version}</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-xjc</artifactId>
            <version>${jaxb.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-xjc</artifactId>
            <version>${jaxb.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>codemodel</artifactId>
            <version>${jaxb.api.version}</version>
        </dependency>

        <!-- JAXB activation -->
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>javax.activation-api</artifactId>
            <version>1.2.0</version>
        </dependency>

        <!-- JAXWS for wsimport -->
        <dependency>
            <groupId>com.sun.xml.stream.buffer</groupId>
            <artifactId>streambuffer</artifactId>
            <version>1.5.9</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>policy</artifactId>
            <version>2.7.10</version>
        </dependency>
        <dependency>
            <groupId>org.jvnet.staxex</groupId>
            <artifactId>stax-ex</artifactId>
            <version>1.8.3</version>
        </dependency>

        <!-- axis2 with axiom JAXWS reference implementation -->
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-jws-api</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-jaxws</artifactId>
            <version>${axis2.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-kernel</artifactId>
            <version>${axis2.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-saaj</artifactId>
            <version>${axis2.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-metadata</artifactId>
            <version>${axis2.api.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-api</artifactId>
            <version>${axiom.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-dom</artifactId>
            <version>${axiom.api.version}</version>
        </dependency>

        <dependency>
            <groupId>xml-resolver</groupId>
            <artifactId>xml-resolver</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Cybersource -->
        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-core</artifactId>
            <version>1.5.9</version>
        </dependency>
        <dependency>
            <groupId>ma.glasnost.orika</groupId>
            <artifactId>orika-core</artifactId>
            <version>1.4.5</version>
        </dependency>
        <dependency>
            <groupId>com.netflix.archaius</groupId>
            <artifactId>archaius-core</artifactId>
            <version>0.4.1</version>
        </dependency>
        <dependency>
            <groupId>com.netflix.hystrix</groupId>
            <artifactId>hystrix-servo-metrics-publisher</artifactId>
            <version>1.5.9</version>
        </dependency>
        <!-- Classes from this libs are loaded in runtime during checkout -->
        <dependency>
            <groupId>org.hdrhistogram</groupId>
            <artifactId>HdrHistogram</artifactId>
            <version>2.1.12</version>
        </dependency>

    </dependencies>
</project>

Sample external-dependencies.xml with AntCodegenTask ant task and axis2 replacement for JAX-WS:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.hybris.platform</groupId>
    <artifactId>blogextension</artifactId>
    <version>6.2.0.0-RC12</version>

    <packaging>jar</packaging>

    <properties>
        <axiom.api.version>1.2.22</axiom.api.version>
        <axis2.api.version>1.7.9</axis2.api.version>
        <jaxb.api.version>2.3.3</jaxb.api.version>
        <jaxws.api.version>2.3.3</jaxws.api.version>
    </properties>

    <dependencies>

        <!-- Ant axis2 codegen task (wsimport replacement) -->
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-kernel</artifactId>
            <version>1.7.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-ant-plugin</artifactId>
            <version>1.7.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-codegen</artifactId>
            <version>1.7.9</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.3</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.neethi</groupId>
            <artifactId>neethi</artifactId>
            <version>3.1.1</version>
        </dependency>

        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-api</artifactId>
            <version>1.2.22</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-impl</artifactId>
            <version>1.2.22</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.xmlschema</groupId>
            <artifactId>xmlschema-core</artifactId>
            <version>2.2.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.woden</groupId>
            <artifactId>woden-core</artifactId>
            <version>1.0M10</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-codegen</artifactId>
            <version>1.7.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-kernel</artifactId>
            <version>1.7.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-adb</artifactId>
            <version>1.7.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-adb-codegen</artifactId>
            <version>1.7.9</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>

        <!-- JAXWS api -->
        <dependency>
            <groupId>javax.xml.soap</groupId>
            <artifactId>javax.xml.soap-api</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.ws</groupId>
            <artifactId>jaxws-api</artifactId>
            <version>2.3.1</version>
        </dependency>

        <!-- axis2 with axiom JAXWS reference implementation -->
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-jws-api</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-jaxws</artifactId>
            <version>${axis2.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-saaj</artifactId>
            <version>${axis2.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-metadata</artifactId>
            <version>${axis2.api.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-api</artifactId>
            <version>${axiom.api.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ws.commons.axiom</groupId>
            <artifactId>axiom-dom</artifactId>
            <version>${axiom.api.version}</version>
        </dependency>

        <dependency>
            <groupId>xml-resolver</groupId>
            <artifactId>xml-resolver</artifactId>
            <version>1.2</version>
        </dependency>

    </dependencies>
</project>

Example of AntCodegenTask ant task definition and usage for buildcallbacks.xml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12

<taskdef name="codegen" classname="org.apache.axis2.tool.ant.AntCodegenTask">
    <classpath>
        <pathelement path="${classpath}"/>
        <fileset dir="${ext.lib.path}" includes="*.jar"/>
    </classpath>
</taskdef>

<codegen wsdlfilename="https://ics2wsa.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_${wsVersion}.wsdl"
         output="${ext.lib.path}"
         packageName="cybersource-ws-client"
         generateservicexml="true"/>

Rampart maven dependencies:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!-- rampart dependency -->
<dependency>
    <groupId>org.apache.rampart</groupId>
    <artifactId>rampart-core</artifactId>
    <version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart-policy</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart-trust</artifactId>
<version>1.7.1</version>
</dependency>
        <!-- rampart mar file to automatically engage rampart module in axis2 ServiceClient -->
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart</artifactId>
<version>1.7.1</version>
<type>mar</type>
</dependency>

P.S. Most probably to generate classes from wsdl jaxws-tools would be not enough. You can add glassfish metro implementation to bypass issue with wsimport. Keep in mind that it is not compatible with axis2 implementation.

1
2
3
4
5
6

<dependency>
    <groupId>org.glassfish.metro</groupId>
    <artifactId>webservices-rt</artifactId>
    <version>2.4.3</version>
</dependency>

P.P.S. List of possible exceptions for easier search of article on site

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Caused by: java.lang.ClassNotFoundException: com.sun.tools.xjc.api.ErrorListener
Caused by: java.lang.ClassNotFoundException: com.sun.xml.ws.util.exception.JAXWSExceptionBase
Caused by: java.lang.ClassNotFoundException: jakarta.xml.ws.WebServiceException
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.marshaller.SAX2DOMEx
Caused by: java.lang.ClassNotFoundException: com.sun.istack.tools.DefaultAuthenticator$Receiver
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource
Caused by: java.lang.ClassNotFoundException: com.sun.xml.ws.policy.sourcemodel.wspolicy.NamespaceVersion
Caused by: java.lang.ClassNotFoundException: org.jvnet.staxex.XMLStreamReaderEx
Caused by: java.lang.ClassNotFoundException: javax.wsdl.WSDLException
Caused by: java.lang.ClassNotFoundException: org.apache.axis2.wsdl.util.ConfigPropertyFileLoader
Caused by: java.lang.ClassNotFoundException: org.apache.woden.WSDLException
Caused by: java.lang.ClassNotFoundException: org.apache.axis2.schema.ExtensionUtility


MessageFactory: Unable to create SAAJ meta-factoryProvider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found; nested exception is javax.xml.soap.SOAPException: Unable to create SAAJ meta-factoryProvider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found
comments powered by Disqus