This documentation is for WSO2 ESB version 4.5.0. View documentation for the latest release.

Sequence Template

The Sequence Template is a parametrized sequence defined in ESB. Parameters of a template are defined in the form of XPath statement/s. Callers can invoke such a template by populating parameters with static values/XPath expressions. We call such an artifact, the Call Template Mediator.

In other words, template sequence is an abstract/generic form of a ESB sequence. Only the Call Template Mediator can make a sequence template into a concrete sequence. Let's illustrate this with a simple example. Suppose, we have a sequence which logs the "hello world" in four different languages.



Configuration

<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 this actions, which will accept any greeting message(from a particular language) and log it on screen. For example, we can create the following template, which you may name "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, 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>

Note

Call template mediator/s points to the same template "HelloWorld_Logger" and passes different arguments to it. 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>

Sequence template is a top level element defined with the name attribute in ESB configuration. Both endpoint and sequence template starts with a template element. Parameters (for example, <parameter>) are the inputs supported by this sequence template. These sequence template parameters can be referred by a Xpath expression defined inside the in-line sequence. For example, parameter named "foo" can be referred by the Property Mediator (defined inside the in-line sequence of the template) in following ways:

<property name=”fooValue” expression=”$func:foo” />

or

<property name=”fooValue” expression=”get-property('foo','func')” />

Note

The scope variable used in the XPath expression. We use function scope or "?func?" to refer to template parameters. Only through this parameter name, we can refer to a particular parameter value passed externally by an invoker such as the Call Template Mediator.


Call Template Mediator

<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>

The Call Template Mediator should define a target template. It should be invoking with "target" attribute.

<with-param> element is used to parse parameter values to a target sequence template. That parameter names has to be exact match to the names specified in target template. Parameter element can contain three types of parametrized values. XPath values are passed in within curly braces (for example,{}) for value attribute. Special type of XPath expressions can be declared in double curly braces. These XPath expressions will be evaluated dynamically (others are evaluated before invoking a template or outside the template).

Note

This is currently only supported for special type 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.

WSO2 ESB allows add, edit, manage and delete sequence templates.

For more information about templates, see Templates.