I am trying to understand how to integrate Apache Camel with any web service that provides a WSDL to generate its classes to afterward call his methods to return some reques
One of my main responsibilities is to consume different web services using camel as a client. This is the approach I generally use, never ran into any problems it works like a charm everytime.
1) Define the endpoint in your camel-config.xml file:
< bean id="service_name_CXFEndpoint" class="org.apache.camel.component.cxf.CxfEndpoint" />
2) Use the Endpoint Defined in the config file in the route for web service consumption:
private String CXF_SERVICE_ENDPOINT = "cxf:bean:service_name_CXFEndpoint?address=wsdl_uri_location&serviceClass=service_name_from_the_stubs&loggingFeatureEnabled=true";
For the service name, you need to copy the contents of the wsdl, paste it in a .wsdl file and generate webservice client. To do this, you need to right click on the wsdl file>webservices>Generate Client. Then you need to select JbossWS for the runtime( You have to set it up first in the preferences). Once the stubs, have been generated, look for the main service class. Then copy its entire location.(for example, for a class called WebServiceClass located in com.test would be serviceClass=com.test.WebService.class)
3) Define the routing for consumption:
from("direct:web_service")
.routeId("service_name")
.bean(ServiceWSProcessor,"processRequest")
.to(CXF_SERVICE_ENDPOINT)
.bean(ServiceWSProcessor,"processResponse")
.end();
Now, you send a request to this processor, which will go to the web service endpoint and give you a response.
4) Write a processor for the request response(in this case serviceWS processor).
@Component(value="serviceWSProcessor")
public class ServiceWSProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceWSProcessor.class);
public void processRequest(Exchange exchange) throws Exception {
Message in = exchange.getIn();
Message out = exchange.getOut();
try {
LOGGER.info("Service - START");
Request Request = in.getBody(Request.class);
//This depends on your WSDL File. Test the process in SOAP UI and see how the request looks like and code
//accordingly.
List
For the list of dependencies required for camel and spring-ws, check out this page.
https://github.com/gauthamhs/Java/blob/master/JavaEE/Dependencies-Important-Camel-Spring.xml
Let me know if you need additional help or if you have any concerns.
Regards, Gautham