Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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.

Code Block
java
java

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"

Wiki Markup
{snippet:id=example|lang=xml|url=activemq/camel/trunk/examples/camel-example-cxf/src/main/resources/org/apache/camel/example/camel/transport/CamelDestination.xml}

If you just want to set the conduit's Camel context, you can take the below configuration file as an example

Wiki Markup
{snippet:id=example|lang=xml|url=activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/transport/CamelConduit.xml}