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

Migrating from On-Prem to Cloud Middleware? Here’s what Aberdeen Group says leading companies should be considering. Brought to you in partnershp with Liaison Technologies

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.

Is iPaaS solving the right problems? Not knowing the fundamental difference between iPaaS and iPaaS+ could cost you down the road. Brought to you in partnership with Liaison Technologies.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}