camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > Zip File DataFormat
Date Sat, 16 Feb 2013 20:09: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="">Zip
File DataFormat</a></h2>
    <h4>Page <b>edited</b> by             <a href="">Henryk
        <div id="versionComment">
        Added version legend to the POM example.<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}
    </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=""
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

<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 ""
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

<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></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

<p>This route would result in a Zip file named "" 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()); 

<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
  <span class="code-tag">&lt;artifactId&gt;</span>camel-zipfile<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>
        <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