I'm modernizing some java code to version 17 using Eclipse, Maven and Apache CXF 3.5.0 to build a soap client that connects to the WSDL address below.
Below is my java version:
daniel@pop-os:~$ java -version
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
Below is my pom.xml:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Java17</groupId>
<artifactId>Java17</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<java.version>17</java.version>
<cxf.version>3.5.1</cxf.version>
</properties>
<build>
<finalName>Java17</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- marshalling error loading wsdl -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>3.0.2</version>
</dependency>
<!-- cxf -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-databinding-jaxb</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
</project>
Below is my java code:
package com.webservices;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
public class ClientExample {
public static void main(String args[]) throws Exception {
try {
String wsdl = "https://www.w3schools.com/xml/tempconvert.asmx?WSDL";
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient(wsdl);
Object[] res = client.invoke("CelsiusToFahrenheit", "35");
System.out.println("Echo response: " + res[0]);
} catch (Exception e) {
e.printStackTrace();
}
}
}
After updating the project using the command "Maven > Update Project" and installing the dependencies, I run the ClientExample.java class and get the following error:
WARNING: Interceptor for {https://www.w3schools.com/xml/}TempConvert#{https://www.w3schools.com/xml/}CelsiusToFahrenheit has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Marshalling Error: javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:267)
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:239)
at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:118)
at org.apache.cxf.wsdl.interceptors.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:528)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:439)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:354)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:312)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:332)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:318)
at com.webservices.ClientExample.main(ClientExample.java:27)
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context
javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:301)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:226)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:110)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:642)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:244)
... 11 more
Caused by: com.sun.istack.SAXException2: javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context
javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:217)
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:232)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:117)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:100)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:302)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:309)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:45)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:464)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:298)
... 15 more
Caused by: javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:603)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:114)
... 21 more
org.apache.cxf.interceptor.Fault: Marshalling Error: javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:267)
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:239)
at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:118)
at org.apache.cxf.wsdl.interceptors.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:528)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:439)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:354)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:312)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:332)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:318)
at com.webservices.ClientExample.main(ClientExample.java:27)
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context
javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:301)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:226)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:110)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:642)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:244)
... 11 more
Caused by: com.sun.istack.SAXException2: javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context
javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:217)
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:232)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:117)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:100)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:302)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:309)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:45)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:464)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:298)
... 15 more
Caused by: javax.xml.bind.JAXBException: https.www_w3schools_com.xml.CelsiusToFahrenheit is not known to this context
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:603)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:114)
... 21 more
How do I get this code to work properly?