When a poller endpoint is configured to poll a directory it will attempt to consume any file placed into that directory. If you want to limit the files a poller endpoint will attempt to consume, you can configure the endpoint to filter files based on their names. To do so, you must supply the endpoint with an implementation of the java.io.FileFilter
interface.
There are several file filter implementation available in open source including the Apache Commons IO implementations and the Apache Jakarta-ORO implementations. You can also implement your own file filter if you need specific filtering capabilities.
To implement a file filter, you need to provide an implementation of the
java.io.FileFilter
interface. The FileFilter
interface has a single method, accept()
, that needs to be implemented.
Example 2.11 shows the signature of the
accept()
method.
The accept()
method takes a File
object that represents the file being checked against the filter. If the file passes the filter, the accept()
method should return true
. If the file does not pass, then the method should return false
.
Example 2.12 shows a file filter implementation that matches against a string passed into its constructor.
Example 2.12. Simple file filter implementation
package org.apache.servicemix.demo; import java.io.File; import java.io.FileFilter; public class myFileFilter implements FileFilter { String filtername = "joe.xml"; public myFileFilter() { } public myFileFilter(String filtername) { this.filtername = filtername; } public boolean accept(File file) { String name = file.getName(); return name.equals(this.filtername); } }
You configure a poller endpoint to use a file filter using its filter
attribute. The filter
attribute's value is a reference to a
bean
element specifying the class of the file filter implementation.
Example 2.13 shows configuration for a poller endpoint that uses the
file filter implemented in Example 2.11. The
constructor-arg
element sets the filter's fitlername by
passing a value into the constructor.
Example 2.13. Poller endpoint using a file filter
<beans xmlns:file="http://servicemix.apache.org/file/1.0" xmlns:foo="http://servicemix.org/demo/"> <file:poller service="foo:filePoller" endpoint="filePoller" targetService="foo:fileSender" file="inbox" filter="#myFilter" /> <bean id="myFilter" class="org.apache.servicemix.demo.myFileFilter"> <constructor-arg value="joefred.xml" /> </bean> ... </beans>
![]() | Note |
---|---|
You can also configure a poller endpoint to use a file filter by adding a child
|