2 Replies Latest reply on Jan 25, 2013 7:57 PM by Keith Babo

    Custom filter in Camel file binding

    Calvin Chu Newbie

      I am using SwitchYard 0.6, I want to monitor files base on the file path with Camel file binding, I found the the include parameter is only apply to the file name. So I implemented the org.apache.camel.component.file.GenericFileFilter interface and pass the class name as the filter parameter in my SwitchYard.xml,

       

      <camel:binding.file>
           <camel:contextMapper/>
           <camel:directory>C://test</camel:directory>        
           <camel:consume>                 
                <camel:recursive>true</camel:recursive>
                <camel:noop>true</camel:noop>
                <camel:preMove>.processing</camel:preMove>
                <camel:filter>com.my.TestFileFilter</camel:filter>
           </camel:consume>
      </camel:binding.file>
      

       

      and i got below exceptions during deployment:

       

      Caused by: java.lang.IllegalArgumentException: Could not find a suitable setter for property: filter as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: org.apache.camel.component.file.GenericFileFilter with value com.my.TestFileFilter

          at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:347)

          at org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:367)

          at org.apache.camel.util.IntrospectionSupport.setProperties(IntrospectionSupport.java:297)

          at org.apache.camel.util.EndpointHelper.setProperties(EndpointHelper.java:249)

          at org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:222)

          at org.apache.camel.component.file.GenericFileComponent.createEndpoint(GenericFileComponent.java:65)

          at org.apache.camel.component.file.GenericFileComponent.createEndpoint(GenericFileComponent.java:36)

          at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:91)

          at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:451)

          ... 23 more

      I read the Camel document and found that the value of the filter attribuite should be the bean id of the bean defined in spring XML file (i.e.)

       

      <!-- define our sorter as a plain spring bean -->

         <bean id="myFilter" class="com.mycompany.MyFileSorter"/>

       

        <route>

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

          <to uri="bean:processInbox"/>

        </route>

      However, I didn't use spring in my project, how can I specify my filter as a bean and pass the bean id to Camel file configuration ? Thanks!