...
Examples
Webservice client
The following route supports marshalling the request and unmarshalling a response or fault.
Code Block |
---|
SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
from("direct:customerServiceClient")
.onException(Exception.class)
.handled(true)
.unmarshal(soapDF)
.end()
.marshal(soapDF)
.to("http://myserver/customerservice")
.unmarshal(soapDF);
|
The below snippet creates a proxy for the service interface and makes a SOAP call to the above routeThis snippet shows how to create a proxy for a service interface that sends requests to a direct endpoint and receives the response.
Code Block |
---|
import org.apache.camel.Endpoint;
import org.apache.camel.component.bean.ProxyHelper;
...
Endpoint startEndpoint = context.getEndpoint("direct:customerServiceClient");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
// CustomerService below is the service endpoint interface, *not* the javax.xml.ws.Service subclass
CustomerService proxy = ProxyHelper.createProxy(startEndpoint, classLoader, CustomerService.class);
GetCustomersByNameResponse response = proxy.getCustomersByName(new GetCustomersByName());
|
This route supports marshalling the request and unmarshalling response or fault.
Code Block |
---|
SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class)); from("direct:customerServiceClient") .onException(Exception.class) .handled(true) .unmarshal(soapDF) .end() .marshal(soapDF) .to("http://myserver/customerservice") .unmarshal(soapDF); |
Webservice Server
Using the following route sets up a webservice server that listens on jms queue customerServiceQueue and processes requests using the class CustomerServiceImpl. The customerServiceImpl of course should implement the interface CustomerService. Instead of directly instantiating the server class it could be defined in a spring context as a regular bean.
...