Checking for empty strings in a camel route

Solution Verified - Updated -

Environment

Camel 2.8

Issue

How to check for empty strings in a camel route using Camel's Simple Expression Language

Resolution

The following example shows a regular expression that identifies an empty string (a string that only contains ONLY white spaces) using Camel's Simple Expression Language. In this example, the empty string check is used within the "choice" Enterprise Integration Pattern


... <choice> <when> <simple>${header.STORE_NUMBER} regex '^\s*$'</simple> <to uri="activemq:queue:EMPTY_STRING"/> </when> ....

From Fuse Enterprise 7.0.1 onwards the following is possible:


... <simple>${header.STORE_NUMBER.toString().trim()} == ''</simple> ...

If the header is already of type String, the toString() method can be omitted:

...
<simple>${header.STORE_NUMBER.trim()} == ''</simple>
...

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.