servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache ServiceMix > servicemix-file
Date Mon, 17 May 2010 10:13:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/13/_/styles/combined.css?spaceKey=SM&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="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" >| filter		| class		| java.io.FileFilter
(optional filter)				| null - no filter      		| <br>| scheduler		| class		| org.apache.servicemix.components.varscheduler.Scheduler
| new Scheduler(true)			| <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
comparator            | class         | implementation of java.util.Comparator&lt;File&gt;
interface        | null - no ordering                    | <br></td></tr>
            <tr><td class="diff-unchanged" >| archive               | string 
      | sets the directory to archive files before deleting them \\ (available since 3.2)
                  | null (no archiving)                   | <br>{info} <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >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: http://commons.apache.org/io/ <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2.
Comparators <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">You
can define an implementation of the java.util.Comparator interface to specifies the process
order of the files. <br> <br>For example, you can process file sorted by file
name. You can implement the following comparator: <br> <br>{code:lang=java|title=NameComparator}
<br>public class NameComparator implements Comparator&lt;File&gt; { <br>
<br>    /* <br>     * (non-Javadoc) <br>     * @see java.util.Comparator#compare(java.lang.Object,
java.lang.Object) <br>     */ <br>    public int compare(File file1, File file2)
{ <br>        return file1.getPath().compareTo(file2.getPath()); <br>    } <br>
<br>} <br>{code} <br> <br>and use it in the endpoint definition: <br>
<br>{code:lang=xml|title=XBean using NameComparator} <br>&lt;file:poller service=&quot;test:poller&quot;
endpoint=&quot;poller&quot; <br>	file=&quot;file:inbox&quot; targetService=&quot;test:service&quot;
<br>	targetEndpoint=&quot;endpoint&quot; period=&quot;10000&quot; recursive=&quot;true&quot;&gt;
<br>        &lt;property name=&quot;comparator&quot;&gt; <br>
           &lt;bean class=&quot;your.package.NameComparator&quot;/&gt; <br>
       &lt;/property&gt; <br>&lt;/file:poller&gt; <br>{code} <br>
<br>Like this, you can process file by name, last modification date, size. <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 &amp; write files via URI or to periodically poll directories for new
files.</p>

<p>Note that this component is only available in releases &gt;= 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">
&lt;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>
/&gt;
</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">
&lt;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> /&gt;
</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'>&nbsp;</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'>&nbsp;</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'>&nbsp;</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'>&nbsp;</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'>&nbsp;</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&lt;File&gt;
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>&nbsp;<br/>
&nbsp;</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'>&nbsp;</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'>&nbsp;</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'>&nbsp;</td>
<td class='confluenceTd'> "servicemix-"                         </td>
</tr>
<tr>
<td class='confluenceTd'> tempFileSuffix        </td>
<td class='confluenceTd'> string        </td>
<td class='confluenceTd'>&nbsp;</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">
&lt;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>&gt;
	<span class="code-tag">&lt;property name=<span class="code-quote">"filter"</span>&gt;</span>
		<span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.oro.io.GlobFilenameFilter"</span>&gt;</span>
			<span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"*.xml"</span>
/&gt;</span>
		<span class="code-tag">&lt;/bean&gt;</span>
	<span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/file:poller&gt;</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">
&lt;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>&gt;
        <span class="code-tag">&lt;property name=<span class="code-quote">"filter"</span>&gt;</span>
            <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.commons.io.filefilter.WildcardFilter"</span>&gt;</span>
                <span class="code-tag">&lt;constructor-arg value=<span class="code-quote">"*.csv"</span>
/&gt;</span>
            <span class="code-tag">&lt;/bean&gt;</span>
        <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/file:poller&gt;</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&lt;File&gt; {
    
    /*
     * (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">
&lt;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>&gt;
        <span class="code-tag">&lt;property name=<span class="code-quote">"comparator"</span>&gt;</span>
            <span class="code-tag">&lt;bean class=<span class="code-quote">"your.package.NameComparator"</span>/&gt;</span>
        <span class="code-tag">&lt;/property&gt;</span>
<span class="code-tag">&lt;/file:poller&gt;</span>
</pre>
</div></div>

<p>Like this, you can process file by name, last modification date, size.</p>

<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">&lt;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>&gt;</span>
  <span class="code-tag">&lt;file:marshaler&gt;</span>
    <span class="code-tag">&lt;sm:defaultFileMarshaler&gt;</span>
      <span class="code-tag">&lt;sm:fileName&gt;</span>
        <span class="code-tag"><span class="code-comment">&lt;!-- lets use
a header from the message --&gt;</span></span>
        <span class="code-tag">&lt;sm:xpathString xpath=<span class="code-quote">"concat($name,
'.xml')"</span>/&gt;</span>
      <span class="code-tag">&lt;/sm:fileName&gt;</span>
    <span class="code-tag">&lt;/sm:defaultFileMarshaler&gt;</span>
  <span class="code-tag">&lt;/file:marshaler&gt;</span>
<span class="code-tag">&lt;/file:sender&gt;</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">&lt;?xml version=<span class="code-quote">"1.0"</span>?&gt;</span>
&lt;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>&gt;

  &lt;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>&gt;

    <span class="code-tag">&lt;property name=<span class="code-quote">"marshaler"</span>&gt;</span>
      <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.servicemix.components.util.BinaryFileMarshaler"</span>
/&gt;</span>
    <span class="code-tag">&lt;/property&gt;</span>
  <span class="code-tag">&lt;/f:sender&gt;</span>


  &lt;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>&gt;

      <span class="code-tag">&lt;property name=<span class="code-quote">"marshaler"</span>&gt;</span>
        <span class="code-tag">&lt;bean class=<span class="code-quote">"org.apache.servicemix.components.util.BinaryFileMarshaler"</span>
/&gt;</span>
      <span class="code-tag">&lt;/property&gt;</span>
    <span class="code-tag">&lt;/f:poller&gt;</span>
<span class="code-tag">&lt;/beans&gt;</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=21&originalVersion=20">View
Changes</a>
                |
        <a href="http://cwiki.apache.org/confluence/display/SM/servicemix-file?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message