Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Exposing and Consuming SOAP Web Service Using Apache Camel-CXF Component and Spring

DZone's Guide to

Exposing and Consuming SOAP Web Service Using Apache Camel-CXF Component and Spring

· Integration Zone ·
Free Resource

Learn more about how to Prevent Slow or Broken APIs From Affecting Your Bottom Line.

Let’s take the customer endpoint in my earlier article. Here I am going to use Apache Camel-CXF component to expose this customer endpoint as a web service.

@WebService(serviceName="customerService")
public interface CustomerService 
{
	public Customer getCustomerById(String customerId);

}

public class CustomerEndpoint implements CustomerService
{
	private CustomerEndPointService service;

	@Override
	public Customer getCustomerById(String customerId)
	{
		Customer customer= service.getCustomerById(customerId);
		return customer;
	}

	
}

Exposing the service using Camel-CXF component

<cxf:cxfEndpoint id="customerEndpoint" address="http://localhost:9000/CRMApplication/customer"
            wsdlURL="http://localhost:9000/CRMApplication/customer?wsdl"
            serviceClass="com.sample.services.customers.CustomerService"
            endpointName="ws:CustomerServicePort"
            serviceName="ws:CustomerService"
        xmlns:ws="http://com.sample.customer.endpoint" />

Remember to specify the schema Location and namespace in spring context file

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        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/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

Consuming SOAP web service using Camel-CXF

Say you have a SOAP web service to the address http://localhost:8181/OrderManagement/order

Then you can invoke this web service from a camel route. Please the code snippet below.

	<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
       <route>
         <from uri="cxf:customerEndpoint" />
         <to uri="http://localhost:8181/OrderManagement/order" />
       </route>
    </camelContext>

In a camel-cxf component you can also specify the data format for an endpoint like given below.

<cxf:cxfEndpoint id="customerEndpoint" address="http://localhost:9000/CRMApplication/customer"
            wsdlURL="http://localhost:9000/CRMApplication/customer?wsdl"
            serviceClass="com.sample.services.customers.CustomerService"
            endpointName="ws:CustomerServicePort"
            serviceName="ws:CustomerService"
        xmlns:ws="http://com.sample.customer.endpoint">
		<cxf:properties>
			<entry key="dataFormat" value="MESSAGE"/>
		</cxf:properties>
	</cxf:cxfEndpoint>

Hope this will help you to create SOAP web service using Camel-CXF component.

Learn about the Five Steps to API Monitoring Success with Runscope

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}