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 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.

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);