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…

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…

How to resolve maven dependency conflicts

When dealing with lots of maven dependencies we normally ends up with conflicts. This can be due to different versions of same library in classpath. In this case we have to manually identify the exact maven dependencies with which this library is added. Maven provides an option to list all the libraries added to classpath due Read More…

Abbreviations used in Java world

AFC – Application Foundation Classes AJAX – Asynchronous JavaScript and XML ANT – Another Neat Tool AWT – Abstract Window Toolkit CMP – Container Managed Persistence CMT – Container Managed Transaction EJB – Enterprise Java Beans GWT – Google Web Toolkit IDE – Integrated Development Environment JAR – Java Archive JAX – Java API for Read More…