0

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.

Jsmith
  • 350
  • 1
  • 4
  • 19

1 Answers1

1

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

Community
  • 1
  • 1
Souciance Eqdam Rashti
  • 3,143
  • 3
  • 15
  • 31
  • Hmm maybe I wasn't clear, sorry. But what I mean is I have a specially made filter class for the route (it is filtering based on timestamps of the files, plus a little extra), and I wanted to reference that class as the one to use for filtering in the URI – Jsmith Dec 05 '16 at 20:26
  • So maybe I did this wrong, but this is the issue I keep having happen. I do `from("ftp://x?filter=#myFilter")` but always end up with the error of something along the lines of `Cannot convert String to required type of GenericFileFilter with value #myFilter`. What is all that about? – Jsmith Dec 06 '16 at 12:45
  • This is how I refer to a parameter for netty.. serverInitializerFactory=#spf. I think the error you are getting has to do with adding the parameter to the registry. See the second link in my answer for how to acheive that using the java dsl. – Souciance Eqdam Rashti Dec 06 '16 at 12:52
  • That is an.. interesting way to deal with this. Why is it such a pain to add something to the registry in Java DSL? :( The 2nd link worked however! Thanks a bunch! – Jsmith Dec 06 '16 at 13:03
  • I think it has to do with the fact that I am using the java dsl and blueprint together. Then I would need to do as seen in that link. If you use a pure java approach it can be done in a simpler fashion. See Claus's answer for how to do that here http://stackoverflow.com/questions/19357395/how-to-create-datasource-using-camel – Souciance Eqdam Rashti Dec 06 '16 at 13:26