The ServiceMix VFS component provides support for reading from and writing to virtual file systems via the enterprise service bus by using the Apache commons-vfs library.
You can use Maven servicemix-vfs-service-unit archetype to create a VFS service unit:
mvn archetype:create \ -DarchetypeGroupId=org.apache.servicemix.tooling \ -DarchetypeArtifactId=servicemix-vfs-service-unit \ -DarchetypeVersion=2010.01 \ -DgroupId=your.group.id \ -DartifactId=your.artifact.id \ -Dversion=your-version |
Once you've customized the service unit, simply install the SU:
mvn install |
|
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.
|
The VFS Poller endpoint polls a VFS path, read the VFS file using the marshaler and send the file content to the NMR.
|
The VFS Poller endpoint generates an InOnly exchange. |
<vfs:poller service="replaceMe:serviceName"
endpoint="vfs-poller"
path="file:///vfs/path/input/"
targetService="replaceMe:serviceName"
targetEndpoint="target-endpoint"
period="10000"
deleteFile="true"
recursive="true" >
<property name="marshaler">
<bean class="org.apache.servicemix.components.util.BinaryFileMarshaler" />
</property>
</vfs:poller>
|
|
The VFS Sender endpoint expects messages coming from the NMR, converts it using the marshaler and send it to the VFS path.
<vfs:sender service="replaceMe:serviceName"
endpoint="vfs-sender"
path="file:///vfs/path/output/">
<property name="marshaler">
<bean class="org.apache.servicemix.components.util.BinaryFileMarshaler" />
</property>
</vfs:sender>
|
|
By default, poller endpoints expect the content of the file to be in XML format.
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.
The contents below were used in an xbean.xml file for a service unit named filemover
<?xml version="1.0"?>
<beans xmlns:vfs="http://servicemix.apache.org/vfs/1.0"
xmlns:proj="http://servicemix.apache.org/samples/filemover"
xmlns:sm="http://servicemix.apache.org/config/1.0">
<vfs:poller service="proj:vfsPoller"
endpoint="pollerEndpoint"
path="file:///C:/opensrc/test/myInbox"
targetService="proj:vfsSender"
period="10000"
deleteFile="true"
recursive="true" >
<property name="marshaler">
<bean class="org.apache.servicemix.components.util.BinaryFileMarshaler" />
</property>
</vfs:poller>
<vfs:sender service="proj:vfsSender"
endpoint="senderEndpoint"
path="file:///C:/opensrc/test/myOutbox/">
<property name="marshaler">
<bean class="org.apache.servicemix.components.util.BinaryFileMarshaler" />
</property>
</vfs:sender>
</beans>
|
Have a look at the Apache Commons-VFS Supported File Systems page.
|
Some of the VFS are accessed read-only. Those file system types can't be used for sender endpoints and will |