Validating the class of Object available in camel exchange body

In camel routes, we can validate the class of object available in Camel exchange body.

It can be achieved by using below code:

CamelContext context = new DefaultCamelContext();
try {
 context.addRoutes(new RouteBuilder() {
 public void configure() throws Exception {
 .when(simple("${body} is 'java.util.List'"))
 .log(LoggingLevel.INFO, "Body contains java.util.List object")
 .when(simple("${body} is 'java.lang.String'"))
 .log(LoggingLevel.INFO, "Body contains java.lang.String object")
 .log(LoggingLevel.INFO, "Body contains objects other than java.util.List and java.lang.String")
 ProducerTemplate template = context.createProducerTemplate();
 template.sendBody("direct:validateInputObject", "Hello World");
} catch (Exception e) {
} finally {


Leave a Reply

Your email address will not be published. Required fields are marked *