Check the size of a List/Map from Apache camel route

We can check the size of a java.util.List using below code. .choice() .when(simple(“${body.size() > 10}”)) .log(LoggingLevel.INFO, “List size is greater than 10”) .when(simple(“${body.size() > 0}”)) .log(LoggingLevel.INFO, “List size is greater than 0”) .otherwise() .log(LoggingLevel.INFO, “List is empty”) .endChoice() Same logic can be used for other collection objects in Java. Please not that you have to add Read More…

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() { @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 Read More…

How to add logger in Apache Camel routes

Yes, we can log messages from Camel route, and can define different log levels for each log message. In order to add logger, first you need to add required additional dependencies to your application. <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> Then add log4j.properties or log4j.xml to the application classpath. log4j.properties log4j.rootLogger=INFO, out log4j.appender.out=org.apache.log4j.ConsoleAppender log4j.appender.out.layout=org.apache.log4j.PatternLayout Read More…

Null check in camel routes

In camel routes, null check of body content can be done as given below: .choice() .when(body().isNull()) .log(LoggingLevel.INFO, “Body is null”) .otherwise() .log(LoggingLevel.INFO, “Body is not null”) .endChoice() If you are doing null check on a exchange header, this can be done using: .choice() .when(header(“sampleheader”).isNull()) .log(LoggingLevel.INFO, “Value of exchange header ‘sampleheader’ is null”) .otherwise() .log(LoggingLevel.INFO, “Value Read More…

Apache Camel – Message History

Message history in Apache Camel is available since camel 2.12. Message history of a message will help to trace out the list of all applications that the message passed through since its origination. When a message is sent to an endpoint, that endpoint information is stored in message history.Message history is stored as exchange property. Read More…

List of JavaDoc tags

Following are the list of JavaDoc tags available. Tag Available from Use @author 1.0 To mention author name of the class @deprecated 1.0 To notify that a given API is no longer supported and shouldn’t be used anymore @exception 1.0 To add Throws subheading to the generated documentation, wit classname & description @param 1.0 Parameter Read More…