Skip to content
𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ

Share the knowledge

𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ

Share the knowledge

Validating the class of Object available in camel exchange body

Posted on February 22, 2017September 20, 2021 By sastrija

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();
}

 

Related

Uncategorized

Post navigation

Previous post
Next post
©2026 𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ | WordPress Theme by SuperbThemes