This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Spring WS Example
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Spring Web Services Example

Available as of Camel 2.6

This example shows how to expose a SOAP-based web service using Camel and Spring Web Services.

Running the example

The example is included in the distribution at examples/camel-example-spring-ws. To start the example use Maven:

mvn clean install jetty:run

This will expose a web service on http://localhost:8080/increment. With the help of a tool such as Soap-UI it's easy to sent messages to this endpoint. There's a ready to use SOAP-UI project available at examples/camel-example-spring-ws/client.

Code walk through

The Camel route exposing the above web service is defined as:

JaxbDataFormat jaxb = new JaxbDataFormat(false);

.process(new IncrementProcessor())

Taking a closer look at the URI reveals that this route consumes messages with a certain rootqname. In this case it listens for messages with root element incrementRequest defined in the namespace. These XML messages are unmarshalled to objects using Camel's Data Format support (JAXB in this case). After processing the resulting object is marshalled back to XML and returned to the client as a response.

Further notice that the URI contains a reference to an endpointMapping in the Registry. Since we're using Spring the registry is a Spring ApplicationContext defined in spring-ws-servlet.xml. This file contains the following bean:

<bean id="endpointMapping" class="">
	<property name="interceptors">
			<ref local="validatingInterceptor" />
			<ref local="loggingInterceptor" />

The endpointMapping bean is a Spring-WS endpoint mapping that maps incoming messages to appropriate Camel routes. You'll only need to define a single CamelEndpointMapping, regardless of the number of Camel routes using Spring-WS endpoints.

The above endpointMapping bean is automatically picked up by the MessageDispatcherServlet declared in web.xml:

Since the servlet is named {{spring-ws}} it will look for a file named {{/WEB-INF/spring-ws-servlet.xml}}.
  • No labels