<html>
<head>
<base href="http://cwiki.apache.org/confluence">
<link rel="stylesheet" href="/confluence/s/1810/9/13/_/styles/combined.css?spaceKey=SM&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="http://cwiki.apache.org/confluence/display/SM/servicemix-file">servicemix-file</a></h2>
<h4>Page <b>edited</b> by <a href="http://cwiki.apache.org/confluence/display/~nanthrax">Jean-Baptiste
Onofré</a>
</h4>
<br/>
<h4>Changes (3)</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" >{code} <br> <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Like
this, you can process file by name, last modification date, size. <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">We
provide the following comparators: <br></td></tr>
<tr><td class="diff-unchanged" > <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">{info:title=Provided
Comparator|borderStyle=solidbgColor='lighblue'} <br>|| Class Name
|| Description
|| <br>| org.apache.servicemix.file.comparator.FileNameComparator |
Compare the files based on the file name/path (alphanumeric sorted) | <br>|
org.apache.servicemix.file.comparator.LastModificationDateComparator | Compare the files based
on the last modification date (from oldest to newest) | <br>| org.apache.servicemix.file.comparator.SizeComparator
| Compare the files based on the file length (from smallest to biggest)
| <br>{info} <br> <br> <br></td></tr>
<tr><td class="diff-unchanged" >h2. Marshalers <br> <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<h1><a name="servicemix-file-ServiceMixFile"></a>ServiceMix File</h1>
<p>The ServiceMix File component provides JBI integration to the file system. It can
be used to read & write files via URI or to periodically poll directories for new
files.</p>
<p>Note that this component is only available in releases >= 3.1.</p>
<h2><a name="servicemix-file-URI"></a>URI</h2>
<p>You can use the familiar file URI to communicate with files</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
file:foo.xml
file:<span class="code-comment">//path/to/something</span>
</pre>
</div></div>
<h2><a name="servicemix-file-Endpoints"></a>Endpoints</h2>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Provider endpoint</b></div><div
class="codeContent panelContent">
<pre class="code-xml">
<file:sender service=<span class="code-quote">"test:service"</span>
endpoint=<span class="code-quote">"endpoint"</span>
directory=<span class="code-quote">"file:target/pollerFiles"</span>
/>
</pre>
</div></div>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Polling (consumer) endpoint</b></div><div
class="codeContent panelContent">
<pre class="code-xml">
<file:poller service=<span class="code-quote">"test:poller"</span>
endpoint=<span class="code-quote">"poller"</span>
targetService=<span class="code-quote">"test:receiver"</span>
file=<span class="code-quote">"file:target/pollerFiles"</span> />
</pre>
</div></div>
<p>Poller generates an InOnly message</p>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Poller endpoint
attributes</b><br /><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Default </th>
</tr>
<tr>
<td class='confluenceTd'> service </td>
<td class='confluenceTd'> QName </td>
<td class='confluenceTd'> the service name of the endpoint </td>
<td class='confluenceTd'> required to be spec'd </td>
</tr>
<tr>
<td class='confluenceTd'> endpoint </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> the endpoint name of the endpoint </td>
<td class='confluenceTd'> required to be spec'd </td>
</tr>
<tr>
<td class='confluenceTd'> interfaceName </td>
<td class='confluenceTd'> QName </td>
<td class='confluenceTd'> the interface name of the endpoint </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'> targetService </td>
<td class='confluenceTd'> QName </td>
<td class='confluenceTd'> the service name of the target endpoint </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'> targetEndpoint </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> the endpoint name of the target endpoint </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'> targetInterface </td>
<td class='confluenceTd'> QName </td>
<td class='confluenceTd'> the interface name of the target endpoint </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'> targetUri </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> the uri of the target endpoint </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'> autoCreateDirectory </td>
<td class='confluenceTd'> boolean </td>
<td class='confluenceTd'> creates dir if doesn't exist </td>
<td class='confluenceTd'> true </td>
</tr>
<tr>
<td class='confluenceTd'> firstTime </td>
<td class='confluenceTd'> date </td>
<td class='confluenceTd'> datetime before first poll can take place </td>
<td class='confluenceTd'> null (first poll right after start) </td>
</tr>
<tr>
<td class='confluenceTd'> delay </td>
<td class='confluenceTd'> long </td>
<td class='confluenceTd'> amount of time first polling is delayed after start </td>
<td class='confluenceTd'> 0 </td>
</tr>
<tr>
<td class='confluenceTd'> period </td>
<td class='confluenceTd'> long </td>
<td class='confluenceTd'> amount of time between polls </td>
<td class='confluenceTd'> 5000 </td>
</tr>
<tr>
<td class='confluenceTd'> file </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> sets the file or directory to poll </td>
<td class='confluenceTd'> null (must be spec'd) </td>
</tr>
<tr>
<td class='confluenceTd'> deleteFile </td>
<td class='confluenceTd'> boolean </td>
<td class='confluenceTd'> delete file when it is processed </td>
<td class='confluenceTd'> true </td>
</tr>
<tr>
<td class='confluenceTd'> recursive </td>
<td class='confluenceTd'> boolean </td>
<td class='confluenceTd'> process sub directories </td>
<td class='confluenceTd'> true </td>
</tr>
<tr>
<td class='confluenceTd'> marshaler </td>
<td class='confluenceTd'> class </td>
<td class='confluenceTd'> org.apache.servicemix.components.util.FileMarshaler </td>
<td class='confluenceTd'> DefaultFileMarshaler </td>
</tr>
<tr>
<td class='confluenceTd'> lockManager </td>
<td class='confluenceTd'> class </td>
<td class='confluenceTd'> org.apache.servicemix.locks.LockManager </td>
<td class='confluenceTd'> SimpleLockManager </td>
</tr>
<tr>
<td class='confluenceTd'> filter </td>
<td class='confluenceTd'> class </td>
<td class='confluenceTd'> java.io.FileFilter (optional filter) </td>
<td class='confluenceTd'> null - no filter </td>
</tr>
<tr>
<td class='confluenceTd'> scheduler </td>
<td class='confluenceTd'> class </td>
<td class='confluenceTd'> org.apache.servicemix.components.varscheduler.Scheduler </td>
<td class='confluenceTd'> new Scheduler(true) </td>
</tr>
<tr>
<td class='confluenceTd'> comparator </td>
<td class='confluenceTd'> class </td>
<td class='confluenceTd'> implementation of java.util.Comparator<File>
interface </td>
<td class='confluenceTd'> null - no ordering </td>
</tr>
<tr>
<td class='confluenceTd'> archive </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> sets the directory to archive files before deleting them <br
class="atl-forced-newline" /> (available since 3.2) </td>
<td class='confluenceTd'> null (no archiving) </td>
</tr>
</tbody></table>
</div>
</td></tr></table></div>
<p> <br/>
</p>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Sender endpoint
attributes</b><br /><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
<th class='confluenceTh'> Default </th>
</tr>
<tr>
<td class='confluenceTd'> service </td>
<td class='confluenceTd'> QName </td>
<td class='confluenceTd'> the service name of the endpoint </td>
<td class='confluenceTd'> required to be spec'd </td>
</tr>
<tr>
<td class='confluenceTd'> endpoint </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> the endpoint name of the endpoint </td>
<td class='confluenceTd'> required to be spec'd </td>
</tr>
<tr>
<td class='confluenceTd'> directory </td>
<td class='confluenceTd'> file </td>
<td class='confluenceTd'> </td>
<td class='confluenceTd'> required to be spec'd </td>
</tr>
<tr>
<td class='confluenceTd'> autoCreateDirectory </td>
<td class='confluenceTd'> boolean </td>
<td class='confluenceTd'> </td>
<td class='confluenceTd'> true </td>
</tr>
<tr>
<td class='confluenceTd'> append </td>
<td class='confluenceTd'> boolean </td>
<td class='confluenceTd'> append to an existing file instead of overwriting it (3.3
or above) </td>
<td class='confluenceTd'> false </td>
</tr>
<tr>
<td class='confluenceTd'> marshaler </td>
<td class='confluenceTd'> class </td>
<td class='confluenceTd'> org.apache.servicemix.components.util.FileMarshaler </td>
<td class='confluenceTd'> DefaultFileMarshaler </td>
</tr>
<tr>
<td class='confluenceTd'> tempFilePrefix </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> </td>
<td class='confluenceTd'> "servicemix-" </td>
</tr>
<tr>
<td class='confluenceTd'> tempFileSuffix </td>
<td class='confluenceTd'> string </td>
<td class='confluenceTd'> </td>
<td class='confluenceTd'> ".xml" </td>
</tr>
</tbody></table>
</div>
</td></tr></table></div>
<p>For all xbean file endpoint configuration take a look at <a href="/confluence/display/SM/Xml+schemas"
title="Xml schemas">Xml schemas</a></p>
<h2><a name="servicemix-file-Filtering"></a>Filtering</h2>
<p>Filtering of files to use during the polling process can be accomplished by configuring
the filter property.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Filter example</b></div><div
class="codeContent panelContent">
<pre class="code-xml">
<file:poller service=<span class="code-quote">"test:poller"</span> endpoint=<span
class="code-quote">"poller"</span>
file=<span class="code-quote">"file:inbox"</span> targetService=<span class="code-quote">"test:service"</span>
targetEndpoint=<span class="code-quote">"endpoint"</span> period=<span class="code-quote">"10000"</span>
recursive=<span class="code-quote">"true"</span>>
<span class="code-tag"><property name=<span class="code-quote">"filter"</span>></span>
<span class="code-tag"><bean class=<span class="code-quote">"org.apache.oro.io.GlobFilenameFilter"</span>></span>
<span class="code-tag"><constructor-arg value=<span class="code-quote">"*.xml"</span>
/></span>
<span class="code-tag"></bean></span>
<span class="code-tag"></property></span>
<span class="code-tag"></file:poller></span>
</pre>
</div></div>
<p>In the example above, the Apache ORO jar must be in the classpath. See: <a href="http://jakarta.apache.org/oro/"
class="external-link" rel="nofollow">http://jakarta.apache.org/oro/</a></p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>ServiceMix 3.2 Filter example</b></div><div
class="codeContent panelContent">
<pre class="code-xml">
<file:poller service=<span class="code-quote">"test:poller"</span> endpoint=<span
class="code-quote">"poller"</span>
file=<span class="code-quote">"file:inbox"</span> targetService=<span class="code-quote">"test:service"</span>
targetEndpoint=<span class="code-quote">"endpoint"</span> period=<span class="code-quote">"10000"</span>
recursive=<span class="code-quote">"true"</span>>
<span class="code-tag"><property name=<span class="code-quote">"filter"</span>></span>
<span class="code-tag"><bean class=<span class="code-quote">"org.apache.commons.io.filefilter.WildcardFilter"</span>></span>
<span class="code-tag"><constructor-arg value=<span class="code-quote">"*.csv"</span>
/></span>
<span class="code-tag"></bean></span>
<span class="code-tag"></property></span>
<span class="code-tag"></file:poller></span>
</pre>
</div></div>
<p>In the example above it uses Apache Commons IO WildcardFilter as it implements FileFilter.
The Apache Commons IO jar file must be in the classpath. See: <a href="http://commons.apache.org/io/"
class="external-link" rel="nofollow">http://commons.apache.org/io/</a></p>
<h2><a name="servicemix-file-Comparators"></a>Comparators</h2>
<p>You can define an implementation of the java.util.Comparator interface to specifies
the process order of the files.</p>
<p>For example, you can process file sorted by file name. You can implement the following
comparator:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>NameComparator</b></div><div
class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">public</span> class NameComparator <span class="code-keyword">implements</span>
Comparator<File> {
/*
* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.<span class="code-object">Object</span>,
java.lang.<span class="code-object">Object</span>)
*/
<span class="code-keyword">public</span> <span class="code-object">int</span>
compare(File file1, File file2) {
<span class="code-keyword">return</span> file1.getPath().compareTo(file2.getPath());
}
}
</pre>
</div></div>
<p>and use it in the endpoint definition:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>XBean using NameComparator</b></div><div
class="codeContent panelContent">
<pre class="code-xml">
<file:poller service=<span class="code-quote">"test:poller"</span> endpoint=<span
class="code-quote">"poller"</span>
file=<span class="code-quote">"file:inbox"</span> targetService=<span class="code-quote">"test:service"</span>
targetEndpoint=<span class="code-quote">"endpoint"</span> period=<span class="code-quote">"10000"</span>
recursive=<span class="code-quote">"true"</span>>
<span class="code-tag"><property name=<span class="code-quote">"comparator"</span>></span>
<span class="code-tag"><bean class=<span class="code-quote">"your.package.NameComparator"</span>/></span>
<span class="code-tag"></property></span>
<span class="code-tag"></file:poller></span>
</pre>
</div></div>
<p>We provide the following comparators:</p>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Provided
Comparator</b><br /><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Class Name
</th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> org.apache.servicemix.file.comparator.FileNameComparator
</td>
<td class='confluenceTd'> Compare the files based on the file name/path (alphanumeric
sorted) </td>
</tr>
<tr>
<td class='confluenceTd'> org.apache.servicemix.file.comparator.LastModificationDateComparator
</td>
<td class='confluenceTd'> Compare the files based on the last modification date (from
oldest to newest) </td>
</tr>
<tr>
<td class='confluenceTd'> org.apache.servicemix.file.comparator.SizeComparator
</td>
<td class='confluenceTd'> Compare the files based on the file length (from smallest
to biggest) </td>
</tr>
</tbody></table>
</div>
</td></tr></table></div>
<h2><a name="servicemix-file-Marshalers"></a>Marshalers</h2>
<p>By default, poller endpoints expect the content of the file to be in xml format.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Marshaler example</b></div><div
class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag"><file:sender service=<span class="code-quote">"test:service"</span>
endpoint=<span class="code-quote">"endpoint"</span> directory=<span class="code-quote">"file:target/componentOutput"</span>></span>
<span class="code-tag"><file:marshaler></span>
<span class="code-tag"><sm:defaultFileMarshaler></span>
<span class="code-tag"><sm:fileName></span>
<span class="code-tag"><span class="code-comment"><!-- lets use
a header from the message --></span></span>
<span class="code-tag"><sm:xpathString xpath=<span class="code-quote">"concat($name,
'.xml')"</span>/></span>
<span class="code-tag"></sm:fileName></span>
<span class="code-tag"></sm:defaultFileMarshaler></span>
<span class="code-tag"></file:marshaler></span>
<span class="code-tag"></file:sender></span>
</pre>
</div></div>
<p>Below is an example of a non-XML file marshaler that moves a file from an inbox to
an outbox directory. The binary marshaler sends a message with the file attached. This allows
any file to be processed.</p>
<p>The contents below were used in an xbean.xml file for a service unit named filemover</p>
<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>Binary File Marshaler example</b></div><div
class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag"><?xml version=<span class="code-quote">"1.0"</span>?></span>
<beans <span class="code-keyword">xmlns:f</span>=<span class="code-quote">"http://servicemix.apache.org/file/1.0"</span>
<span class="code-keyword">xmlns:proj</span>=<span class="code-quote">"http://servicemix.apache.org/samples/filemover"</span>
<span class="code-keyword">xmlns:sm</span>=<span class="code-quote">"http://servicemix.apache.org/config/1.0"</span>>
<f:sender service=<span class="code-quote">"proj:fileSender"</span>
endpoint=<span class="code-quote">"endpoint"</span>
directory=<span class="code-quote">"file:///C:/opensrc/test/myOutbox"</span>
autoCreateDirectory=<span class="code-quote">"true"</span>>
<span class="code-tag"><property name=<span class="code-quote">"marshaler"</span>></span>
<span class="code-tag"><bean class=<span class="code-quote">"org.apache.servicemix.components.util.BinaryFileMarshaler"</span>
/></span>
<span class="code-tag"></property></span>
<span class="code-tag"></f:sender></span>
<f:poller
service=<span class="code-quote">"proj:filePoller"</span>
endpoint=<span class="code-quote">"poller"</span>
file=<span class="code-quote">"file:///C:/opensrc/test/myInbox"</span>
targetService=<span class="code-quote">"proj:fileSender"</span>
targetEndpoint=<span class="code-quote">"endpoint"</span>
period=<span class="code-quote">"60000"</span>
recursive=<span class="code-quote">"true"</span>
autoCreateDirectory=<span class="code-quote">"true"</span>>
<span class="code-tag"><property name=<span class="code-quote">"marshaler"</span>></span>
<span class="code-tag"><bean class=<span class="code-quote">"org.apache.servicemix.components.util.BinaryFileMarshaler"</span>
/></span>
<span class="code-tag"></property></span>
<span class="code-tag"></f:poller></span>
<span class="code-tag"></beans></span>
</pre>
</div></div>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;">
<a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
</div>
<a href="http://cwiki.apache.org/confluence/display/SM/servicemix-file">View
Online</a>
|
<a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=39201&revisedVersion=22&originalVersion=21">View
Changes</a>
|
<a href="http://cwiki.apache.org/confluence/display/SM/servicemix-file?showComments=true&showCommentArea=true#addcomment">Add
Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
|