ServiceMix File
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.
Note that this component is only available in releases >= 3.1.
URI
You can use the familiar file URI to communicate with files
Endpoints
<file:sender service="test:service"
endpoint="endpoint"
directory="file:target/pollerFiles" />
<file:poller service="test:poller"
endpoint="poller"
targetService="test:receiver"
file="file:target/pollerFiles" />
Poller generates an InOnly message
 | Poller endpoint attributes
Name |
Type |
Description |
Default |
service |
QName |
the service name of the endpoint |
required to be spec'd |
endpoint |
string |
the endpoint name of the endpoint |
required to be spec'd |
interfaceName |
QName |
the interface name of the endpoint |
|
targetService |
QName |
the service name of the target endpoint |
|
targetEndPoint |
string |
the endpoint name of the target endpoint |
|
targetInterface |
QName |
the interface name of the target endpoint |
|
targetUri |
string |
the uri of the target endpoint |
|
autoCreateDirectory |
boolean |
creates dir if doesn't exist |
true |
firstTime |
date |
datetime before first poll can take place |
null (first poll right after start) |
delay |
long |
amount of time first polling is delayed after start |
0 |
period |
long |
amount of time between polls |
5000 |
file |
string |
sets the file or directory to poll |
null (must be spec'd) |
deleteFile |
boolean |
delete file when it is processed |
true |
recursive |
boolean |
process sub directories |
true |
marshaler |
class |
org.apache.servicemix.components.util.FileMarshaler |
DefaultFileMarshaler |
lockManager |
class |
org.apache.servicemix.locks.LockManager |
SimpleLockManager |
filter |
class |
java.io.FileFilter (optional filter) |
null - no filter |
scheduler |
class |
org.apache.servicemix.components.varscheduler.Scheduler |
new Scheduler(true) |
|
For all xbean file endpoint configuration take a look at Xml schemas
Filtering
Filtering of files to use during the polling process can be accomplished by configuring the filter property.
<file:poller service="test:poller" endpoint="poller"
file="file:inbox" targetService="test:service"
targetEndpoint="endpoint" period="10000" recursive="true">
<property name="filter">
<bean class="org.apache.oro.io.GlobFilenameFilter">
<constructor-arg value="*.xml" />
</bean>
</property>
</file:poller>
In this example, the apache oro jar must be in the classpath.
Marshalers
<file:sender service="test:service" endpoint="endpoint" directory="file:target/componentOutput">
<file:marshaler>
<sm:defaultFileMarshaler>
<sm:fileName>
<sm:xpathString xpath="concat($name, '.xml')"/>
</sm:fileName>
</sm:defaultFileMarshaler>
</file:marshaler>
</file:sender>