camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > File Language
Date Sun, 26 Sep 2010 06:58:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/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/File+Language">File
Language</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (10)</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" >And of course all this can be combined
in one expression where you can use the [File Language], [Simple] and the [Bean] language
in one combined expression. This is pretty powerful for those common file path patterns. <br>
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">{tip:title=Can
be used in Spring XML} <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3.
Using Spring PropertyPlaceholderConfigurer together with the [File|File2] component  <br></td></tr>
            <tr><td class="diff-changed-lines" >In Camel <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">2.2</span>
you can use the [File Language] directly from the [Simple] language which makes a [Content
Based Router] more easy to do in Spring XML, where we can route based on file extensions as
shown below: <br></td></tr>
            <tr><td class="diff-unchanged" >{code:xml} <br>  &lt;from
uri=&quot;file://input/orders&quot;/&gt; <br></td></tr>
            <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;">If
you use Springs PropertyPlaceholderConfigurer in conjunction with the file language, make
sure you set the property {{ignoreUnresolvablePlaceholders}} to {{true}}.  <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">If
you use the {{fileName}} option on the [File|File2] endpoint to set a dynamic filename using
the [File Language] then make sure you  <br>use the alternative syntax (available from
Camel 2.5 onwards) to avoid clash with Springs {{PropertyPlaceholderConfigurer}}. <br>
<br></td></tr>
            <tr><td class="diff-unchanged" >{code:title=bundle-context.xml} <br>&lt;bean
id=&quot;propertyPlaceholder&quot; class=&quot;org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&quot;&gt;
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
   &lt;property name=&quot;ignoreUnresolvablePlaceholders&quot; value=&quot;true&quot;
/&gt; <br></td></tr>
            <tr><td class="diff-unchanged" >    &lt;property name=&quot;location&quot;
value=&quot;classpath:bundle-context.cfg&quot; /&gt; <br>&lt;/bean&gt;
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >{code:title=bundle-context.cfg} <br>fromEndpoint=activemq:queue:test
<br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">toEndpoint=file://fileRoute/out?fileName=test-$<span
class="diff-added-chars"style="background-color: #dfd;">simple</span>{date:now:yyyyMMdd}.txt</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">Otherwise
you will receive an exception like <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>Notice how we use the $simple{ } syntax in the {{toEndpoint}} above. <br>If
you don&#39;t do this, there is a class and Spring will thrown an exception like <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br>org.springframework.beans.factory.BeanDefinitionStoreException:
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >Could not resolve placeholder &#39;date:now:yyyyMMdd&#39;
<br>{code} <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">{tip}
 <br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="FileLanguage-FileExpressionLanguage"></a>File Expression
Language</h2>

<p><b>Available as of Camel 1.5</b></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>File language
is now merged with Simple language</b><br />From Camel 2.2 onwards, the file language
is now merged with <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a>
language which means you can use all the file syntax directly within the simple language.</td></tr></table></div>

<p>The File Expression Language is an extension to the <a href="/confluence/display/CAMEL/Simple"
title="Simple">Simple</a> language, adding file related capabilities. These capabilities
is related to common use cases working with file path and names. The goal is to allow expression
to be used with the <a href="/confluence/display/CAMEL/File" title="File">File</a>
and <a href="/confluence/display/CAMEL/FTP" title="FTP">FTP</a> components for
setting dynamic file patterns for both consumer and producer. </p>

<h3><a name="FileLanguage-Syntax"></a>Syntax</h3>
<p>This language is an <b>extension</b> to the <a href="/confluence/display/CAMEL/Simple"
title="Simple">Simple</a> language so the <a href="/confluence/display/CAMEL/Simple"
title="Simple">Simple</a> syntax applies also. So the table below only lists the
additional. <br/>
As opposed to <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a>
language <a href="/confluence/display/CAMEL/File+Language" title="File Language">File
Language</a> also supports <a href="/confluence/display/CAMEL/Constant" title="Constant">Constant</a>
expressions so you can enter a fixed filename.</p>

<p>All the file tokens uses the same expression name as the method on the <tt>java.io.File</tt>
object, for instance <tt><a href="file:absolute" class="external-link" rel="nofollow">file:absolute</a></tt>
refers to the <tt>java.io.File.getAbsolute()</tt> method. Notice that not all
expressions is supported by the current Exchange. For instance the <a href="/confluence/display/CAMEL/FTP"
title="FTP">FTP</a> component supports some of the options, where as the <a href="/confluence/display/CAMEL/File"
title="File">File</a> component support all of them.</p>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Expression </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> File Consumer </th>
<th class='confluenceTh'> File Producer </th>
<th class='confluenceTh'> FTP Consumer </th>
<th class='confluenceTh'> FTP Producer </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:name" class="external-link" rel="nofollow">file:name</a>
</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> refers to the file name (is relative to the starting directory,
see note below) </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:name.ext" class="external-link" rel="nofollow">file:name.ext</a>
</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> refers to the file extension
only </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:name.noext" class="external-link" rel="nofollow">file:name.noext</a>
</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> refers to the file name with no extension (is relative to
the starting directory, see note below) </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:onlyname" class="external-link" rel="nofollow">file:onlyname</a>
</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> refers to the file name only
with no leading paths. </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:onlyname.noext" class="external-link" rel="nofollow">file:onlyname.noext</a>
</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> refers to the file name only
with no extension and with no leading paths. </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:ext" class="external-link" rel="nofollow">file:ext</a>
</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> <b>Camel 1.6.1/Camel 2.0:</b> refers to the file
extension only </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:parent" class="external-link" rel="nofollow">file:parent</a>
</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> refers to the file parent </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:path" class="external-link" rel="nofollow">file:path</a>
</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> refers to the file path </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:absolute" class="external-link" rel="nofollow">file:absolute</a>
</td>
<td class='confluenceTd'> Boolean </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> refers to whether the file is
regarded as absolute or relative </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:absolute.path" class="external-link" rel="nofollow">file:absolute.path</a>
</td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> refers to the absolute file path </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:length" class="external-link" rel="nofollow">file:length</a>
</td>
<td class='confluenceTd'> Long </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> refers to the file length returned as a Long type </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:size" class="external-link" rel="nofollow">file:size</a>
</td>
<td class='confluenceTd'> Long </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> <b>Camel 2.5:</b> refers to the file length returned
as a Long type </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:modified" class="external-link" rel="nofollow">file:modified</a>
</td>
<td class='confluenceTd'> Date </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> no </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> refers to the file last modified
returned as a Date type </td>
</tr>
<tr>
<td class='confluenceTd'> date:<em>command:pattern</em> </td>
<td class='confluenceTd'> String </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> yes </td>
<td class='confluenceTd'> for date formatting using the <tt>java.text.SimepleDataFormat</tt>
patterns. Is an <b>extension</b> to the <a href="/confluence/display/CAMEL/Simple"
title="Simple">Simple</a> language. Additional command is: <b>file</b>
(consumers only) for the last modified timestamp of the file. Notice: all the commands from
the <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> language
can also be used. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="FileLanguage-Filetokenexample"></a>File token example</h3>

<h4><a name="FileLanguage-Relativepaths"></a>Relative paths</h4>
<p>We have a <tt>java.io.File</tt> handle for the file <tt>hello.txt</tt>
in the following <b>relative</b> directory: <tt>.\filelanguage\test</tt>.
And we configure out endpoint to use this starting directory <tt>.\filelanguage</tt>.
The the file tokens will return as:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Expression </th>
<th class='confluenceTh'> Returns </th>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:name" class="external-link" rel="nofollow">file:name</a>
</td>
<td class='confluenceTd'> test\hello.txt </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:name.ext" class="external-link" rel="nofollow">file:name.ext</a>
</td>
<td class='confluenceTd'> txt </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:name.noext" class="external-link" rel="nofollow">file:name.noext</a>
</td>
<td class='confluenceTd'> test\hello </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:onlyname" class="external-link" rel="nofollow">file:onlyname</a>
</td>
<td class='confluenceTd'> hello.txt </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:onlyname.noext" class="external-link" rel="nofollow">file:onlyname.noext</a>
</td>
<td class='confluenceTd'> hello </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:ext" class="external-link" rel="nofollow">file:ext</a>
</td>
<td class='confluenceTd'> txt </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:parent" class="external-link" rel="nofollow">file:parent</a>
</td>
<td class='confluenceTd'> filelanguage\test </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:path" class="external-link" rel="nofollow">file:path</a>
</td>
<td class='confluenceTd'> filelanguage\test\hello.txt </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:absolute" class="external-link" rel="nofollow">file:absolute</a>
</td>
<td class='confluenceTd'> false </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:absolute.path" class="external-link" rel="nofollow">file:absolute.path</a>
</td>
<td class='confluenceTd'> \workspace\camel\camel-core\target\filelanguage\test\hello.txt
</td>
</tr>
</tbody></table>
</div>


<h4><a name="FileLanguage-Absolutepaths"></a>Absolute paths</h4>
<p>We have a <tt>java.io.File</tt> handle for the file <tt>hello.txt</tt>
in the following <b>absolute</b> directory: <tt>\workspace\camel\camel-core\target\filelanguage\test</tt>.
And we configure out endpoint to use the absolute starting directory <tt>\workspace\camel\camel-core\target\filelanguage</tt>.
The the file tokens will return as:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Expression </th>
<th class='confluenceTh'> Returns </th>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:name" class="external-link" rel="nofollow">file:name</a>
</td>
<td class='confluenceTd'> test\hello.txt </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:name.ext" class="external-link" rel="nofollow">file:name.ext</a>
</td>
<td class='confluenceTd'> txt </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:name.noext" class="external-link" rel="nofollow">file:name.noext</a>
</td>
<td class='confluenceTd'> test\hello </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:onlyname" class="external-link" rel="nofollow">file:onlyname</a>
</td>
<td class='confluenceTd'> hello.txt </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:onlyname.noext" class="external-link" rel="nofollow">file:onlyname.noext</a>
</td>
<td class='confluenceTd'> hello </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:ext" class="external-link" rel="nofollow">file:ext</a>
</td>
<td class='confluenceTd'> txt </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:parent" class="external-link" rel="nofollow">file:parent</a>
</td>
<td class='confluenceTd'> \workspace\camel\camel-core\target\filelanguage\test </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:path" class="external-link" rel="nofollow">file:path</a>
</td>
<td class='confluenceTd'> \workspace\camel\camel-core\target\filelanguage\test\hello.txt
</td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:absolute" class="external-link" rel="nofollow">file:absolute</a>
</td>
<td class='confluenceTd'> true </td>
</tr>
<tr>
<td class='confluenceTd'> <a href="file:absolute.path" class="external-link" rel="nofollow">file:absolute.path</a>
</td>
<td class='confluenceTd'> \workspace\camel\camel-core\target\filelanguage\test\hello.txt
</td>
</tr>
</tbody></table>
</div>


<h3><a name="FileLanguage-Samples"></a>Samples</h3>
<p>You can enter a fixed <a href="/confluence/display/CAMEL/Constant" title="Constant">Constant</a>
expression such as <tt>myfile.txt</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fileName=<span class="code-quote">"myfile.txt"</span>
</pre>
</div></div>

<p>Lets assume we use the file consumer to read files and want to move the read files
to backup folder with the current date as a sub folder. This can be archived using an expression
like:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fileName=<span class="code-quote">"backup/${date:now:yyyyMMdd}/${file:name.noext}.bak"</span>
</pre>
</div></div>

<p>relative folder names is also supported so suppose the backup folder should be a
sibling folder then you can append .. as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fileName=<span class="code-quote">"../backup/${date:now:yyyyMMdd}/${file:name.noext}.bak"</span>
</pre>
</div></div>

<p>As this is an extension to the <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a>
language we have access to all the goodies from this language also, so in this use case we
want to use the in.header.type as a parameter in the dynamic expression:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fileName=<span class="code-quote">"../backup/${date:now:yyyyMMdd}/type-${in.header.type}/backup-of-${file:name.noext}.bak"</span>
</pre>
</div></div>

<p>If you have a custom Date you want to use in the expression then Camel supports retrieving
dates from the message header.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fileName=<span class="code-quote">"orders/order-${in.header.customerId}-${date:in.header.orderDate:yyyyMMdd}.xml"</span>
</pre>
</div></div>

<p>And finally we can also use a bean expression to invoke a POJO class that generates
some String output (or convertible to String) to be used:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
fileName=<span class="code-quote">"uniquefile-${bean:myguidgenerator.generateid}.txt"</span>
</pre>
</div></div>

<p>And of course all this can be combined in one expression where you can use the <a
href="/confluence/display/CAMEL/File+Language" title="File Language">File Language</a>,
<a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> and the <a
href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> language in one combined
expression. This is pretty powerful for those common file path patterns.</p>

<h3><a name="FileLanguage-UsingSpringPropertyPlaceholderConfigurertogetherwiththeFileFile2component"></a>Using
Spring PropertyPlaceholderConfigurer together with the <a href="/confluence/display/CAMEL/File2"
title="File2">File</a> component </h3>
<p>In Camel you can use the <a href="/confluence/display/CAMEL/File+Language" title="File
Language">File Language</a> directly from the <a href="/confluence/display/CAMEL/Simple"
title="Simple">Simple</a> language which makes a <a href="/confluence/display/CAMEL/Content+Based+Router"
title="Content Based Router">Content Based Router</a> more easy to do in Spring XML,
where we can route based on file extensions as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;from uri=<span class="code-quote">"file://input/orders"</span>/&gt;</span>
     <span class="code-tag">&lt;choice&gt;</span>
       <span class="code-tag">&lt;when&gt;</span>
           <span class="code-tag">&lt;simple&gt;</span>${file:ext} ==
'txt'<span class="code-tag">&lt;/simple&gt;</span>
           <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:orderService?method=handleTextFiles"</span>/&gt;</span>
       <span class="code-tag">&lt;/when&gt;</span>
       <span class="code-tag">&lt;when&gt;</span>
           <span class="code-tag">&lt;simple&gt;</span>${file:ext} ==
'xml'<span class="code-tag">&lt;/simple&gt;</span>
           <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:orderService?method=handleXmlFiles"</span>/&gt;</span>
       <span class="code-tag">&lt;/when&gt;</span>
       <span class="code-tag">&lt;otherwise&gt;</span>
           <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:orderService?method=handleOtherFiles"</span>/&gt;</span>
       <span class="code-tag">&lt;/otherwise&gt;</span>
    <span class="code-tag">&lt;/choice&gt;</span>
</pre>
</div></div>

<p>If you use the <tt>fileName</tt> option on the <a href="/confluence/display/CAMEL/File2"
title="File2">File</a> endpoint to set a dynamic filename using the <a href="/confluence/display/CAMEL/File+Language"
title="File Language">File Language</a> then make sure you <br/>
use the alternative syntax (available from Camel 2.5 onwards) to avoid clash with Springs
<tt>PropertyPlaceholderConfigurer</tt>.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>bundle-context.xml</b></div><div
class="codeContent panelContent">
<pre class="code-java">
&lt;bean id=<span class="code-quote">"propertyPlaceholder"</span> class=<span
class="code-quote">"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"</span>&gt;
    &lt;property name=<span class="code-quote">"location"</span> value=<span
class="code-quote">"classpath:bundle-context.cfg"</span> /&gt;
&lt;/bean&gt;

&lt;bean id=<span class="code-quote">"sampleRoute"</span> class=<span class="code-quote">"SampleRoute"</span>&gt;
    &lt;property name=<span class="code-quote">"fromEndpoint"</span> value=<span
class="code-quote">"${fromEndpoint}"</span> /&gt;
    &lt;property name=<span class="code-quote">"toEndpoint"</span> value=<span
class="code-quote">"${toEndpoint}"</span> /&gt;
&lt;/bean&gt;
</pre>
</div></div>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>bundle-context.cfg</b></div><div
class="codeContent panelContent">
<pre class="code-java">
fromEndpoint=activemq:queue:test
toEndpoint=file:<span class="code-comment">//fileRoute/out?fileName=test-$simple{date:now:yyyyMMdd}.txt</span>
</pre>
</div></div>

<p>Notice how we use the $simple{ } syntax in the <tt>toEndpoint</tt> above.<br/>
If you don't do this, there is a class and Spring will thrown an exception like</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
org.springframework.beans.factory.BeanDefinitionStoreException:
Invalid bean definition with name 'sampleRoute' defined in class path resource [bundle-context.xml]:
Could not resolve placeholder 'date:now:yyyyMMdd'
</pre>
</div></div>


<h3><a name="FileLanguage-Dependencies"></a>Dependencies</h3>
<p>The File language is part of <b>camel-core</b>.</p>
    </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/File+Language">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=95383&revisedVersion=36&originalVersion=35">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/File+Language?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message