camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > Flatpack DataFormat
Date Fri, 07 Sep 2012 16:49:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
<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="">Flatpack
    <h4>Page <b>edited</b> by             <a href="">Christian
                         <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-flatpack&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;1.5.0&lt;/version&gt;</span>
<span class="diff-added-words"style="background-color: #dfd;">&lt;version&gt;x.x.x&lt;/version&gt;</span>
            <tr><td class="diff-unchanged" >&lt;/dependency&gt; <br>{code}
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="FlatpackDataFormat-FlatpackDataFormat"></a>Flatpack
<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>.
<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></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>
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>

<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>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
<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>
<td class='confluenceTd'> <tt>fixed</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Delimited or fixed. </td>
<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>
<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 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>
<td class='confluenceTd'> <tt>parserFactory</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Uses the default Flatpack parser factory. </td>

<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
  from(<span class="code-quote">"file:order/in"</span>).unmarshal(df).to(<span
<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
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>);
<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">

        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>
        <a href="">View
        <a href="">View
        <a href=";showCommentArea=true#addcomment">Add

View raw message