Go to new doc!

+49 228 5552576-0




Renders the body content of a message from a template. The template can produce plain text, Json or XML. Variables in the template are substituted with values from the body, header, query parameters, etc. If the extension of a referenced template file is .xml it will use XMLTemplateEngine otherwise StreamingTemplateEngine . Have a look at the samples in examples/template .

Can be used in

spring:beans, api, bean, if, interceptor, internalProxy, proxy, registration, request, response, serviceProxy, soapProxy, stompProxy, swaggerProxy, transport and wsStompReassembler


Text Template

Call it with a query parameter name:


<api port="2000">
		<template contentType="text/plain">Hello ${params.name}!</template>
	<return statusCode="200"/>
JSON Template

Call it with the answer.


<api name="JSON" port="2000" method="GET">
		<template contentType="application/json" pretty="yes">
				"answer": ${params.answer},
				"foo": 7
	<return statusCode="200"/>
XML Template

Send a POST with an XML body content to the api.

<api port="2000">
		<template location="template.xml"/>
	<return statusCode="200"/>

If the filename of the template ends with .xml you can use the elements from the gsp namespace. See GroovyXMLTemplate Engine

<destinations xmlns:gsp='http://groovy.codehaus.org/2005/gsp'>

	<gsp:scriptlet>def answer = 42;</gsp:scriptlet>

		import groovy.xml.XmlSlurper
		def xml = new XmlSlurper().parseText(body)

	<gsp:scriptlet>xml.children().each { </gsp:scriptlet>
	<gsp:scriptlet> } </gsp:scriptlet>



Name Required Default Description Example
contentType false - content type for body application/json
location false - path of xml template file. template.xml
pretty false no Format JSON documents. yes


The following variables can be accessed within a template.

Name Class Description
exc com.predic8.membrane.core.exchange.Exchange The Exchange class provides, among others, access to the Request, Response and their corresponding Headers.
message com.predic8.membrane.core.http.Message Message is the superclass of a request or a response. Depending on the flow the message contains data from the request or the response.
header com.predic8.membrane.core.http.Header The header object allows access to the HTTP header fields. You can remove, add and change fields.
body com.predic8.membrane.core.http.Body The body of the message.
json java.util.Map If the message contains a body of the type application/json this varible will contain the JSON as a Map. Use it only to read the JSON document.
flow com.predic8.membrane.core.interceptor.Flow REQUEST or RESPONSE
properties java.util.Map The properties of the exchange object.
spring org.springframework.context.ApplicationContext The Spring application context hosting the router instance (or null, if the router is not hosted by Spring).