To invoke a JAX-WS web service running on WildFly from Apache Camel, you can utilize the Camel CXF component, which provides integration with the Apache CXF web service framework. Here’s a step-by-step guide on how to accomplish this.
Defining the JAX-WS Web service
Firstly, we will create the JAX-WS Web Service. This is a simple Web service implementation:
import javax.jws.WebService;
@WebService
public class SimpleWebSevice implements Simple {
@Override
public String hello(String s) {
System.out.println("Called Web service with: " + s);
return "Hello " + s;
}
}
And its interface:
public interface Simple {
public String hello(String s);
}
The Web service is packaged in a Web application named DemoWS.war therefore its WSDL is available as: http://localhost:8080/DemoWS/SimpleWebService?wsdl
Creating the Camel application
Now create a new Camel Maven project as described in this tutorial: Setting up a Camel project with Maven
We can describe the Camel route either as Java DSL or via Spring. Using spring, we will create the file camel-context.xml under src/main/resources/META-INF/spring:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<cxf:cxfEndpoint id="SimpleWebService"
address="http://localhost:8080/DemoWS/SimpleWebService" wsdlURL="http://localhost:8080/DemoWS/SimpleWebService?wsdl"
serviceClass="com.sample.SimpleWebService" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="wsClient">
<from uri="timer:foo?repeatCount=1" />
<setBody>
<simple>Hello World!</simple>
</setBody>
<log message="${body}" />
<to uri="cxf:bean:SimpleWebService?defaultOperationName=hello" />
<to uri="mock:result" />
</route>
</camelContext>
</beans>
In the first part of the configuration file we have declared the cxf: component, which provides integration with Apache CXF for connecting to JAX-WS services hosted in CXF. Then, our route which:
1) Starts with a Timer which is executed once
2) Sets the message body
3) Logs Message
4) Invokes the hello method of SimpleWebService (passing the Message body)
5) Sends the output to the mock component which cab be used by unit tests

Provided that you have included the Camel Maven plugin in the pom.xml:
<?xml version="1.0" encoding="UTF-8"?><plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>2.14.0</version>
</plugin>
Then you can start the route with:
mvn camel:run
Source code for this tutorial: https://github.com/fmarchioni/masterspringboot/tree/master/camel/camel-jaxws
Found the article helpful? if so please follow us on Socials