Camel CXF Web Services – Expose them


Camel Web Services Integration, A very essential and basic need in an any IT landscape where integration is involved. (Of course yes, where camel is also involved)

I will try to write a series of articles on Camel – Web services integration. Assume this to be episode-1.

We can integrate to a web service using many components, Use Camel-CXF – where you can use POJO, PAYLOAD & MESSAGE data formats (They are brilliant). Further there are options to use jetty, http, http4, etc. Or simply use jax-ws libraries with Camel as well. All these can be used to expose a web service endpoint or consume a web service(except http(4) components, they are meant for only consuming an existing http / webservice endpoint – means, they can be defined only in ‘to’ endpoints).

In this article lets talk about how to expose a web service in Camel:

1. Exposing Web Services using Camel-CXF – using MESSAGE data format. (also without creating any java classes)

a) Open your favourite XML editor – Start creating your WSDL. Define your desired operations, message inputs and outputs, schemas, services name and address. (Nowadays tools are very matured, you can create WSDL’s without even seeing the XML snippets)

b) Create a camel project, Easiest is to import any of the existing camel examples project (I prefer camel-example-cxf-tomcat). Don’t worry they are Apache licensed.

c) Copy the WSDL to the classpath

Camel CXF - WSDL location

Camel CXF – WSDL location

d) Define a CXF endpoint in beans-context.xml – This is the endpoint you would like to expose for your clients. Fill in all the details from WSDL.

e) Use the above defined endpoint in your Camel routes ‘From’ endpoint.

f) Do whatever you like in the subsequent ‘To’ endpoints.

g) Deploy the code in your favourite container or run using mvn camel:run

So you are now running your own web service, ready to be consumed by your clients.

Refer this project for more details. But trust me, thats it. No Java classes nor you have to generate them from WSDL’s. No there are no other hidden camel code to expose a web service of your own.

Example – Expose a Web Service :

Also thats the speciality of MESSAGE dataformat, It allows you to see the complete incoming SOAP envelope as a single message. Logically a single payload of string. Its up to you, either take the incoming message with or without soap envelope across your camel context.

Note: Refer this link to understand the use case of this project.

Gnanaguru Sattanathan

Gnanaguru Sattanathan

I am a Integration developer and a open source enthusiast. My areas of interest includes Enterprise messaging & SOA. Twitter: @tallguru

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>