Search Tutorials

Apache Camel + Apache CXF SOAP Webservices Hello World Example | JavaInUse

Apache Camel CXF WebService using Spring DSL Hello World Example

In this post we will implement a simple Apache Camel CXF webservice and deploy it on JBoss Fuse.

Apache Camel - Table of Contents

File Transfer Using Java DSL Apache Camel Apache Camel Java DSL + Spring Integration Hello World Example Apache Camel Exception Handling Using Simple Example Apache Camel Redelivery policy using example Integrate Apache Camel and ActiveMQ EIP patterns using Apache Camel Apache Camel Tutorial- Integrate Spring Boot+ Apache Camel Apache Camel Tutorial- Integrate with MySQL DB using SQL query Apache Camel EIP - Splitter and Aggregator pattern Apache Camel Unit Testing Apache Camel + Spring + Quartz Hello World Example Camel application deployment on JBoss Fuse Apache Camel + Apache CXF SOAP Webservices Apache Camel + JAX-RS REST Webservice Apache Camel + CXFRS REST Webservice Apache Camel Routing Slip EIP Pattern Apache Camel Load Balancer EIP Pattern Apache Camel Interceptors Apache Camel + Kafka Hello World Example Apache Camel - Marshalling/Unmarshalling XML/JSON Data Example Calling and Consuming Webservices using Apache Camel Apache Camel Tutorial - Send SMTP Email Using Gmail Apache Camel Tutorial - SEDA component Hello World Example


This tutorial is explained in the below Youtube Video.

Lets Begin

Create the maven project as follows-

The classes in package com.javainuse are generated classes from wsdl.
The pom.xml will be as follows-
<project xmlns="" xmlns:xsi=""










Next we define a "contract-first" webservice using WSDL. In the contract-first web service, the "contract" i.e a WSDL definition of operations and endpoints and XML schema of the messages is created first, without actually writing any service code.
Next we define the wsdl file that takes a String as an input and returns another string as output.
The WSDL is defined as follows-
<?xml version="1.0" encoding="ISO-8859-1"?>

<wsdl:definitions xmlns:soap=""
	xmlns:tns="" xmlns:xs=""
	xmlns:http="" xmlns:wsdl=""

		<xs:schema targetNamespace="">
			<xs:element name="inputSOATest">
						<xs:element type="xs:string" name="test" />
			<xs:element name="outputSOATest">
						<xs:element type="xs:string" name="result" />

<!--Define input and output parameters -->
	<wsdl:message name="inputSOATest">
		<wsdl:part name="in" element="tns:inputSOATest" />
	<wsdl:message name="outputSOATest">
		<wsdl:part name="out" element="tns:outputSOATest" />

<!--Define port definition -->
	<wsdl:portType name="SOATestEndpoint">
		<wsdl:operation name="SOATest">
			<wsdl:input message="tns:inputSOATest" />
			<wsdl:output message="tns:outputSOATest" />

<!--Bind Soap operation and service -->
	<wsdl:binding name="SOATestBinding" type="tns:SOATestEndpoint">
		<soap:binding transport="" />
		<wsdl:operation name="SOATest">
			<soap:operation soapAction=""
				style="document" />
				<soap:body parts="in" use="literal" />
				<soap:body parts="out" use="literal" />

<!--Define service -->
	<wsdl:service name="SOATestEndpointService">
		<wsdl:port name="SOATestEndpoint" binding="tns:SOATestBinding">
			<soap:address location="http://localhost:8181/cxf/javainuse/learn" />

Next we define a cxfEndpoint and configure a route to expose webservice.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
	xmlns:xsi="" xmlns:camel=""
	xmlns:osgi="" xmlns:cxf=""

	//define a cxfEndpoint for the wsdl
	<cxf:cxfEndpoint id="CXFTest" address="/javainuse/learn"
		endpointName="a:SOATestEndpoint" serviceName="a:SOATestEndpointService"
		wsdlURL="META-INF/wsdl/test.wsdl" serviceClass="com.javainuse.SOATestEndpoint"
		xmlns:a="" />

	<bean id="processor" class="com.javainuse.beans.CamelProcessor" />
	//camel route for processing the input
	<camelContext id="camelId" xmlns="">

		<camel:route id="bookTicket">
			<camel:from uri="cxf:bean:CXFTest" />
			<process ref="processor" />


package com.javainuse.beans;

import java.util.List;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import com.javainuse.InputSOATest;
import com.javainuse.OutputSOATest;

public class CamelProcessor implements Processor {

    public void process(Exchange exchange) throws Exception {
        OutputSOATest out = new OutputSOATest();
        //Get input from exchange
        List soaList = exchange.getIn().getBody(List.class);
        InputSOATest inputSOATest = (InputSOATest) soaList.get(0);
        out.setResult("Welcome " + inputSOATest.getTest().toString());
        //set output in exchange


Start JBoss Fuse and type the command-
install mvn:com.javainuse/soapexample/0.0.1-SNAPSHOT
start 251
Use list command to check if the bundle is started correctly

Next go to url localhost:8181/cxf

Click on the wsdl hyperlink.


Download Source Code

Download it - Apache Camel +CXF SOAP Webservice Hello World

See Also

Spring Boot Hello World Application- Create simple controller and jsp view using Maven Spring Boot Tutorial-Spring Data JPA Spring Boot + Simple Security Configuration Pagination using Spring Boot Simple Example Spring Boot + ActiveMQ Hello world Example Spring Boot + Swagger Example Hello World Example Spring Boot + Swagger- Understanding the various Swagger Annotations Spring Boot Main Menu Spring Boot Interview Questions