camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > BeanIO
Date Sun, 18 Mar 2012 10:20: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/BeanIO">BeanIO</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (6)</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" >The BeanIO [Data Format] uses [BeanIO|http://beanio.org/]
to handle flat payloads (such as XML, CSV, delimited, or fixed length formats). <br>
<br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">BeanIO
is configured using a [mappings XML|http://beanio.org/2.0/docs/reference/index.html#TheMappingFile]
file where you define the mapping from the flat format to Objects (POJOs). This mapping file
is mandatory to use. <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Options <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{div:class=confluenceTableSmall}
<br>|| Option || Default || Description || <br>| mapping | | The BeanIO mapping
file. The option is mandatory. Is by default loaded from the classpath. You can prefix with
{{file:}}, {{http:}}, or {{classpath:}} to denote from where to load the mapping file. | <br>|
streamName | | The name of the stream to use. This option is mandatory. | <br>| ignoreUnidentifiedRecords
| {{false}} | Whether to ignore unidentified records. | <br>| ignoreUnexpectedRecords
| {{false}} | Whether to ignore unexpected records. | <br>| ignoreInvalidRecords | {{false}}
| Whether to ignore invalid records. | <br>| encoding | Platform default | The charset
to use. | <br>{div} <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">||
Option || Type || Description || <br>| config | CSVConfig | Can be used to set a custom
CSVConfig object. | <br>TODO: <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Usage <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">TODO:
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">An
example of a [mapping file is here|https://svn.apache.org/repos/asf/camel/trunk/components/camel-beanio/src/test/resources/org/apache/camel/dataformat/beanio/mappings.xml].
<br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h4.
Using Java DSL <br>To use the {{BeanIODataFormat}} you need to configure the data format
with the mapping file, as well the name of the stream. <br>In Java DSL this can be done
as shown below. The streamName is &quot;employeeFile&quot;. <br> <br>Then
we have two routes. The first route is for transforming CSV data into a List&lt;Employee&gt;
Java objects. Which we then [split|Splitter], so the mock endpoint <br>receives a message
for each row. <br> <br>The 2nd route is for the reverse operation, to transform
a List&lt;Employee&gt; into a stream of CSV data. <br>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-beanio/src/test/java/org/apache/camel/dataformat/beanio/BeanIODataFormatSimpleTest.java}
<br> <br>The CSV data could for example be as below: <br>{snippet:id=e2|lang=java|url=camel/trunk/components/camel-beanio/src/test/java/org/apache/camel/dataformat/beanio/BeanIODataFormatSimpleTest.java}
<br> <br>h4. Using XML DSL <br>To use the BeanIO data format in XML, you
need to configure it using the &lt;beanio&gt; XML tag as shown below. The routes is
similar to the example above. <br>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-beanio/src/test/resources/org/apache/camel/dataformat/beanio/SpringBeanIODataFormatSimpleTest.xml}
<br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Dependencies <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="BeanIO-BeanIO"></a>BeanIO</h2>
<p><b>Available as of Camel 2.10</b></p>

<p>The BeanIO <a href="/confluence/display/CAMEL/Data+Format" title="Data Format">Data
Format</a> uses <a href="http://beanio.org/" class="external-link" rel="nofollow">BeanIO</a>
to handle flat payloads (such as XML, CSV, delimited, or fixed length formats).</p>

<p>BeanIO is configured using a <a href="http://beanio.org/2.0/docs/reference/index.html#TheMappingFile"
class="external-link" rel="nofollow">mappings XML</a> file where you define the mapping
from the flat format to Objects (POJOs). This mapping file is mandatory to use.</p>

<h3><a name="BeanIO-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> mapping </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The BeanIO mapping file. The option is mandatory. Is by default
loaded from the classpath. You can prefix with <tt>file:</tt>, <tt>http:</tt>,
or <tt>classpath:</tt> to denote from where to load the mapping file. </td>
</tr>
<tr>
<td class='confluenceTd'> streamName </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The name of the stream to use. This option is mandatory. </td>
</tr>
<tr>
<td class='confluenceTd'> ignoreUnidentifiedRecords </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether to ignore unidentified records. </td>
</tr>
<tr>
<td class='confluenceTd'> ignoreUnexpectedRecords </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether to ignore unexpected records. </td>
</tr>
<tr>
<td class='confluenceTd'> ignoreInvalidRecords </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether to ignore invalid records. </td>
</tr>
<tr>
<td class='confluenceTd'> encoding </td>
<td class='confluenceTd'> Platform default </td>
<td class='confluenceTd'> The charset to use. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="BeanIO-Usage"></a>Usage</h3>

<p>An example of a <a href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-beanio/src/test/resources/org/apache/camel/dataformat/beanio/mappings.xml"
class="external-link" rel="nofollow">mapping file is here</a>.</p>

<h4><a name="BeanIO-UsingJavaDSL"></a>Using Java DSL</h4>
<p>To use the <tt>BeanIODataFormat</tt> you need to configure the data format
with the mapping file, as well the name of the stream.<br/>
In Java DSL this can be done as shown below. The streamName is "employeeFile".</p>

<p>Then we have two routes. The first route is for transforming CSV data into a List&lt;Employee&gt;
Java objects. Which we then <a href="/confluence/display/CAMEL/Splitter" title="Splitter">split</a>,
so the mock endpoint<br/>
receives a message for each row.</p>

<p>The 2nd route is for the reverse operation, to transform a List&lt;Employee&gt;
into a stream of CSV data.</p>
<div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException:
Index: 20, Size: 20</span> </div>

<p>The CSV data could for example be as below:</p>
<div class="error"><span class="error">Error formatting macro: snippet: java.lang.IndexOutOfBoundsException:
Index: 20, Size: 20</span> </div>

<h4><a name="BeanIO-UsingXMLDSL"></a>Using XML DSL</h4>
<p>To use the BeanIO data format in XML, you need to configure it using the &lt;beanio&gt;
XML tag as shown below. The routes is similar to the example above.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext xmlns=<span
class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
  <span class="code-tag"><span class="code-comment">&lt;!-- setup beanio data
format --&gt;</span></span>
  <span class="code-tag">&lt;dataFormats&gt;</span>
    <span class="code-tag">&lt;beanio id=<span class="code-quote">"myBeanio"</span>
mapping=<span class="code-quote">"org/apache/camel/dataformat/beanio/mappings.xml"</span>
streamName=<span class="code-quote">"employeeFile"</span>/&gt;</span>
  <span class="code-tag">&lt;/dataFormats&gt;</span>

  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:unmarshal"</span>/&gt;</span>
    <span class="code-tag">&lt;unmarshal ref=<span class="code-quote">"myBeanio"</span>/&gt;</span>
    <span class="code-tag">&lt;split&gt;</span>
      <span class="code-tag">&lt;simple&gt;</span>body<span class="code-tag">&lt;/simple&gt;</span>
      <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:beanio-unmarshal"</span>/&gt;</span>
    <span class="code-tag">&lt;/split&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
  
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:marshal"</span>/&gt;</span>
    <span class="code-tag">&lt;marshal ref=<span class="code-quote">"myBeanio"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:beanio-marshal"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

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

<p>To use BeanIO in your camel routes you need to add the a dependency on <b>camel-beanio</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-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-beanio<span
class="code-tag">&lt;/artifactId&gt;</span>
  <span class="code-tag">&lt;version&gt;</span>2.10.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/BeanIO">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27841387&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/BeanIO?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message