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

Share, secure, distribute, control, and monetize your APIs with the platform built with performance, time-to-value, and growth in mind. Free 90-day trial of 3Scale by Red Hat

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.

Explore the core elements of owning an API strategy and best practices for effective API programs. Download the API Owner's Manual, brought to you by 3Scale by Red Hat

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}