...
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.
Maven Archetype
You have two archetypes available depending of you want a file poller or a file sender.
The servicemix-file-poller-service-unit archetype creates a File Poller Service Unit which contains both poller and sender endpoints sample:
Code Block |
---|
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-file-poller-service-unit \
-DarchetypeVersion=2010.01 \
-DgroupId=your.group.id \
-DartifactId=your.artifact.id \
-Dversion=your-version
|
The servicemix-file-sender-service-unit archetype creates a File Sender Service UnitOnce you've customized the service unit, simply install the SU:
Code Block |
---|
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-file-sender-service-unit \
-DarchetypeVersion=2010.01 \
-DgroupId=your.group.id \
-DartifactId=your.artifact.id \
-Dversion=your-version
|
Endpoints Configuration
...
lang | xml |
---|---|
title | Provider endpoint |
install
|
Info | ||
---|---|---|
Remember that to be deployable in ServiceMix, the ServiceUnit has to be embedded in a Service Assembly: only the Service Assembly zip file can be deployed in ServiceMix.
|
Endpoints Configuration
Poller Endpoint
The File Poller endpoint polls file in a given directory, read it using the marshaler, and send marshaled file content to the NMR.
...
Code Block | ||||
---|---|---|---|---|
| ||||
<file:poller service="test:poller" endpoint="poller" targetService="test:receiver" file="file:target/pollerFiles" /> |
Note |
---|
Poller generates an InOnly message. |
Info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sender Endpoint
A File Sender endpoint expects messages coming from the NMR, converts it to file content (using the marshaler) and write file in the given directory.
Code Block | ||||
---|---|---|---|---|
| ||||
<file:sender service="test:service"
endpoint="endpoint"
directory="file:target/pollerFiles" />
|
Info | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||
|
...
URI
You can use the familiar file URI to communicate with files
...
In the example above, the Apache ORO jar must be in the classpath. See: http://jakarta.apache.org/oro/
Code Block | ||||
---|---|---|---|---|
| ||||
<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.commons.io.filefilter.WildcardFilter"> <constructor-arg value="*.csv" /> </bean> </property> </file:poller> |
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/
Comparators
You can define an implementation of the java.util.Comparator interface to specifies the process order of the files.
...