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() { @Override public void configure() throws Exception { from("direct:validateInputObject") .choice() .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") .otherwise() .log(LoggingLevel.INFO, "Body contains objects other than java.util.List and java.lang.String") .endChoice() .end(); } }); ProducerTemplate template = context.createProducerTemplate(); context.start(); template.sendBody("direct:validateInputObject", "Hello World"); } catch (Exception e) { e.printStackTrace(); } finally { context.stop(); }