IAmYourFaja
IAmYourFaja

Reputation: 56912

Apache Camel File Component: Specifying 1 file in regex

I have the following Camel route (Spring XML);

<route id="myroute">
    <from uri="file:///home/myuser/someDir?include=toprocess_*.txt" />

    <to uri="bean:fileProcessor?method=process" />
</route>

And on my machine's file system:

/home/user/someDir/
    toprocess_1.txt
    toprocess_2.txt
    toprocess_3.txt
    ...
    toprocess_13904.txt

How do I change the include option (or the uri in general) so that only the first file (regardless of its name) matching the regex gets added to the route, and subsequently, routed on to the fileProcessor bean?

Please note that in my example, the first file will most likely be toprocess_1.txt. However I could have a file system like so:

/home/user/someDir/
    toprocess_red.txt
    toprocess_blue.txt
    toprocess_green.txt
    ...
    toprocess_black.txt

So it's not as simple as just making the URI:

<from uri="file:///home/myuser/someDir?include=toprocess_1.txt" />

I'm expecting something like:

<from uri="file:///home/myuser/someDir?include=toprocess_*.txt&maxFiles=1" />

But in the Camel docs, I see no such option, or anything similar to it.

Upvotes: 1

Views: 3389

Answers (2)

Claus Ibsen
Claus Ibsen

Reputation: 55545

The include options is using regular expression as documented

So you need to use a regular expression to match the wildcards, eg *. should be flipped

?include=toprocess_.*txt"

Its just a standard java regular expressions so you can find plenty of information about these on the internet, and in the javadoc of the JDK itself.

Upvotes: 3

hveiga
hveiga

Reputation: 6925

I believe you could do it this way:

<route id="myroute">
    <from uri="timer:foo?repeatCount=1" />
    <pollEnrich uri="file:///home/myuser/someDir?include=toprocess_*.txt" />
    <to uri="bean:fileProcessor?method=process" />
</route>

Upvotes: 3

Related Questions