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 ws example
Date Sun, 09 Jan 2011 00:49:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/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+ws+example">spring
ws example</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~rkettelerij">Richard
Kettelerij</a>
    </h4>
        <br/>
                         <h4>Changes (2)</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" >mvn clean install jetty:run <br>{code}
<br></td></tr>
            <tr><td class="diff-changed-lines" >This will expose a web service
on {{http://localhost:8080/increment}}. With <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">the</span>
help of a tool such as [Soap-UI|http://www.soap-ui.org] it&#39;s easy to sent messages
to this endpoint. There&#39;s a ready to use SOAP-UI project available at {{examples/camel-example-spring-ws/client}}.
<br></td></tr>
            <tr><td class="diff-unchanged" > <br>h3. Code walk through <br>
<br></td></tr>
            <tr><td class="diff-changed-lines" >The Camel route <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">exposing</span>
<span class="diff-added-words"style="background-color: #dfd;">that exposes</span>
the above web service is defined as: <br></td></tr>
            <tr><td class="diff-unchanged" >{code:Java} <br>JaxbDataFormat
jaxb = new JaxbDataFormat(false); <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="springwsexample-SpringWebServicesExample"></a>Spring
Web Services Example</h2>
<p><b>Available as of Camel 2.6</b></p>

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

<h3><a name="springwsexample-Runningtheexample"></a>Running the example</h3>

<p>The example is included in the distribution at <tt>examples/camel-example-spring-ws</tt>.
To start the example use Maven:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn clean install jetty:run
</pre>
</div></div>
<p>This will expose a web service on <tt><a href="http://localhost:8080/increment"
class="external-link" rel="nofollow">http://localhost:8080/increment</a></tt>.
With help of a tool such as <a href="http://www.soap-ui.org" class="external-link" rel="nofollow">Soap-UI</a>
it's easy to sent messages to this endpoint. There's a ready to use SOAP-UI project available
at <tt>examples/camel-example-spring-ws/client</tt>.</p>

<h3><a name="springwsexample-Codewalkthrough"></a>Code walk through</h3>

<p>The Camel route that exposes the above web service is defined as:</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">"org.apache.camel.example.server.model"</span>);

from(<span class="code-quote">"spring-ws:rootqname:{http:<span class="code-comment">//camel.apache.org/example/increment}incrementRequest?endpointMapping=#endpointMapping"</span>)
</span>.unmarshal(jaxb)
.process(<span class="code-keyword">new</span> IncrementProcessor())
.marshal(jaxb);
</pre>
</div></div>

<p>Taking a closer look at the URI reveals that this route consumes messages with a
certain <tt>rootqname</tt>. In this case it listens for messages with root element
<tt>incrementRequest</tt> defined in the <tt><a href="http://camel.apache.org/example/increment"
class="external-link" rel="nofollow">http://camel.apache.org/example/increment</a></tt>
namespace. These XML messages are unmarshalled to using Camel's <a href="/confluence/display/CAMEL/Data+Format"
title="Data Format">Data Format</a> support (JAXB in this case). After processing
the resulting object is marshalled back to XML and returned to the client.</p>

<p>Further notice that the URI contains a reference to an <tt>endpointMapping</tt>
in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.
Since we're using Spring the registry is a Spring ApplicationContext defined in <tt>spring-ws-servlet.xml</tt>.
This file contains the following bean:</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;property name=<span class="code-quote">"interceptors"</span>&gt;</span>
		<span class="code-tag">&lt;list&gt;</span>
			<span class="code-tag">&lt;ref local=<span class="code-quote">"validatingInterceptor"</span>
/&gt;</span>
			<span class="code-tag">&lt;ref local=<span class="code-quote">"loggingInterceptor"</span>
/&gt;</span>
		<span class="code-tag">&lt;/list&gt;</span>
	<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/bean&gt;</span>
</pre>
</div></div>

<p>This bean is a Spring-WS <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> that maps incoming messages
to appropriate Camel routes. You'll only need to define <em>one</em> <tt>CamelEndpointMapping</tt>
regardless of the number of Camel routes that use Spring-WS endpoints. </p>

<p>The above <tt>endpointMapping</tt> bean is automatically picked up by
the <tt>MessageDispatcherServlet</tt> declared in <tt>web.xml</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<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;/servlet&gt;</span>
</pre>
</div></div>
<p>Since the servlet is named <tt>spring-ws</tt> it will look for the file
<tt>/WEB-INF/spring-ws-servlet.xml</tt> containing the earlier mentioned <tt>endpointMapping</tt>
bean.</p>
    </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+ws+example">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24192725&revisedVersion=6&originalVersion=5">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/spring+ws+example?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message