Reputation: 7
I am new to Apache camel. Does anyone know how to use camel to process the content of a text file to check if a particular string e.g "error" is present within a text file. I cant seem to go past the first line below with java. Any help will be appreciated
from("file://inputdir/").convertBodyTo(String.class).
Upvotes: 0
Views: 989
Reputation: 1
You can use ${bodyAs(String)} as follows:
<route id="_route1">
<from id="_from1" uri="file:work/cbr/input"/>
<when id="_when1">
<simple>${bodyAs(String)} contains 'ABC'</simple>
<log id="_log1" message="contains string ABC"/>
<to id="_to1" uri="file:work/cbr/output"/>
</when>
</route>
Upvotes: 0
Reputation: 19517
Use bodyAs
and contains
. For example:
from("file://inputdir/")
.choice()
.when(bodyAs(String.class).contains("error"))
.to(/* a route for errors */)
.otherwise()
.to(/* a route for non-errors */);
Upvotes: 1