CXF Proxy Example
Available as of Camel 2.5
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 Maven then you can easily run it from the command line using:
Code Block |
---|
mvn jettycamel:run |
About
This example demonstrates how you CXF can use CXF be used to proxy a real web service. For this example in this case we want Camel to validate and enrich the input message before its send it's sent to the real actual web service. We do this to ensure the data is correct and that to have Camel automatically add in any missing information is added automatic by Camel. In real life you may want to do this in case a client send wish to use a proxy in cases where clients are sending bad/faulty data to a web service, and its it's costly/not possible to update and fix that client. Instead lets fix it by a proxy with Camel.those clients.
Tip | ||
---|---|---|
| ||
If you want a pure http 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. You may want to do this if you want This is for cases where you need a simple straight thru through proxy where the message should not be altered by Camel. |
Implementation
Since For this is a simple example it provides both the Camel application and the real web service are in the same JVM. In your use-case production work the real webs ervice will web service may often be hosted on another server, etc.
Spring XML
In the Spring XML file we have define defined the CXF proxy endpoint using the <cxf:cxfEndpoint>
tag.
And the 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 enrich bean EnrichBean which validates and add 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 use used as a reply for the proxied web service as well.
...
You start the example from the command line using the maven Maven goal mvn jettycamel:run
. There is also a build.xml
file for ANT users.
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
.The console should then output progress.
After making a SOAP request, check the console to see the SOAP request and response:
Sample output
Here is some a sample output from the console:
Code Block |
---|
2010-09-26 12:20:46,974 [main ] INFO DefaultCamelContext - Apache Camel 2.5-SNAPSHOT (CamelContext: camel-1) started in 0.858 seconds 2010-09-26 12:20:55,685 [tp-1790017034-1] INFO input - Exchange[ExchangePattern:InOut, BodyType:null, Body: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rep="http://reportincident.example.camel.apache.org"> <soapenv:Header/> <soapenv:Body> <rep:inputReportIncident> <incidentId><<incidentId>63</incidentId> <incidentDate>2010-09-26</incidentDate> <givenName>Ibsen<<givenName>Claus</givenName> <familyName>Claus<<familyName>Ibsen</familyName> <summary>Bla bla</summary> <details>More bla</details> <email>davsclaus@apache.org</email> <phone>12345678</phone> </rep:inputReportIncident> </soapenv:Body> </soapenv:Envelope>] Incident was 63, changed to 456 Invoked real web service: id=456 by Claus Ibsen Claus 2010-09-26 12:20:55,997 [tp-1790017034-1] INFO output - Exchange[ExchangePattern:InOut, BodyType:org.apache.camel.converter.stream.CachedOutputStream.WrappedInputStream, Body: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns2:outputReportIncident xmlns:ns2="http://reportincident.example.camel.apache.org"> <code>OK;456</code> </ns2:outputReportIncident> </soap:Body> </soap:Envelope>] |
...