What's the Camel Transport for CXF
You can use the camel-cxf component to communicate the CXF endpoints in Camel Context, in this way we just treat CXF as a service framework library in Camel. But if you want to leverage the Camel routing and mediation engine in CXF , the best way is to treat Camel as an EIP library and put it into CXF transport layer. The Camel transport for CXF is this kind of component which implements the CXF transport API with Camel core library.
CXF architecture in one minute
CXF is a service framework which supports lots of transports and bindings and you can easily develop and publish the service as you want. Here are two layers in the CXF runtime, one is generic messaging layer comprised of Messages, Interceptors, and InterceptorChains, the other is transport layer which hides transport specific details from the messaging layer. This two layer are build up with the service model which holds the WS* meta data. The transport layer with feed the incoming message to the message layer and consume the outgoing message from the message layer.
You can find the more information for the CXF architecture document herehttp://cwiki.apache.org/CXF20DOC/cxf-architecture.html.
Integrate Camel's into CXF transport layer
Camel transport for CXF implements the CXF transport API, you could treat it as a normal transport implementation. But you need to initiate a camel context for the camel transport and do the routing and mediation work as you want in the CXF transport layer than pass the message to CXF Messaging layer for the WS* message handling.
Here we connect a camel consumer with the Camel conduit and a camel producer with the Camel Destination by using the endpoint URL in a certain Camel context.
Configure the Camel context
Basically , Camel transport factory is in charge of Camel transport, and CXF core will load this factory when you put the camel-cxf.jar into the class path. Since you need to pass the camel context into the transport layer , you could do it in a programmatic way or with the spring configuration.
Setting the Camel context in a programmatic way
Camel transport provides a setConetxt method that you could use to set the Camel context into the transport factory. If you want this factory take effect, you need to register the factory into the CXF bus. Here is a full example for you.
import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; import org.apache.cxf.transport.ConduitInitiatorManager; import org.apache.cxf.transport.DestinationFactoryManager; ... BusFactory bf = BusFactory.newInstance(); //setup the camel transport for the bus Bus bus = bf.createBus(); CamelTransportFactory camelTransportFactory = new CamelTransportFactory(); //set the context here to the transport factory; camelTransportFactory.setCamelContext(context) // register the conduit initiator ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class); cim.registerConduitInitiator(CamelTransportFactory.TRANSPORT_ID, camelTransportFactory); // register the destination factory DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class); dfm.registerDestinationFactory(CamelTransportFactory.TRANSPORT_ID, camelTransportFactory); // set the default bus for BusFactory.setDefaultBus(bus);
Setting the Camel context with the spring configuration
Since Camel and CXF both support the spring configuration, you can easily set up the Camel context in the Camel transport for CXF. If you do not familiar with the CXF transport configuration, please ref to http://cwiki.apache.org/CXF20DOC/server-http-transport.html and http://cwiki.apache.org/CXF20DOC/client-http-transport-including-ssl-support.html for more information.
This example show how to use the camel load balance feature in CXF, and you need load the configuration file in CXF and publish the endpoints on the address "camel://direct:EndpointA" and "camel://direct:EndpointB"
If you just want to set the conduit's Camel context, you can take the below configuration file as an example