Skip to main content
Version: 4.11.0

Velocity component

The Velocity component uses Apache Velocity that lets you template your body. Apache Velocity is a Java-based template engine that provides a template language to reference object and variables defined in the current context. In this case you can template your body with the header/environment variables of the current flow.

Configuration

The Velocity component has the following configuration options:

PropertyDescription
TemplateThe Velocity template that should be evaluated for each message passing through the component.

Remarks

  • Be aware that the combination of the symbols # and * considers as the beginning of a comment section in the Velocity template language. a XML or JSON body will be truncated after #*. To prevent this use a replace component located before the velocity component.

Examples

This is 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)}

You can also use this to compose error messages to return.

{
"error": "Wrong Authorization-Token supplied!",
"supplied_headers": [
#foreach($header in $headers.entrySet())
{
"$header.key": "$header.value"
} #if( $foreach.hasNext ), #end
#end
]
}

The response would be generated like this:

{
"error": "Wrong Authorization-Token supplied!",
"supplied_headers": [
{
"Accept": "*/*"
},
{
"Content-Type": "application/json"
},
{
"Authorization-Token": "12345"
},
{
"Cache-Control": "no-cache"
}
}