Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Complete rewrite to make it clearer what the Camel Transport does and how to set it up.. hope that is ok

What's the Camel Transport for CXF

In CXF you offer a webservice by defining it´s address. The first part of the address specifies the protocol to use. For example address="http://localhost:90000" in an endpoint config means your service will be offered using the http protocol on port 9000 of localhost. When you integrate Camel Tranport into CXF you get a new transport "camel". So you can specifiy address="camel://direct:MyEndpointName" to offer your CXF service as a camel direct endpoint.

Technically speaking Camel transport for CXF is a 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 the 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.

This allows you to use camel´s routing engine and integration patterns support smoothly together with your CXF services.

Integrate Camel

...

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.

To include the Camel Tranport into your CXF bus you use the CamelTransportFactory. You can do this in Java as well as in Spring.

Setting up the Camel Transport in Spring

Code Block
xml
xml

<bean class="org.apache.camel.component.cxf.transport.CamelTransportFactory">
  <property name="bus" ref="cxf" />
  <property name="camelContext" ref="camelContext" />
  <property name="transportIds">
    <list>
      <value>http://cxf.apache.org/transports/camel</value>
    </list>
  </property>
</bean>

Integrating the Camel Transport

...

in a programmatic way

Camel transport provides a setConetxt setContext 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 or bus as the default bus for cxf
BusFactory.setDefaultBus(bus);

Setting the Camel context with the spring configuration

...

Using Camel as a load balancer for CXF

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

...

Complete Howto and Example for attaching Camel to CXF

Better JMS Transport for CXF Webservice using Apache Camel 

...