Filter using org.apache.camel.component.file.GenericFileFilter - 6.3

Talend ESB Mediation Developer Guide

Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Design and Development
Talend ESB

Camel supports pluggable filtering strategies. You can then configure the endpoint with such a filter to skip certain files being processed.

In the sample we have built our own filter that skips files starting with skip in the filename:

public class MyFileFilter implements GenericFileFilter {
   public boolean accept(GenericFile pathname) {
      // we don't accept any files starting with skip in the name
      return !pathname.getFileName().startsWith("skip");

Then we can configure our route using the filter attribute to reference our filter (using # notation) that we have defines in the Spring XML file:

<!-- define our sorter as a plain Spring bean -->
<bean id="myFilter" class="com.mycompany.MyFileSorter"/>

   <from uri="file://inbox?filter=#myFilter"/>
   <to uri="bean:processInbox"/>

Filtering using ANT path matcher


There are also antInclude and antExclude options to make it easy to specify ANT style include/exclude without having to define the filter. See the URI options above for more information.

The ANT path matcher is shipped out-of-the-box in the camel-spring jar. So you need to depend on camel-spring if you are using Maven. The reason is that we leverage Spring's AntPathMatcher to do the matching.

The file paths is matched with the following rules:

  • ? matches one character

  • * matches zero or more characters

  • ** matches zero or more directories in a path

The sample below demonstrates how to use it:

<camelContext xmlns="">
   <template id="camelTemplate"/>

   <!-- use myFilter as filter to allow setting 
         ANT paths for which files to scan for -->
   <endpoint id="myFileEndpoint" uri=

      <from ref="myFileEndpoint"/>
      <to uri="mock:result"/>

<!-- we use the antpath file filter to use Ant paths -->
<!-- for includes and excludes -->
<bean id="myAntFilter" 
   <!-- include and file in the subfolder that has 'day' in the name -->
   <property name="includes" value="**/subfolder/**/*day*"/>
   <!-- exclude all files with 'bad' in name or .xml files. -->
   <!-- Use comma to separate multiple excludes -->
   <property name="excludes" value="**/*bad*,**/*.xml"/>