camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > SOAP
Date Sat, 27 Feb 2010 20:35:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/SOAP">SOAP</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~christian%2Bschneider">Christian
Schneider</a>
    </h4>
     
          <br/>
     <div class="notificationGreySide">
         <h2><a name="SOAP-SOAP%28AvailableinCamel%3E%3D2.3.0%29"></a>SOAP
(Available in Camel &gt;= 2.3.0) </h2>

<p>SOAP is a <a href="/confluence/display/CAMEL/Data+Format" title="Data Format">Data
Format</a> which uses JAXB2 and JAX-WS to marshal and unmarshal SOAP payloads. It provides
the basic features of Apache CXF without need for the CXF Stack.</p>

<h3><a name="SOAP-ElementNameStrategy"></a>ElementNameStrategy</h3>

<p>An element name strategy is used for two purposes. The first is to find a xml element
name for a given object and soap action when marshalling the object into a SOAP message. The
second is to find an Exception class for a given soap fault name.</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Strategy </th>
<th class='confluenceTh'> Usage </th>
</tr>
<tr>
<td class='confluenceTd'> QNameStrategy </td>
<td class='confluenceTd'> Uses a fixed qName that is configured on instantiation. Exception
lookup is not supported </td>
</tr>
<tr>
<td class='confluenceTd'> TypeNameStrategy </td>
<td class='confluenceTd'> Uses the name and namespace from the @XMLType annotation of
the given type. If no namespace is set then package-info is used. Exception lookup is not
supported </td>
</tr>
<tr>
<td class='confluenceTd'> ServiceInterfaceStrategy </td>
<td class='confluenceTd'> Uses information from a webservice interface to determine
the type name and to find the exception class for a SOAP fault</td>
</tr>
</tbody></table>

<p>If you have generated the web service stub code with cxf-codegen or a similar tool
then you probably will want to use the ServiceInterfaceStrategy. In the case you have no annotated
service interface you should use QNameStrategy or TypeNameStrategy.</p>

<h3><a name="SOAP-UsingtheJavaDSL"></a>Using the Java DSL</h3>

<p>For example the following uses a named DataFormat of <em>soap</em> which
is configured with the package com.example.customerservice to initialize the <a href="http://java.sun.com/javase/6/docs/api/javax/xml/bind/JAXBContext.html"
rel="nofollow">JAXBContext</a>. The second parameter is the ElementNameStrategy.
The route is able to marshal normal objects as well as exceptions.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
SoapJaxbDataFormat soap = <span class="code-keyword">new</span> SoapJaxbDataFormat(<span
class="code-quote">"com.example.customerservice"</span>, <span class="code-keyword">new</span>
ServiceNameStrategy(CustomerService.class));
from(<span class="code-quote">"direct:start"</span>)
  .marshal(soap)
  .to(<span class="code-quote">"jms:myQueue"</span>);
</pre>
</div></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>See also</b><br
/>As the SOAP dataformat inherits from the <a href="/confluence/display/CAMEL/JAXB"
title="JAXB">JAXB</a> dataformat most settings apply here as well</td></tr></table></div>

<h3><a name="SOAP-Examples"></a>Examples</h3>

<h4><a name="SOAP-Webserviceclient"></a>Webservice client</h4>

<p>This snippet shows how to create a proxy for a service interface that sends requests
to a direct endpoint and is also able to receive the response. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Endpoint startEndpoint = context.getEndpoint(<span class="code-quote">"direct:customerServiceClient"</span>);
<span class="code-object">ClassLoader</span> classLoader = <span class="code-object">Thread</span>.currentThread().getContextClassLoader();
CustomerService proxy = ProxyHelper.createProxy(startEndpoint, classLoader, CustomerService.class);
GetCustomersByNameResponse response = proxy.getCustomersByName(<span class="code-keyword">new</span>
GetCustomersByName());
</pre>
</div></div>

<p>This route supports marshalling the request and unmarshalling response or fault.
</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
SoapJaxbDataFormat soap = <span class="code-keyword">new</span> SoapJaxbDataFormat(<span
class="code-quote">"com.example.customerservice"</span>, <span class="code-keyword">new</span>
ServiceNameStrategy(CustomerService.class));
from(<span class="code-quote">"direct:customerServiceClient"</span>)
  .onException(Exception.class)
    .handled(<span class="code-keyword">true</span>)
    .unmarshal(soap)
  .end()
  .marshal(soap)
  .to(<span class="code-quote">"http:<span class="code-comment">//myserver/customerservice"</span>)
</span>  .unmarshal(soapDataFormat);
</pre>
</div></div>

<h4><a name="SOAP-WebserviceServer"></a>Webservice Server</h4>

<p>Using the following route sets up a webservice server that listens on jms queue customerServiceQueue
and processes requests<br/>
using the class CustomerServiceImpl. The customerServiceImpl of course should implement the
interface CustomerService. Instead of directly<br/>
instantiating the server class it could of course be defined in a spring context as a regular
bean.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
SoapJaxbDataFormat soap = <span class="code-keyword">new</span> SoapJaxbDataFormat(<span
class="code-quote">"com.example.customerservice"</span>, <span class="code-keyword">new</span>
ServiceNameStrategy(CustomerService.class));
CustomerService serverBean = <span class="code-keyword">new</span> CustomerServiceImpl();
from(<span class="code-quote">"jms:<span class="code-comment">//queue:customerServiceQueue"</span>)
</span>  .onException(Exception.class)
    .handled(<span class="code-keyword">true</span>)
    .marshal(soap)
  .end()
  .unmarshal(soap)
  .bean(serverBean)
  .marshal(soapDataFormat);
</pre>
</div></div>

<h3><a name="SOAP-Dependencies"></a>Dependencies</h3>

<p>To use the SOAP dataformat in your camel routes you need to add the following dependency
to your pom.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
  &lt;artifactId&gt;camel-soap&lt;/artifactId&gt;
  &lt;version&gt;1.6.0&lt;/version&gt;
&lt;/dependency&gt;
</pre>
</div></div>
     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/SOAP">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=14811197&revisedVersion=3&originalVersion=2">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/SOAP?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message