apache-camelapache-camel-cdi

camel-file component filter with cdi


I'm using camel without the Spring framework (using CDI instead). How can I set a filter for the camel-file component?

My filter class looks like this:

@Named
@Stateless
public class MyFilter<T> implements GenericFileFilter<T> {
   System.out.println("MyFilter was triggered");
  .......

So I tried this:

<route>
   <from uri="file://somewhere?filter=#myFilter"/>
   <to uri="...."/>
 </route>

But I'm getting:

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 #myFilter

What am I missing?

Update:

Please note that the bean is registered. If I use:

<to uri="ejb:java:global/Abc/MyFilter?method=accept"/>

then MyFilter was triggered is showing up in the log.

So the problem is about configuring the file component filter.


Solution

  • Update: Since Camel-cdi uses JNDI-registry, the filter is configured like this:

    filter=#java:global/Abc/MyFilter
    

    Since I do not use Spring and the filter parameter is awaiting an instance and not only a classname, a TypeConverter is necessary

    @Converter
    public class MyGenericFileFilterConverter implements TypeConverters {
    
       @Converter
       public static GenericFileFilter toMYFilter(String filter){
          return new MyFilter();
       }
    }