CXF Example
CXF example for routing the message with different transport
The Camel CXF example is a demo of the camel-cxf component to show how to route the message between to CXF endpoints , one endpoint consumes the SOAP over JMS request , the other endpoint provides the SOAP over http request for the actual CXF Service endpoint. This camel router just routs the SOAP over HTTP CXF client request to the SOAP over HTTP CXF service.
To run the example we use the maven exec plugin. For example from the source or binary distribution the following should work
cd examples/camel-example-cxf mvn compile exec:java
We start with creating a CamelContext - which is a container for Components, Routes etc:
There is the JMS broker and CXF server set up code
Now we setup the router for the two endpoint URI which we mentioned before, ROUTER_ENDPOINT_URI is the endpoint for consuming the request of SOAP over HTTP, SERVICE_ENDPOINT_URI is the endpoint for providing the request for the SOAP over JMS service.
Then we start up the camel context and create the CXF client to kick off the request.
CXF example for using Camel transport
Since Camel has lots of components and is a great mediation rule engine , we can leverage these camel feature in CXF by using the camel transport. Here is an example to show how to use the Camel transport in CXF.
In this example, we setup a load balance Camel context in the camel destination.
When CXF load this configuration, it will attach an two CXF Endpoint to two different Camel endpoints.
Here is the code that show how to publish the endpoint to different Camel context endpoints, you can specify the Camel endpoint uri as the endpoint address parameter.
CXF example for using the WebServiceProvider API
JAXWS API provides the WebServiceProvider API to meet the requirement of XML lever message handling. This example is to show how to route an SOAP Message from a WebServiceProvider implementor to bean endpoint in the Camel context. Basically , we still pass the WebServiceProvider implementor as SEI, and the camel-cxf consumer will pass the SOAP Message in a list of parameter to camel router for further processing.
First, let's have a look at the Camel context's configuration. Here we start a camel-cxf consumer to listen to the address and pass soap message to the test bean.
Here is the WebServiceProvider implementor's annotation , we just want to handle SOAPMessage in the Message mode
Since the cxf-camel component will replace the cxf invoker to call the processor when start a cxf endpoint, the cxf-camel consumer will never call the provider implementor's invoke method here.
Now we can implement the bean for handling the invocation of the SOAP message