Jsmith
Jsmith

Reputation: 360

Apache Camel URI filter in Java DSL

So maybe I'm missing something obvious, which is very possible!

However, I want to migrate a route from Spring to Java. This route is something like:

<bean id="myFilter" class="my.filter.MyFilter />
<route>
<from uri="ftp://someplace?filter=#myFilter" />
<to uri=(....) />
</route>

When converting to Java DSL I thought the following would be equivalent, but it's not. I get different behavior than I thought I would:

MyFilter m = new MyFilter();
.........
from("ftp://someplace")
.filter().method(m)
.to(....)
;

The way above seems to retrieve the files from the FTP server and then filter, one by one.

Whereas the Spring way, with the filter option in the URI, seems to filter out all the results I don't want first, then continue on its merry little way.

Is there a way to recreate the functionality of the filter as part of the URI in Java DSL?

I'm assuming I'd have to declare a bean in some fashion in order to be able to use it, but the documentation I'm finding doesn't seem to be clear on how I can achieve this.

Upvotes: 0

Views: 1467

Answers (1)

Souciance Eqdam Rashti
Souciance Eqdam Rashti

Reputation: 3191

You should be able to do something like:

from("ftp://someplace?filter=#MyFilter").to("somewhere");

But you need to add the MyFilter to the registry, or if you use blueprint, add it as a bean like:

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

Alternatively look here for how to do it in pure java: http://camel.465427.n5.nabble.com/Adding-File-name-filter-for-RouteEndpointDefinition-td4968230.html

Camel how to add something to registry - with java, in general

Upvotes: 1

Related Questions