camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Zip File DataFormat
Date Sat, 16 Feb 2013 19:43: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/Zip+File+DataFormat">Zip
File DataFormat</a></h2>
    <h4>Page  <b>added</b> by             <a href="https://cwiki.apache.org/confluence/display/~sdanig">Daniel
Gredler</a>
    </h4>
         <br/>
    <div class="notificationGreySide">
         <p>The Zip File <a href="/confluence/display/CAMEL/Data+Format" title="Data
Format">Data Format</a> is a message compression and de-compression format. Messages
can be marshalled (compressed) to Zip files containing a single entry, and Zip files containing
a single entry can be unmarshalled (decompressed) to the original file contents. This data
format supports ZIP64, as long as <a href="https://blogs.oracle.com/xuemingshen/entry/zip64_support_for_4g_zipfile"
class="external-link" rel="nofollow">Java 7 or later is being used</a>.</p>

<h3><a name="ZipFileDataFormat-Marshal"></a>Marshal</h3>

<p>In this example we marshal a regular text/XML payload to a compressed payload using
Zip file compression, and send it to an ActiveMQ queue called MY_QUEUE.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:start"</span>).marshal().zipFile().to(<span
class="code-quote">"activemq:queue:MY_QUEUE"</span>);</pre>
</div></div>

<p>The name of the Zip entry inside the created Zip file is based on the incoming <tt>CamelFileName</tt>
message header, which is the standard message header used by the <a href="/confluence/display/CAMEL/File2"
title="File2">file component</a>. Additionally, the outgoing <tt>CamelFileName</tt>
message header is automatically set to the value of the incoming <tt>CamelFileName</tt>
message header, with the ".zip" suffix. So for example, if the following route finds a file
named "test.txt" in the input directory, the output will be a Zip file named "test.txt.zip"
containing a single Zip entry named "test.txt":</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"file:input/directory?antInclude=*/.txt"</span>).marshal().zipFile().to(<span
class="code-quote">"file:output/directory"</span>);</pre>
</div></div>

<h3><a name="ZipFileDataFormat-Unmarshal"></a>Unmarshal</h3>

<p>In this example we unmarshal a Zip file payload from an ActiveMQ queue called MY_QUEUE
to its original format, and forward it for processing to the <tt>UnZippedMessageProcessor</tt>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:queue:MY_QUEUE"</span>).unmarshal().zipFile().process(<span
class="code-keyword">new</span> UnZippedMessageProcessor()); 
</pre>
</div></div>

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

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

<p>If you use Maven you can just add the following to your <tt>pom.xml</tt>,
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-zipfile&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/Zip+File+DataFormat">View
Online</a>
              |
       <a href="https://cwiki.apache.org/confluence/display/CAMEL/Zip+File+DataFormat?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
           </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message