Exposing and Consuming SOAP Web Service Using Apache Camel-CXF Component and Spring
Join the DZone community and get the full member experience.
Join For FreeLet’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.
Opinions expressed by DZone contributors are their own.
Comments