These components write messages to files in a directory or poll files or directories (possibly recursively) to send files into the JBI.

Firstly here is the poller which will poll a file or directory (recursively by default) to find files, which are then sent into the JBI bus

<sm:activationSpec componentName="filePoller" service="foo:filePoller" destinationService="foo:receiver">
  <sm:component><bean class="org.apache.servicemix.components.file.FilePoller">
    <property name="workManager" ref="workManager"/>
    <property name="file" value="target/test-data/file"/>
    <!--
    <property name="delete" value="false"/>
    -->
    <property name="period" value="1000"/>
  </bean></sm:component>
</sm:activationSpec>

 

Then here's the sender. We're using a FileMarshaler here to turn JBI messages into files with an expression using XPath from the message content to generate the file name in the directory.

<sm:activationSpec componentName="fileSender" service="foo:fileSender">
  <sm:component><bean class="org.apache.servicemix.components.file.FileWriter">
    <property name="directory" value="target/test-data/file"/>

    <property name="marshaler">
      <bean class="org.apache.servicemix.components.util.DefaultFileMarshaler">
        <property name="fileName">
          <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
            <constructor-arg value="concat('sample_', /sample/@id, '.xml')"/>
          </bean>
        </property>
      </bean>
    </property>
  </bean></sm:component>
</sm:activationSpec>

 

You can if you prefer let the operating system generate temporary file names in the directory specifying an optional prefix and suffix.

Filtering inbound files

You cna configure a java.io.FileFilter to only accept certain files when polling.
This can be done by configuring the filter property on the poller:

<bean class="o.a.s.components.file.FilePoller">
  <property name="filter">
    <bean ... />
  </property>
</bean>

The Jakarta ORO project contains RegExp based filters, but you can also define your own filters by implementing java.io.FileFilter.