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 20:09: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>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~hekonsek">Henryk
Konsek</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Added version legend to the POM example.<br />
    </div>
        <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;artifactId&gt;camel-zipfile&lt;/artifactId&gt;
<br>  &lt;version&gt;x.x.x&lt;/version&gt; <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
 &lt;!-- use the same version as your Camel core version --&gt; <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">
        <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>

<p>If there is no incoming <tt>CamelFileName</tt> message header (for example,
if the <a href="/confluence/display/CAMEL/File2" title="File2">file component</a>
is not the consumer), then the message ID is used by default, and since the message ID is
normally a unique generated ID, you will end up with filenames like <tt>ID-MACHINENAME-2443-1211718892437-1-0.zip</tt>.
If you want to override this behavior, then you can set the value of the <tt>CamelFileName</tt>
header explicitly in your route:</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>).setHeader(Exchange.FILE_NAME,
constant(<span class="code-quote">"report.txt"</span>)).marshal().zipFile().to(<span
class="code-quote">"file:output/directory"</span>);</pre>
</div></div>

<p>This route would result in a Zip file named "report.txt.zip" in the output directory,
containing a single Zip entry named "report.txt".</p>

<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-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-zipfile<span
class="code-tag">&lt;/artifactId&gt;</span>
  <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
  <span class="code-tag"><span class="code-comment">&lt;!-- use the same version
as your Camel core version --&gt;</span></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/Zip+File+DataFormat">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=30753964&revisedVersion=5&originalVersion=4">View
Changes</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