...
Div |
---|
class | confluenceTableSmall |
---|
|
Expression | Type | File Consumer | File Producer | FTP Consumer | FTP Producer | Description |
---|
file:name | String | yes | no | yes | no | refers to the file name (is relative to the starting directory, see note below) | file:name.ext | String | yes | no | yes | no | Camel 2.3: refers to the file extension only | file:name.noext | String | yes | no | yes | no | refers to the file name with no extension (is relative to the starting directory, see note below) | file:onlyname | String | yes | no | yes | no | refers to the file name only with no leading paths. | file:onlyname.noext | String | yes | no | yes | no | refers to the file name only with no extension and with no leading paths. | file:ext | String | yes | no | yes | no | refers to the file extension only | file:parent | String | yes | no | yes | no | refers to the file parent | file:path | String | yes | no | yes | no | refers to the file path | file:absolute | Boolean | yes | no | no | no | refers to whether the file is regarded as absolute or relative | file:absolute.path | String | yes | no | no | no | refers to the absolute file path | file:length | Long | yes | no | yes | no | refers to the file length returned as a Long type | file:size | Long | yes | no | yes | no | Camel 2.5: refers to the file length returned as a Long type | file:modified | Date | yes | no | yes | no | efers to the file last modified returned as a Date type | date:command:pattern | String | yes | yes | yes | yes | for date formatting using the java.text.SimepleDataFormatSimepleDateFormate patterns. Is an extension to the Simple language. Additional command is: file (consumers only) for the last modified timestamp of the file. Notice: all the commands from the Simple language can also be used. |
|
...
You can enter a fixed Constant expression such as myfile.txt
:
Code Block |
---|
fileName="myfile.txt"
|
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 archieved using an expression like:
Code Block |
---|
fileName="backup/${date:now:yyyyMMdd}/${file:name.noext}.bak"
|
relative folder names are also supported so suppose the backup folder should be a sibling folder then you can append .. as:
Code Block |
---|
fileName="../backup/${date:now:yyyyMMdd}/${file:name.noext}.bak"
|
As this is an extension to the Simple 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:
Code Block |
---|
fileName="../backup/${date:now:yyyyMMdd}/type-${in.header.type}/backup-of-${file:name.noext}.bak"
|
If you have a custom Date you want to use in the expression then Camel supports retrieving dates from the message header.
Code Block |
---|
fileName="orders/order-${in.header.customerId}-${date:in.header.orderDate:yyyyMMdd}.xml"
|
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:
Code Block |
---|
fileName="uniquefile-${bean:myguidgenerator.generateid}.txt"
|
...
In Camel you can use the File Language directly from the Simple language which makes a Content Based Router easier to do in Spring XML, where we can route based on file extensions as shown below:
Code Block |
---|
|
<from uri="file://input/orders"/>
<choice>
<when>
<simple>${file:ext} == 'txt'</simple>
<to uri="bean:orderService?method=handleTextFiles"/>
</when>
<when>
<simple>${file:ext} == 'xml'</simple>
<to uri="bean:orderService?method=handleXmlFiles"/>
</when>
<otherwise>
<to uri="bean:orderService?method=handleOtherFiles"/>
</otherwise>
</choice>
|
...
Code Block |
---|
|
<bean id="propertyPlaceholder" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:bundle-context.cfg" />
</bean>
<bean id="sampleRoute" class="SampleRoute">
<property name="fromEndpoint" value="${fromEndpoint}" />
<property name="toEndpoint" value="${toEndpoint}" />
</bean>
|
Code Block |
---|
|
fromEndpoint=activemq:queue:test
toEndpoint=file://fileRoute/out?fileName=test-$simple{date:now:yyyyMMdd}.txt
|
Notice how we use the $simple{ } syntax in the toEndpoint
above.
If you don't do this, there is a clash and Spring will throw an exception like
Code Block |
---|
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'
|
...