camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Spring Web Services
Date Wed, 02 Mar 2011 21:35:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2036/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Spring+Web+Services">Spring
Web Services</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~muellerc">Christian
Mueller</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Reverted from v. 18<br />
    </div>
        <br/>
                         <h4>Changes (3)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">{warning:title=running
Spring Web Services Component 2.7 in OSGI} <br>Because of issue [SWS-681|https://jira.springsource.org/browse/SWS-681]
in Spring-WS, this component cannot be used in an OSGI environment out of the box. <br>When
the Spring guys fixed this issue, announced for 2.0.1.RELEASE, you have to update the dependent
OSGI bundle org.springframework.ws/spring-ws-core to 2.0.1.RELEASE or newer. <br>{warning}
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{info:title=Dependencies}This
component offers support for Spring-WS 1.5.9 which is compatible with Spring 2.5.x and 3.0.x.
<br>In order to run camel-spring-ws on Spring 2.5.x you need to add the spring-webmvc
module from Spring 2.5.x. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">In
order to run Spring-WS 1.5.9 on Spring 3.0 you need to exclude the OXM module from Spring
3.0 as this module is also included in Spring-WS 1.5.9 (see [this post|http://stackoverflow.com/questions/3313314/can-spring-ws-1-5-be-used-with-spring-3])
<br>{info} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. URI format <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="SpringWebServices-SpringWebServicesComponent"></a>Spring
Web Services Component</h2>
<p><b>Available as of Camel 2.6</b></p>

<p>The <b>spring-ws:</b> component allows you to integrate with <a href="http://static.springsource.org/spring-ws/sites/1.5/"
class="external-link" rel="nofollow">Spring Web Services</a>. It offers both <em>client</em>-side
support, for accessing web services, and <em>server</em>-side support for creating
your own contract-first web services.</p>

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt>
for this component:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
	<span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span
class="code-tag">&lt;/groupId&gt;</span>
	<span class="code-tag">&lt;artifactId&gt;</span>camel-spring-ws<span
class="code-tag">&lt;/artifactId&gt;</span>
	<span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
	<span class="code-tag"><span class="code-comment">&lt;!-- use the same version
as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Dependencies</b><br
/>This component offers support for Spring-WS 1.5.9 which is compatible with Spring 2.5.x
and 3.0.x.<br/>
In order to run camel-spring-ws on Spring 2.5.x you need to add the spring-webmvc module from
Spring 2.5.x.

<p>In order to run Spring-WS 1.5.9 on Spring 3.0 you need to exclude the OXM module
from Spring 3.0 as this module is also included in Spring-WS 1.5.9 (see <a href="http://stackoverflow.com/questions/3313314/can-spring-ws-1-5-be-used-with-spring-3"
class="external-link" rel="nofollow">this post</a>)</p></td></tr></table></div>

<h3><a name="SpringWebServices-URIformat"></a>URI format</h3>

<p>The URI scheme for this component is as follows</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
spring-ws:[mapping-type:]address[?options]
</pre>
</div></div>

<p>To expose a web service <b>mapping-type</b> needs to be set to any of
the following:</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Mapping type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>rootqname</tt> </td>
<td class='confluenceTd'> Offers the option to map web service requests based on the
qualified name of the root element contained in the message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>soapaction</tt> </td>
<td class='confluenceTd'> Used to map web service requests based on the SOAP action
specified in the header of the message. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>uri</tt> </td>
<td class='confluenceTd'> In order to map web service requests that target a specific
URI. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>xpathresult</tt> </td>
<td class='confluenceTd'> Used to map web service requests based on the evaluation of
an XPath <tt>expression</tt> against the incoming message. The result of the evaluation
should match the XPath result specified in the endpoint URI. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>beanname</tt> </td>
<td class='confluenceTd'> Allows you to reference a <tt>org.apache.camel.component.spring.ws.bean.CamelEndpointDispatcher</tt>
in order to integrate with existing (legacy) <a href="http://static.springsource.org/spring-ws/sites/1.5/reference/html/server.html#server-endpoint-mapping"
class="external-link" rel="nofollow">endpoint mappings</a> like <tt>PayloadRootQNameEndpointMapping</tt>,
<tt>SoapActionEndpointMapping</tt>, etc </td>
</tr>
</tbody></table>
</div>
</div>

<p>As a consumer the <b>address</b> should contain a value relevant to the
specified mapping-type (e.g. a SOAP action, XPath expression). As a producer the address should
be set to the URI of the web service your calling upon.</p>

<p>You can append query <b>options</b> to the URI in the following format,
<tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="SpringWebServices-Options"></a>Options</h3>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Required? </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>soapAction</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> SOAP action to include inside a SOAP request when accessing
remote web services </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>wsAddressingAction</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> WS-Addressing 1.0 action header to include when accessing
web services. The <tt>To</tt> header is set to the <em>address</em>
of the web service as specified in the endpoint URI (default Spring-WS behavior). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>expression</tt> </td>
<td class='confluenceTd'> Only when <em>mapping-type</em> is <tt>xpathresult</tt>
</td>
<td class='confluenceTd'> XPath expression to use in the process of mapping web service
requests, should match the result specified by <tt>xpathresult</tt> </td>
</tr>
</tbody></table>
</div>
</div>

<h4><a name="SpringWebServices-Registrybasedoptions"></a>Registry based
options</h4>

<p>The following options can be specified in the registry (most likely a Spring ApplicationContext)
and referenced from the endpoint URI using the # notation.</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Required? </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>webServiceTemplate</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Option to provide a custom <a href="http://static.springsource.org/spring-ws/sites/1.5/apidocs/org/springframework/ws/client/core/WebServiceTemplate.html"
class="external-link" rel="nofollow">WebServiceTemplate</a>. This allows for full
control over  client-side web services handling; like adding a custom interceptor or specifying
a fault resolver, message sender or message factory. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageSender</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Option to provide a custom <a href="http://static.springsource.org/spring-ws/sites/1.5/apidocs/org/springframework/ws/transport/WebServiceMessageSender.html"
class="external-link" rel="nofollow">WebServiceMessageSender</a>. For example to
perform authentication or use alternative transports </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>messageFactory</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Option to provide a custom <a href="http://static.springsource.org/spring-ws/sites/1.5/apidocs/org/springframework/ws/WebServiceMessageFactory.html"
class="external-link" rel="nofollow">WebServiceMessageFactory</a>. For example when
you want Apache Axiom to handle web service messages instead of SAAJ </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>transformerFactory</tt> </td>
<td class='confluenceTd'> No </td>
<td class='confluenceTd'> Option to override default TransformerFactory. The provided
transformer factory must be of type <tt>javax.xml.transform.TransformerFactory</tt>
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>endpointMapping</tt> </td>
<td class='confluenceTd'> Only when <em>mapping-type</em> is <tt>rootqname</tt>,
<tt>soapaction</tt>, <tt>uri</tt> or <tt>xpathresult</tt>
</td>
<td class='confluenceTd'> Reference to <tt>org.apache.camel.component.spring.ws.bean.CamelEndpointMapping</tt>
in the Registry/ApplicationContext. Only one bean is required in the registry to serve all
Camel/Spring-WS endpoints. This bean is auto-discovered by the <a href="http://static.springsource.org/spring-ws/sites/1.5/apidocs/org/springframework/ws/server/MessageDispatcher.html"
class="external-link" rel="nofollow">MessageDispatcher</a> and used to map requests
to Camel endpoints based on characteristics specified on the endpoint (like root QName, SOAP
action, etc) </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="SpringWebServices-Messageheaders"></a>Message headers</h3>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelSpringWebserviceEndpointUri</tt> </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> URI of the web service your accessing as a client, overrides
<em>address</em> part of the endpoint URI </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelSpringWebserviceSoapAction</tt> </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> Header to specify the SOAP action of the message, overrides
<tt>soapAction</tt> option if present </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelSpringWebserviceAddressingAction</tt>
</td>
<td class='confluenceTd'> URI </td>
<td class='confluenceTd'> Use this header to specify the WS-Addressing action of the
message, overrides <tt>wsAddressingAction</tt> option if present </td>
</tr>
</tbody></table>
</div>
</div>

<h2><a name="SpringWebServices-Accessingwebservices"></a>Accessing web services</h2>

<p>To call a web service at <tt><a href="http://foo.com/bar" class="external-link"
rel="nofollow">http://foo.com/bar</a></tt> simply define a route:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:example"</span>).to(<span class="code-quote">"spring-ws:http:<span
class="code-comment">//foo.com/bar"</span>)</span>
</pre>
</div></div>

<p>And sent a message:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
template.requestBody(<span class="code-quote">"direct:example"</span>, <span
class="code-quote">"&lt;foobar xmlns=\"</span>http:<span class="code-comment">//foo.com\<span
class="code-quote">"&gt;&lt;msg&gt;test message&lt;/msg&gt;&lt;/foobar&gt;"</span>);</span>
</pre>
</div></div>

<h3><a name="SpringWebServices-SendingSOAPandWSAddressingactionheaders"></a>Sending
SOAP and WS-Addressing action headers</h3>

<p>When a remote web service requires a SOAP action or use of the WS-Addressing standard
you define your route as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:example"</span>)
.to(<span class="code-quote">"spring-ws:http:<span class="code-comment">//foo.com/bar?soapAction=http://foo.com&amp;wsAddressingAction=http://bar.com"</span>)</span>
</pre>
</div></div>

<p>Optionally you can override the endpoint options with header values:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
template.requestBodyAndHeader(<span class="code-quote">"direct:example"</span>,

<span class="code-quote">"&lt;foobar xmlns=\"</span>http:<span class="code-comment">//foo.com\<span
class="code-quote">"&gt;&lt;msg&gt;test message&lt;/msg&gt;&lt;/foobar&gt;"</span>,

</span>SpringWebserviceConstants.SPRING_WS_SOAP_ACTION, <span class="code-quote">"http:<span
class="code-comment">//baz.com"</span>);</span>
</pre>
</div></div>

<h3><a name="SpringWebServices-UsingacustomMessageSenderandMessageFactory"></a>Using
a custom MessageSender and MessageFactory</h3>

<p>A custom message sender or factory in the registry can be referenced like this:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:example"</span>)
.to(<span class="code-quote">"spring-ws:http:<span class="code-comment">//foo.com/bar?messageFactory=#messageFactory&amp;messageSender=#messageSender"</span>)</span>
</pre>
</div></div>

<p>Spring configuration:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag"><span class="code-comment">&lt;!--
authenticate using HTTP Basic Authentication --&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"messageSender"</span>
class=<span class="code-quote">"org.springframework.ws.transport.http.CommonsHttpMessageSender"</span>&gt;</span>
	<span class="code-tag">&lt;property name=<span class="code-quote">"credentials"</span>&gt;</span>
		<span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.commons.httpclient.UsernamePasswordCredentials"</span>&gt;</span>
			<span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"0"</span>
value=<span class="code-quote">"admin"</span>/&gt;</span>
			<span class="code-tag">&lt;constructor-arg index=<span class="code-quote">"1"</span>
value=<span class="code-quote">"secret"</span>/&gt;</span>
		<span class="code-tag">&lt;/bean&gt;</span>
	<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>

<span class="code-tag"><span class="code-comment">&lt;!-- force use of Sun
SAAJ implementation, http://static.springsource.org/spring-ws/sites/1.5/faq.html#saaj-jboss
--&gt;</span></span>
<span class="code-tag">&lt;bean id=<span class="code-quote">"messageFactory"</span>
class=<span class="code-quote">"org.springframework.ws.soap.saaj.SaajSoapMessageFactory"</span>&gt;</span>
	<span class="code-tag">&lt;property name=<span class="code-quote">"messageFactory"</span>&gt;</span>
		<span class="code-tag">&lt;bean class=<span class="code-quote">"com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl"</span>&gt;</span><span
class="code-tag">&lt;/bean&gt;</span>
	<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<h2><a name="SpringWebServices-Exposingwebservices"></a>Exposing web services</h2>

<p>In order to expose a web service using this component you first need to set-up a
<a href="http://static.springsource.org/spring-ws/sites/1.5/reference/html/server.html"
class="external-link" rel="nofollow">MessageDispatcher</a> to look for endpoint mappings
in a Spring XML file. If you plan on running inside a servlet container you probably want
to use a <tt>MessageDispatcherServlet</tt> configured in <tt>web.xml</tt>.
</p>

<p>By default the <tt>MessageDispatcherServlet</tt> will look for a Spring
XML named <tt>/WEB-INF/spring-ws-servlet.xml</tt>. To use Camel with Spring-WS
the only mandatory bean in that XML file is <tt>CamelEndpointMapping</tt>. This
bean allows the <tt>MessageDispatcher</tt> to dispatch web service requests to
your routes. </p>

<p><em>web.xml</em></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;web-app&gt;</span>
    <span class="code-tag">&lt;servlet&gt;</span>
        <span class="code-tag">&lt;servlet-name&gt;</span>spring-ws<span
class="code-tag">&lt;/servlet-name&gt;</span>
        <span class="code-tag">&lt;servlet-class&gt;</span>org.springframework.ws.transport.http.MessageDispatcherServlet<span
class="code-tag">&lt;/servlet-class&gt;</span>
        <span class="code-tag">&lt;load-on-startup&gt;</span>1<span
class="code-tag">&lt;/load-on-startup&gt;</span>
    <span class="code-tag">&lt;/servlet&gt;</span>
    <span class="code-tag">&lt;servlet-mapping&gt;</span>
        <span class="code-tag">&lt;servlet-name&gt;</span>spring-ws<span
class="code-tag">&lt;/servlet-name&gt;</span>
        <span class="code-tag">&lt;url-pattern&gt;</span>/*<span class="code-tag">&lt;/url-pattern&gt;</span>
    <span class="code-tag">&lt;/servlet-mapping&gt;</span>
<span class="code-tag">&lt;/web-app&gt;</span>
</pre>
</div></div>

<p><em>spring-ws-servlet.xml</em></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;bean id=<span class="code-quote">"endpointMapping"</span>
class=<span class="code-quote">"org.apache.camel.component.spring.ws.bean.CamelEndpointMapping"</span>
/&gt;</span>

<span class="code-tag">&lt;bean id=<span class="code-quote">"wsdl"</span>
class=<span class="code-quote">"org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition"</span>&gt;</span>
	<span class="code-tag">&lt;property name=<span class="code-quote">"schema"</span>&gt;</span>

		<span class="code-tag">&lt;bean class=<span class="code-quote">"org.springframework.xml.xsd.SimpleXsdSchema"</span>&gt;</span>
                  
			<span class="code-tag">&lt;property name=<span class="code-quote">"xsd"</span>
value=<span class="code-quote">"/WEB-INF/foobar.xsd"</span>/&gt;</span>
		<span class="code-tag">&lt;/bean&gt;</span>    
	<span class="code-tag">&lt;/property&gt;</span>                     
                  
	<span class="code-tag">&lt;property name=<span class="code-quote">"portTypeName"</span>
value=<span class="code-quote">"FooBar"</span>/&gt;</span>         
                      
	<span class="code-tag">&lt;property name=<span class="code-quote">"locationUri"</span>
value=<span class="code-quote">"/"</span>/&gt;</span>              
               
	<span class="code-tag">&lt;property name=<span class="code-quote">"targetNamespace"</span>
value=<span class="code-quote">"http://example.com/"</span>/&gt;</span>
      
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>More information on setting up Spring-WS can be found in <a href="http://static.springsource.org/spring-ws/sites/1.5/reference/html/tutorial.html"
class="external-link" rel="nofollow">Writing Contract-First Web Services</a>. Basically
paragraph 3.6 "Implementing the Endpoint" is handled by this component (specifically paragraph
3.6.2 "Routing the Message to the Endpoint" is where <tt>CamelEndpointMapping</tt>
comes in). Also don't forget to check out the <a href="/confluence/display/CAMEL/Spring+WS+Example"
title="Spring WS Example">Spring Web Services Example</a> included in the Camel distribution.</p>

<h3><a name="SpringWebServices-Endpointmappinginroutes"></a>Endpoint mapping
in routes</h3>

<p>With the XML configuration in-place you can now use Camel's DSL to define what web
service requests are handled by your endpoint:</p>

<p>The following route will receive all web service requests that have a root element
named "GetFoo" within the <tt><a href="http://example.com/" class="external-link"
rel="nofollow">http://example.com/</a></tt> namespace.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"spring-ws:rootqname:{http:<span class="code-comment">//example.com/}GetFoo?endpointMapping=#endpointMapping"</span>)
</span>.convertBodyTo(<span class="code-object">String</span>.class).to(mock:example)
</pre>
</div></div>

<p>The following route will receive web service requests containing the <tt><a
href="http://example.com/GetFoo" class="external-link" rel="nofollow">http://example.com/GetFoo</a></tt>
SOAP action.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"spring-ws:soapaction:http:<span class="code-comment">//example.com/GetFoo?endpointMapping=#endpointMapping"</span>)
</span>.convertBodyTo(<span class="code-object">String</span>.class).to(mock:example)
</pre>
</div></div>

<p>The following route will receive all requests sent to <tt><a href="http://example.com/foobar"
class="external-link" rel="nofollow">http://example.com/foobar</a></tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"spring-ws:uri:http:<span class="code-comment">//example.com/foobar?endpointMapping=#endpointMapping"</span>)
</span>.convertBodyTo(<span class="code-object">String</span>.class).to(mock:example)
</pre>
</div></div>

<p>The route below will receive requests that contain the element <tt>&lt;foobar&gt;abc&lt;/foobar&gt;</tt>
anywhere inside the message (and the default namespace).</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"spring-ws:xpathresult:abc?expression=<span class="code-comment">//foobar&amp;endpointMapping=#endpointMapping"</span>)
</span>.convertBodyTo(<span class="code-object">String</span>.class).to(mock:example)
</pre>
</div></div>

<h3><a name="SpringWebServices-Alternativeconfiguration%2Cusingexistingendpointmappings"></a>Alternative
configuration, using existing endpoint mappings</h3>

<p>For every endpoint with mapping-type <tt>beanname</tt> one bean of type
<tt>CamelEndpointDispatcher</tt> with a corresponding name is required in the
Registry/ApplicationContext. This bean acts as a bridge between the Camel endpoint and an
existing <a href="http://static.springsource.org/spring-ws/sites/1.5/reference/html/server.html#server-endpoint-mapping"
class="external-link" rel="nofollow">endpoint mapping</a> like <tt>PayloadRootQNameEndpointMapping</tt>.
</p>

<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/warning.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>The use of the <tt>beanname</tt>
mapping-type is primarily meant for (legacy) situations where you're already using Spring-WS
and have endpoint mappings defined in a Spring XML file. The <tt>beanname</tt>
mapping-type allows you to wire your Camel route into an existing endpoint mapping. When you're
starting from scratch it's recommended to define your endpoint mappings as Camel URI's (as
illustrated above with <tt>endpointMapping</tt>) since it requires less configuration
and is more expressive. Alternatively you could use vanilla Spring-WS with the help of annotations.</td></tr></table></div>

<p>An example of a route using <tt>beanname</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext xmlns=<span class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>	&lt;route&gt;
		&lt;from uri=<span class="code-quote">"spring-ws:beanname:QuoteEndpointDispatcher"</span>
/&gt;
		&lt;to uri=<span class="code-quote">"mock:example"</span> /&gt;
	&lt;/route&gt;
&lt;/camelContext&gt;

&lt;bean id=<span class="code-quote">"legacyEndpointMapping"</span> class=<span
class="code-quote">"org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping"</span>&gt;
    &lt;property name=<span class="code-quote">"mappings"</span>&gt;
        &lt;props&gt;
            &lt;prop key=<span class="code-quote">"{http:<span class="code-comment">//example.com/}GetFuture"</span>&gt;FutureEndpointDispatcher&lt;/prop&gt;
</span>            &lt;prop key=<span class="code-quote">"{http:<span class="code-comment">//example.com/}GetQuote"</span>&gt;QuoteEndpointDispatcher&lt;/prop&gt;
</span>        &lt;/props&gt;
    &lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=<span class="code-quote">"QuoteEndpointDispatcher"</span> class=<span
class="code-quote">"org.apache.camel.component.spring.ws.bean.CamelEndpointDispatcher"</span>
/&gt;
&lt;bean id=<span class="code-quote">"FutureEndpointDispatcher"</span> class=<span
class="code-quote">"org.apache.camel.component.spring.ws.bean.CamelEndpointDispatcher"</span>
/&gt;
</pre>
</div></div>

<h2><a name="SpringWebServices-POJO%28un%29marshalling"></a>POJO (un)marshalling</h2>

<p>Camel's <a href="/confluence/display/CAMEL/Data+Format" title="Data Format">pluggable
data formats</a> offer support for pojo/xml marshalling using libraries such as JAXB,
XStream, Castor and XMLBeans. You can use these data formats in your route to sent and receive
pojo's, to and from web services. </p>

<p>When <em>accessing</em> web services you can marshal the request and
unmarshal the response message:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
JaxbDataFormat jaxb = <span class="code-keyword">new</span> JaxbDataFormat(<span
class="code-keyword">false</span>);
jaxb.setContextPath(<span class="code-quote">"com.example.model"</span>);

from(<span class="code-quote">"direct:example"</span>).marshal(jaxb).to(<span
class="code-quote">"spring-ws:http:<span class="code-comment">//foo.com/bar"</span>).unmarshal(jaxb);</span>
</pre>
</div></div>

<p>Similarly when <em>providing</em> web services, you can unmarshal XML
requests to POJO's and marshal the response message back to XML:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"spring-ws:rootqname:{http:<span class="code-comment">//example.com/}GetFoo?endpointMapping=#endpointMapping"</span>).unmarshal(jaxb)
</span>.to(<span class="code-quote">"mock:example"</span>).marshal(jaxb);
</pre>
</div></div>

<h3><a name="SpringWebServices-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Spring+Web+Services">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24184490&revisedVersion=20&originalVersion=19">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Spring+Web+Services?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message