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 Thu, 09 Sep 2010 01:56: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/SOAP">SOAP</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~mazzag">Glen
Mazza</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Fix SOAP Call format.<br />
    </div>
        <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" > <br>{code} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">String
WS_URI = &quot;cxf://http://myserver/customerservice?serviceClass=com.example.customerservice&amp;dataFormat=MESSAGE&quot;;
<br></td></tr>
            <tr><td class="diff-unchanged" >SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat(&quot;com.example.customerservice&quot;,
new ServiceInterfaceStrategy(CustomerService.class)); <br>from(&quot;direct:customerServiceClient&quot;)
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >  .end() <br>  .marshal(soapDF)
<br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">.to(&quot;http://myserver/customerservice&quot;)</span>
<span class="diff-added-words"style="background-color: #dfd;">.to(WS_URI)</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >  .unmarshal(soapDF); <br>{code}
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="SOAP-SOAPDataFormat"></a>SOAP DataFormat</h2>
<p><b>Available as of Camel 2.3</b></p>

<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>

<div class='table-wrap'>
<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>
</div>


<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"
class="external-link" 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>
ServiceInterfaceStrategy(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>The following route supports marshalling the request and unmarshalling a response
or fault. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">String</span> WS_URI = <span class="code-quote">"cxf:<span
class="code-comment">//http://myserver/customerservice?serviceClass=com.example.customerservice&amp;dataFormat=MESSAGE"</span>;
</span>SoapJaxbDataFormat soapDF = <span class="code-keyword">new</span>
SoapJaxbDataFormat(<span class="code-quote">"com.example.customerservice"</span>,
<span class="code-keyword">new</span> ServiceInterfaceStrategy(CustomerService.class));
from(<span class="code-quote">"direct:customerServiceClient"</span>)
  .onException(Exception.class)
    .handled(<span class="code-keyword">true</span>)
    .unmarshal(soapDF)
  .end()
  .marshal(soapDF)
  .to(WS_URI)
  .unmarshal(soapDF);
</pre>
</div></div>

<p>The below snippet creates a proxy for the service interface and makes a SOAP call
to the above route. </p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">import</span> org.apache.camel.Endpoint;
<span class="code-keyword">import</span> org.apache.camel.component.bean.ProxyHelper;
...

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();
<span class="code-comment">// CustomerService below is the service endpoint <span
class="code-keyword">interface</span>, *not* the javax.xml.ws.Service subclass
</span>CustomerService proxy = ProxyHelper.createProxy(startEndpoint, classLoader, CustomerService.class);
GetCustomersByNameResponse response = proxy.getCustomersByName(<span class="code-keyword">new</span>
GetCustomersByName());
</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 using the class CustomerServiceImpl. The customerServiceImpl of course
should implement the interface CustomerService. Instead of directly instantiating the server
class it could 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 soapDF = <span class="code-keyword">new</span> SoapJaxbDataFormat(<span
class="code-quote">"com.example.customerservice"</span>, <span class="code-keyword">new</span>
ServiceInterfaceStrategy(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(soapDF)
  .end()
  .unmarshal(soapDF)
  .bean(serverBean)
  .marshal(soapDF);
</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-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-soap<span class="code-tag">&lt;/artifactId&gt;</span>
  <span class="code-tag">&lt;version&gt;</span>2.3.0<span class="code-tag">&lt;/version&gt;</span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>
    </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/SOAP">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=14811197&revisedVersion=13&originalVersion=12">View
Changes</a>
                |
        <a href="https://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