sinclair
sinclair

Reputation: 2861

Camel File component - skip file

I'm using the camel file component to poll files from a directory. Before I can handle a file some conditions have to be satisfied, if not camel should skip the file without deleting/moving it and go to the next one.

To do this I use this:

public InputStream myMethod(@Body InputStream is, @Headers .....) {

if( !checkPrerequisites )
    throw new MyRuntimeException("conditions not satisfied yet");

So I'm wondering if there is another way to archive the desired behaviour.

Upvotes: 1

Views: 2043

Answers (1)

AndyN
AndyN

Reputation: 2105

You could implement a GenericFileFilter. Create the filter, like so:

public class AnotherFileExistsFilter<T> implements GenericFileFilter<T> {

    @Override
    public boolean accept(GenericFile<T> firstFile) {
        return Files.exists(Paths.get("/some/other/folder/" + firstFile.getFileName()));
    }
}

Add it to your endpoint using filter=#anotherFileExistsBeanName.

If you want to keep checking the file, set idempotent=false, and I recommend setting a delay (delay=xxx in ms) in order to not poll the folder continuously.

More details are on the Apache Camel File2 page.

Upvotes: 4

Related Questions