camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Castor
Date Sat, 08 Sep 2012 09:55:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/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/Castor">Castor</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~muellerc">Christian
Mueller</a>
    </h4>
        <br/>
                         <h4>Changes (1)</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" >  &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
<br>  &lt;artifactId&gt;camel-castor&lt;/artifactId&gt; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">&lt;version&gt;2.1.0&lt;/version&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;version&gt;x.x.x&lt;/version&gt;</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >&lt;/dependency&gt; <br>{code}
<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Castor-Castor"></a>Castor</h2>
<p><b>Available as of Camel 2.1</b></p>

<p>Castor is a <a href="/confluence/display/CAMEL/Data+Format" title="Data Format">Data
Format</a> which uses the <a href="http://www.castor.org/" class="external-link"
rel="nofollow">Castor XML library</a> to unmarshal an XML payload into Java objects
or to marshal Java objects into an XML payload.</p>

<p>As usually you can use either Java DSL or Spring XML to work with Castor Data Format.
</p>

<h3><a name="Castor-UsingtheJavaDSL"></a>Using the Java DSL</h3>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:order"</span>).
  marshal().castor().
  to(<span class="code-quote">"activemq:queue:order"</span>);
</pre>
</div></div>

<p>For example the following uses a named DataFormat of Castor which uses default Castor
data binding features.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
CastorDataFormat castor = <span class="code-keyword">new</span> CastorDataFormat
();

from(<span class="code-quote">"activemq:My.Queue"</span>).
  unmarshal(castor).
  to(<span class="code-quote">"mqseries:Another.Queue"</span>);
</pre>
</div></div>



<p>If you prefer to use a named reference to a data format which can then be defined
in your Registry such as via your Spring XML file. e.g.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:My.Queue"</span>).
  unmarshal(<span class="code-quote">"mycastorType"</span>).
  to(<span class="code-quote">"mqseries:Another.Queue"</span>);
</pre>
</div></div>



<p>If you want to override default mapping schema by providing a mapping file you can
set it as follows.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
CastorDataFormat castor = <span class="code-keyword">new</span> CastorDataFormat
();
castor.setMappingFile(<span class="code-quote">"mapping.xml"</span>);
</pre>
</div></div>


<p>Also if you want to have more control on Castor Marshaller and Unmarshaller you can
access them as below.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
castor.getMarshaller();
castor.getUnmarshaller();
</pre>
</div></div>



<h3><a name="Castor-UsingSpringXML"></a>Using Spring XML</h3>
<p>The following example shows how to use Castor to unmarshal using Spring configuring
the castor data type</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camel"</span> 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">"direct:start"</span>/&gt;
    &lt;unmarshal&gt;
      &lt;castor validation=<span class="code-quote">"<span class="code-keyword">true</span>"</span>
/&gt;
    &lt;/unmarshal&gt;
    &lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;
  &lt;/route&gt;
&lt;/camelContext&gt;
</pre>
</div></div>

<p>This example shows how to configure the data type just once and reuse it on multiple
routes. You have to set the &lt;castor&gt; element directly in &lt;camelContext&gt;.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext&gt;
&lt;camelContext id=<span class="code-quote">"camel"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//camel.apache.org/schema/spring"</span>&gt;
</span>  &lt;dataFormats&gt;
    &lt;castor id=<span class="code-quote">"myCastor"</span>/&gt;
  &lt;/dataFormats&gt;

  &lt;route&gt;
    &lt;from uri=<span class="code-quote">"direct:start"</span>/&gt;
    &lt;marshal ref=<span class="code-quote">"myCastor"</span>/&gt;
    &lt;to uri=<span class="code-quote">"direct:marshalled"</span>/&gt;
  &lt;/route&gt;
  &lt;route&gt;
    &lt;from uri=<span class="code-quote">"direct:marshalled"</span>/&gt;
    &lt;unmarshal ref=<span class="code-quote">"myCastor"</span>/&gt;
    &lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;
  &lt;/route&gt;

&lt;/camelContext&gt;
</pre>
</div></div>


<h3><a name="Castor-Options"></a>Options</h3>
<p>Castor supports the following options</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> encoding </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> UTF-8 </td>
<td class='confluenceTd'> Encoding to use when marshalling an Object to XML </td>
</tr>
<tr>
<td class='confluenceTd'> validation </td>
<td class='confluenceTd'> Boolean </td>
<td class='confluenceTd'> false </td>
<td class='confluenceTd'> Whether validation is turned on or off. </td>
</tr>
<tr>
<td class='confluenceTd'> mappingFile </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> Path to a Castor mapping file to load from the classpath.
</td>
</tr>
<tr>
<td class='confluenceTd'> packages </td>
<td class='confluenceTd'> String[] </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> Add additional packages to Castor XmlContext </td>
</tr>
<tr>
<td class='confluenceTd'> classNames </td>
<td class='confluenceTd'> String[] </td>
<td class='confluenceTd'> null </td>
<td class='confluenceTd'> Add additional class names to Castor XmlContext </td>
</tr>
</tbody></table>
</div>


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

<p>To use Castor in your camel routes you need to add the a dependency on <b>camel-castor</b>
which implements this data format. </p>

<p>If you use maven you could just add the following to your pom.xml, substituting the
version number for the latest &amp; greatest release (see <a href="/confluence/display/CAMEL/Download"
title="Download">the download page for the latest versions</a>).</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-castor&lt;/artifactId&gt;
  &lt;version&gt;x.x.x&lt;/version&gt;
&lt;/dependency&gt;
</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/Castor">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=3475221&revisedVersion=3&originalVersion=2">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Castor?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message