Velocity component
The Velocity component uses Apache Velocity that lets you template your body. It is a Java-based template engine that provides a language to reference objects and variables defined in the current context. This means you can build your body with the headers and/or flow properties of the current flow.
Configuration
The Velocity component has the following basic configuration options:
Template
The Velocity template that should be evaluated for each message passing through the component.
Be aware that the Velocity templating languages interprets certain characters as syntax.
For instance, combinations of #
and *
symbols are considered comments or comment sections in the Velocity template language. For instance, an XML or JSON body will be truncated after #*
.
Use a Replace component before the Velocity component if you need to replace certain character (combinations).
Don't use a Velocity component to put a header with binary data back onto the body.
Using Velocity
Generic email
Below an example of a Velocity template for a generic email:
Dear ${headers.lastName}, ${headers.firstName}
Thanks for the order of ${headers.item}.
Regards Dovetail
${bodyAs(String)}
Compose an error message
Below an example to use a Velocity component to compose an error message:
{
"error": "Wrong Authorization-Token supplied!",
"supplied_headers": [
#foreach($header in $headers.entrySet())
{
"$header.key": "$header.value"
} #if( $foreach.hasNext ), #end
#end
]
}
An example of the result:
{
"error": "Wrong Authorization-Token supplied!",
"supplied_headers": [
{
"Accept": "*/*"
},
{
"Content-Type": "application/json"
},
{
"Authorization-Token": "12345"
},
{
"Cache-Control": "no-cache"
}
}