Search code examples
javaapache-cameljmsactivemq-classicjms-serializer

How to search for a String inside a textfile Using Apache Camel


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).

Solution

  • 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 */);