Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: text cleanup

CXF Example

CXF example for routing

...

messages with different

...

transports

The Camel CXF example is a demo of the camel-cxf component to show how to route the message messages between to CXF endpoints, with one endpoint consumes the consuming a SOAP over JMS request , while the other endpoint provides the providing a SOAP over http HTTP request for the actual CXF Service endpoint. This camel The 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 From the source or binary distribution the following should work

...

Wiki Markup
{snippet:id=e1|lang=java|url=activemq/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/CamelCxfExample.java}

There Here is code for starting the JMS broker and the CXF server:

Wiki Markup
{snippet:id=e2|lang=java|url=activemq/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/CamelCxfExample.java}

Now we setup the router for the two endpoint URI URIs 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.

...

Since Camel has lots of components and is a great mediation rule engine, we can leverage these camel feature Camel features in CXF by using the camel 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 Camel destination.

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}

When CXF load loads this configuration, it will publish the CXF endpoint to the Camel endpoint that is found in the camel Camel context.

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

Here is the The code that below shows how to publish the endpoint to different Camel context endpoints, you . You can specify the Camel endpoint uri URI as the endpoint address parameter.

...

CXF example for using the WebServiceProvider API

JAXWS API JAX-WS provides the WebServiceProvider API to meet the requirement requirements of XML lever -level message handling. This example is to show shows how to route an a SOAP Message from a WebServiceProvider implementor implementation to bean endpoint in the Camel context. Basically, we still pass the WebServiceProvider implementor as SEI, and the CxfConsumer will pass the SOAP Message in a list of parameters to camel the Camel router for further processing.

First, let's have a look at the Camel context's configuration. Here we start a CxfConsumer to listen to the address and pass soap message SOAP messages to the test bean.

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

Here Below is the WebServiceProvider implementor's annotation. In this code, we just want to handle SOAPMessage SOAPMessages in the Message mode:

Wiki Markup
{snippet:id=e1|lang=java|url=activemq/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/provider/GreeterProvider.java}

Since the cxfCXF-camel Camel component will replace the cxf CXF invoker to call the processor when start starting a cxf CXF endpoint, the cxfCXF-camel 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:

Wiki Markup
{snippet:id=e1|lang=java|url=activemq/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/provider/TesterBean.java}