camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Flatpack DataFormat
Date Sat, 10 Nov 2012 11:44: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/Flatpack+DataFormat">Flatpack
DataFormat</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" >| {{delimiter}} | {{,}} | The delimiter
char (could be {{;}} {{,}} or similar) | <br>| {{parserFactory}} | {{null}} | Uses the
default Flatpack parser factory. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{allowShortLines}} | {{false}} | *Camel 2.9.5 and 2.10.3+*: Allows for lines to be shorter
than expected and ignores the extra characters. | <br>| {{ignoreExtraColumns}} | {{false}}
| *Camel 2.9.5 and 2.10.3+*: Allows for lines to be longer than expected and ignores the extra
characters. | <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h3. Usage <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="FlatpackDataFormat-FlatpackDataFormat"></a>Flatpack
DataFormat</h2>
<p>The <a href="/confluence/display/CAMEL/Flatpack" title="Flatpack">Flatpack</a>
component ships with the Flatpack data format that can be used to format between fixed width
or delimited text messages to a <tt>List</tt> of rows as <tt>Map</tt>.
</p>
<ul class="alternate" type="square">
	<li>marshal = from <tt>List&lt;Map&lt;String, Object&gt;&gt;</tt>
to <tt>OutputStream</tt> (can be converted to <tt>String</tt>)</li>
	<li>unmarshal = from <tt>java.io.InputStream</tt> (such as a <tt>File</tt>
or <tt>String</tt>) to a <tt>java.util.List</tt> as an <tt>org.apache.camel.component.flatpack.DataSetList</tt>
instance.<br/>
The result of the operation will contain all the data. If you need to process each row one
by one you can split the exchange, using <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a>.</li>
</ul>


<p><b>Notice:</b> The Flatpack library does currently not support header
and trailers for the marshal operation.</p>

<h3><a name="FlatpackDataFormat-Options"></a>Options</h3>
<p>The data format has the following options:</p>
<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'> <tt>definition</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The flatpack pzmap configuration file. Can be omitted in simpler
situations, but its preferred to use the pzmap. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fixed</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Delimited or fixed. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreFirstRecord</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Whether the first line is ignored for delimited files (for
the column headers). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>textQualifier</tt> </td>
<td class='confluenceTd'> <tt>"</tt> </td>
<td class='confluenceTd'> If the text is qualified with a char such as <tt>"</tt>.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delimiter</tt> </td>
<td class='confluenceTd'> <tt>,</tt> </td>
<td class='confluenceTd'> The delimiter char (could be <tt>;</tt> <tt>,</tt>
or similar) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>parserFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Uses the default Flatpack parser factory. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>allowShortLines</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.5 and 2.10.3+</b>: Allows for lines
to be shorter than expected and ignores the extra characters. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreExtraColumns</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9.5 and 2.10.3+</b>: Allows for lines
to be longer than expected and ignores the extra characters. </td>
</tr>
</tbody></table>
</div>


<h3><a name="FlatpackDataFormat-Usage"></a>Usage</h3>
<p>To use the data format, simply instantiate an instance and invoke the marshal or
unmarshal operation in the route builder:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  FlatpackDataFormat fp = <span class="code-keyword">new</span> FlatpackDataFormat();
  fp.setDefinition(<span class="code-keyword">new</span> ClassPathResource(<span
class="code-quote">"INVENTORY-Delimited.pzmap.xml"</span>));
  ...
  from(<span class="code-quote">"file:order/in"</span>).unmarshal(df).to(<span
class="code-quote">"seda:queue:neworder"</span>);
</pre>
</div></div>
<p>The sample above will read files from the <tt>order/in</tt> folder and
unmarshal the input using the Flatpack configuration file <tt>INVENTORY-Delimited.pzmap.xml</tt>
that configures the structure of the files. The result is a <tt>DataSetList</tt>
object we store on the SEDA queue.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
FlatpackDataFormat df = <span class="code-keyword">new</span> FlatpackDataFormat();
df.setDefinition(<span class="code-keyword">new</span> ClassPathResource(<span
class="code-quote">"PEOPLE-FixedLength.pzmap.xml"</span>));
df.setFixed(<span class="code-keyword">true</span>);
df.setIgnoreFirstRecord(<span class="code-keyword">false</span>);

from(<span class="code-quote">"seda:people"</span>).marshal(df).convertBodyTo(<span
class="code-object">String</span>.class).to(<span class="code-quote">"jms:queue:people"</span>);
</pre>
</div></div>
<p>In the code above we marshal the data from a Object representation as a <tt>List</tt>
of rows as <tt>Maps</tt>. The rows as <tt>Map</tt> contains the column
name as the key, and the the corresponding value. This structure can be created in Java code
from e.g. a processor. We marshal the data according to the Flatpack format and convert the
result as a <tt>String</tt> object and store it on a JMS queue.</p>

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

<p>To use Flatpack in your camel routes you need to add the a dependency on <b>camel-flatpack</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-flatpack&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/Flatpack+DataFormat">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=96143&revisedVersion=10&originalVersion=9">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Flatpack+DataFormat?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message