CXF Proxy Example

This example is located in the examples/camel-example-cxf-proxy directory of the Camel distribution.
There is a README.txt file with instructions how to run it.

If you use Maven then you can easily run it from the command line using:

About

This example demonstrates how CXF can be used to proxy a real web service. For this example we want Camel to validate and enrich the input message before it's sent to the actual web service. We do this to ensure the data is correct and to have Camel automatically add in any missing information. In real life you may wish to use a proxy in cases where clients are sending bad/faulty data to a web service, and it's costly/not possible to update and fix those clients.

Pure HTTP proxy

Icon

If you want a pure HTTP-based proxy then you can use Jetty or Servlet as the front end in Camel. Then delegate those incoming HTTP requests to the real web service. This is for cases where you need a simple straight through proxy where the message should not be altered by Camel. By using the CXF component you get access to all the web service features Apache CXF provides, whereas Jetty will provide just a pure HTTP proxy.

Implementation

For this simple example both the Camel application and the real web service are in the same JVM. In production work the real web service may often be hosted on another server, etc.

Spring XML

In the Spring XML file we have defined the CXF proxy endpoint using the <cxf:cxfEndpoint> tag. The real web service is the Spring bean with the id realWebService.

As you can see in the Camel route we use a CXF consumer to proxy the web service. Then we route the message to the EnrichBean which validates and adds the missing information. Then we just use the HTTP component to send the web service request to the real web service.
The reply from the real web service is then logged and used as a reply for the proxied web service as well.

Enrich bean

The enrich bean is Java code which in our simple example will just set the incidentId parameter to the fixed value of 456. In your implementation you can of course do a lot more.

Running the example

You start the example from the command line using the Maven goal mvn camel:run.
You can also start the Camel application from your IDE, by running the org.apache.camel.example.cxf.proxy.MyMain main class.

You can then use SoapUI or another web service client and send a request to the http://localhost:9080/camel-example-cxf-proxy/webservices/incident url. The wsdl is located at: http://localhost:9080/camel-example-cxf-proxy/webservices/incident?wsdl.

After making a SOAP request, check the console to see the SOAP request and response:

Sample output

Here is a sample output from the console:

See Also

© 2004-2014 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram