Using Simple expressions
The Simple Expression Language is primarily intended for evaluating expressions or predicates. It also supports the File Expression Language. It only returns plain text, no xml.
Simple expressions are supported by the Set Header, Set Headers, Filter, Content Router and Split components.
Simple expressions are also used to set or calculate with date and time. Please refer to our extensive reference Using time in Dovetail for more details.
Frequently used headers
These expressions are often used with the Set Header or Set Headers components.
Occurrence | Header name | Expression (example) |
---|---|---|
Sets full message body to a header of your choice | [Any] | ${bodyAs(String)} |
Adds an attachment to email | Content-Disposition | attachment;filename=text.csv |
Specifies the content type of an xml message | Content-Type | text/xml |
Specifies the content type of a json message | Content-Type | text/json or application/json |
Specifies the content type of a well formed e-mail in HTML format | Content-Type | text/html |
Specifies the content type of an e-mail in plain text format | Content-Type | text/plain |
Specifies the filename with a timestamp of the message export | CamelFileName | products_${date:now:yyyyMMdd_HHmmssSS}.xml |
Specifies the filename without the original extension of the message export | CamelFileName | john_${file:onlyname.noext}.jpg |
Replaces a character range in a value of a header with another range | [Any] | ${header.HeaderName.replaceAll('A','B')} |
Adds a random number to the value of an existing header | [Any] | ${header.CamelFileName}_${random(100)} |
Determines the length of the message body | [Any] | ${bodyAs(String).length} |
Trims the value to remove leading and trailing whitespaces and line breaks | [Any] | ${header.HeaderName.trim()} |
Gets the error message of the exchange | [Any] | ${exchangeProperty.CamelExceptionCaught.getMessage()} |
Add one to a header value if it's a number (i.e. 2 becomes 3) | [Any] | ${header.CamelSplitIndex}++ |
Substract one from a header value if it's a number (i.e. 2 becomes 1) | [Any] | ${header.CamelSplitIndex}-- |
Frequently used content filters
These expressions are often used in combination with the Filter and Content Router components.
Occurrence | Expression (example) |
---|---|
Allow messages to pass through if the header contains a specific character range | ${header.HeaderName} contains 'A' |
Allow messages to pass through if the header contains the same specific character range as a flow property | '${header.Authorization}' == '#{InboundAuthorizationCode}' |
Allow messages to pass through if the length of the consumed file is larger than 0 kB | ${header.CamelFileLength} > 0 |
Allow messages to pass through if one header doesn't contain a specific character range and simultaneously another header doesn't contain a specific character range too | ${header.abc} not contains 'this' && ${header.def} not contains 'that' |
Allow messages to pass through if the body contains a specific character range or another specific character range | ${bodyAs(String)} contains 'this' || ${bodyAs(String)} contains 'that' |
Allow messages to pass through if a message header doesn't exist. | ${header.abc} == null |
Allow messages to pass through if a message header has a specific value. | ${header.abc} == 'this' |
Allow messages to pass through if a message header is empty. | ${header.abc} == '' |
Allow messages to pass through if a message header is not empty. | ${header.abc} != '' |
Allow messages to pass through if the body length is larger than 2 characters | ${bodyAs(String).length} > 2 |
Operator support
Things to keep in mind
- To refer a header in the simple expression language use the notation as follows:
${header.headername}
- Enclose a literal string in
' '
- There must be spaces around the operator
- Syntax:
${header} [operator] 'value'
- Dovetail will automatically type convert the value type to the header type, so it is possible to for example, convert a string into a numeric so you can use
>
comparison for numeric values - Keep in mind that simple headers are not case sensitive. When a header variable named
errormessage
is set at an earlier stage, a header variable set toERRORMESSAGE
will update the previously set header variableerrormessage
and will not create a new header variable.
Frequently used operators
Operator | Description |
---|---|
== | Equals |
> | Greater than |
>= | Greater than or equals |
< | Less than |
<= | Less than or equals |
!= | Not equals |
contains | For testing if contains in a string based value |
not contains | For testing if not contains in a string based value |
regex | For matching against a given regular expression pattern defined as a String value |
not regex | For not matching against a given regular expression pattern defined as a String value |
starts with | For testing if the left hand side string starts with the right hand string |
ends with | For testing if the left hand side string ends with the right hand string |
&& | The logical AND operator is used to group two expressions |
|| | The logical OR operator is used to group two expressions |
Refer to Simple - Operator support for a full list of supported operators.
Share
Useful and original tips and tricks are always welcome. Let us know and we'll add them to this reference!