This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Sequence Template
A Sequence Template is a parametrized sequence , providing an abstract or generic form of a sequence defined in the ESB. Parameters of a template are defined in the form of XPath statement/s. Callers can invoke the template by populating the parameters with static values/XPath expressions using the Call Template Mediator, which makes a sequence template into a concrete sequence.
Configuration
Let's illustrate the sequence template with a simple example. Suppose we have a sequence that logs the text "hello world" in four different languages.
<sequence> <switch source="//m0:greeting/m0:lang" xmlns:m0="http://services.samples"> <case regex="EN"> <log level="custom"> <property name=”GREETING_MESSAGE” value=”HELLO WORLD!!!!!!” /> </log> </case> <case regex="FR"> <log level="custom"> <property name=”GREETING_MESSAGE” value=”Bonjour tout le monde!!!!!!” /> </log> </case> <case regex="IT"> <log level="custom"> <property name=”GREETING_MESSAGE” value=”Ciao a tutti!!!!!!!” /> </log> </case> <case regex="JPN"> <log level="custom"> <property name=”GREETING_MESSAGE” value=”???????!!!!!!!” /> </log> </case> </switch> </sequence>
Instead of printing our "hello world" message for each and every language inside the sequence, we can create a generalized template of these actions, which will accept any greeting message (from a particular language) and log it on screen. For example, let's create the following template named "HelloWorld_Logger".
<template name="HelloWorld_Logger"> <parameter name="message"/> <sequence> <log level="custom"> <property name=”GREETING_MESSAGE” expression=”$func:message” /> </log> </sequence> </template>
With our "HelloWorld_Logger" in place, the Call Template mediator can populate this template with actual hello world messages and execute the sequence of actions defined within the template like with any other sequence. This is illustrated below.
<sequence> <switch source="//m0:greeting/m0:lang" xmlns:m0="http://services.samples"> <case regex="EN"> <call-template target="HelloWorld_Logger"> <with-param name="message" value="HELLO WORLD!!!!!!" /> </call-template> </case> <case regex="FR"> <call-template target="HelloWorld_Logger"> <with-param name="message" value="Bonjour tout le monde!!!!!!" /> </call-template> </case> <case regex="IT"> <call-template target="HelloWorld_Logger"> <with-param name="message" value="Ciao a tutti!!!!!!!" /> </call-template> </case> <case regex="JPN"> <call-template target="HelloWorld_Logger"> <with-param name="message" value="???????!!!!!!!" /> </call-template> </case> </switch> </sequence>
The Call Template mediator points to the same template "HelloWorld_Logger" and passes different arguments to it. In this way, sequence templates make it easy to stereotype different workflows inside ESB.
Syntax
<template name="string"> <!-- parameters this sequence template will be supporting --> ( <parameter name="string"/> ) * <!--this is the in-line sequence of the template --> <sequence> mediator+ </sequence> </template>
The sequence template is a top-level element defined by the name attribute in the ESB configuration. Both endpoint and sequence template starts with a template element.
The parameters available to configure the Sequence Template are as follows.
Parameter Name | Description |
---|---|
Name | The name of the Sequence Template |
onError | Select the error sequence that needs to be invoked. |
Trace Enabled | Whether or not trace is to be enabled for the sequence. |
Statistics Enabled | Whether or not statistics is to be enabled for the sequence. |
Template Parameters | The input parameter that are supported by this Sequence Template. |
Sequence template parameters can be referenced using an XPath expression defined inside the in-line sequence. For example, the parameter named "foo" can be referenced by the Property mediator (defined inside the in-line sequence of the template) in the following ways:
<property name=”fooValue” expression=”$func:foo” />
or
<property name=”fooValue” expression=”get-property('foo','func')” />
Using function scope or "?func?" in the XPath expression allows us to refer to a particular parameter value passed externally by an invoker such as the Call Template mediator.
Call Template Mediator
The Call Template mediator allows you to construct a sequence by passing values into a sequence template.
<call-template target="string"> <!-- parameter values will be passed on to a sequence template --> ( <!--passing plain static values --> <with-param name="string" value="string" /> | <!--passing xpath expressions --> <with-param name="string" value="{string}" /> | <!--passing dynamic xpath expressions where values will be compiled dynamically--> <with-param name="string" value="{{string}}" /> | ) * <!--this is the in-line sequence of the template --> </call-template>
You use the target
attribute to specify the sequence template you want to use. The <with-param>
element is used to parse parameter values to the target sequence template. The parameter names must be an exact match to the names specified in target template. The parameter value can contain a string, an XPath expression (passed in with curly braces { }), or a dynamic XPath expression (passed in with double curly braces) whose values are compiled dynamically.
This is currently only supported for special types of mediators such as the Iterator and Aggregate Mediators, where actual XPath operations are made on a different SOAP message than the message coming in to the mediator.
For more information, see the following topics: