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

Share the knowledge

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

Share the knowledge

Null check in camel routes

Posted on January 5, 2016September 25, 2021 By sastrija

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 of exchange header 'sampleheader' is not null")
.endChoice()

Similarly you can do null check on exchange property using:

.choice()
  .when(exchangeProperty("sampleproperty").isNull())
    .log(LoggingLevel.INFO, "Value of exchange property 'sampleproperty' is null")
  .otherwise()
    .log(LoggingLevel.INFO, "Value of exchange property 'sampleproperty' is not null")
.endChoice()

We can use .isNotNull() to negate the above .isNull() check.

Related

Uncategorized

Post navigation

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