Using Simple expressions
Simple expression are supported by the following components:
- Set Header
- Set Headers
- Filter
- Content Router
- Split
Frequently used headers
Occurrence | Header name | Expression (example) |
---|---|---|
Sets full message body to a header of your choice | [Random] | ${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 | [Random] | ${header.HeaderName.replaceAll("A","B")} |
Adds a random number to the value of an existing header | [Random] | ${header.CamelFileName}_${random(100)} |
Adds a Europe/Amsterdam DateTimeNow to a header | [Random] | ${date-with-timezone:now:Europe/Amsterdam:yyyy-MM-dd HH:mm:ss} |
Determines the length of the message body | [Random] | ${bodyAs(String).length} |
Trims the value to remove leading and trailing whitespaces and line breaks | [Random] | ${header.HeaderName.trim()} |
Gets the error message of the exchange | [Random] | ${exchangeProperty.CamelExceptionCaught.getMessage()} |
Frequently used content filters
Occurrence | Expression (example) |
---|---|
Allows messages to pass through if the header contains a specific character range | ${header.HeaderName} contains "A" |
Allows messages to pass through if the header contains the same specific character range as an other header has | '${header.Authorization}' == '#{InboundAuthorizationCode}' |
Allows messages to pass through if the length of the consumed file is larger than 0 kB | ${header.CamelFileLength} > 0 |
Allows 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 | ${bodyAs(String)} not contains '"data":"UPDATE"' && ${bodyAs(String)} not contains '"data":"INSERT"' |
Allows messages to pass through if a message header is empty. | ${header.abc} == "" |
Allows messages to pass through if a message header is not empty. | ${header.abc} != "" |
Allows 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 |
&& | The logical AND operator is used to group two expressions |
|| | The logical OR operator is used to group two expressions |
Share
Useful and original tips and tricks are always welcome. Inform us to share it with other users by using the form!