How to implement GenericFileProcessStrategy in Talend route?

How to implement GenericFileProcessStrategy in Talend route?

Hello all of you,
In one of my Talend Route, I have to wait for certain criterias (such as the number, names and types of files) before starting consuming all the files stored in my directory.
I saw it was possible to customize the file process strategy in Camel File Component (Cf. "processStrategy" option), what is, I assume, exactly what I should do to achieve my goal.
The only problem is I don't know how to implement this class (in the beans?), and how to declare it and use it in my route. I've tried to search the documentation and the web for some examples or tutos, but didn't find. Has anyone done this before, or know where I could find some help?
Thanks in advance!

Re: How to implement GenericFileProcessStrategy in Talend route?

Yes, you can provide the class in beans, for example, if you don't want to process the file if it names as a.txt, you can create a Bean in Beans like below:
public class CustomFileProcessStrategy extends GenericFileProcessStrategySupport<File>{
public boolean begin(GenericFileOperations<File> operations,
GenericFileEndpoint<File> endpoint, Exchange exchange,
GenericFile<File> file) throws Exception {
boolean begin = super.begin(operations, endpoint, exchange, file);
return false;
File realFile = file.getFile();
if(realFile == null || !realFile.exists()){
return false;
return false;
return true;


Then according to you studio version:
Before V5.3, you can do it as below:
1. Create a cBeanRegister component, specify the id as fileStrategy, specify the Class Name as beans.CustomFileProcessStrategy
2. On cFile component, specify the Path on Basic settings, and specify the processStrategy with value #fileStrategy on Advanced settings
That's it.
On V5.3, you can replace cBeanRegister by using spring configuration, add below bean definition into Spring configuration:
<bean class="beans.CustomFileProcessStrategy" id="fileStrategy" />

That's it.

Re: How to implement GenericFileProcessStrategy in Talend route?

Thanks for your help, Gliu. It works perfectly!!! So, now, I can do almost everything Smiley Wink
To complete Gliu's answer, here is the list of imports you have to add in the class to get it work properly:
import org.apache.camel.Exchange;
import org.apache.camel.component.file.GenericFile;
import org.apache.camel.component.file.GenericFileEndpoint;
import org.apache.camel.component.file.GenericFileOperations;
import org.apache.camel.component.file.strategy.GenericFileProcessStrategySupport;
One Star

Re: How to implement GenericFileProcessStrategy in Talend route?

When trying with 'Customized' java code in cbeanRegister component, getting "beans.FtpFileFilter cannot be resolved" error .Below is My 'Customized' java code :
"beanInstance = new beans.FtpFileFilter(context.filecontains);"
Could you please help me on this issue ?
How to use the Customized java code to create beanInstance in cbeanRegister component?

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.



Introduction to Talend Open Studio for Data Integration.


Downloads and Trials

Test drive Talend's enterprise products.