<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  ~  Copyright (c) 2009, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
  ~
  ~  WSO2 Inc. licenses this file to you under the Apache License,
  ~  Version 2.0 (the "License"); you may not use this file except
  ~  in compliance with the License.
  ~  You may obtain a copy of the License at
  ~
  ~    http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  -->

<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta content="text/html; charset=iso-8859-1" http-equiv="content-type"/>
  <title>WSO2 ESB - Message Mediation Samples </title>
</head>

<body>
<h1>Running the Message Mediation samples with WSO2 Enterprise Service Bus (ESB)</h1>
<h2><a name="Sample0">Sample 0: Introduction to ESB</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;!-- log all attributes of messages passing through --&gt;
    &lt;log level="full"/&gt;

    &lt;!-- Send the messageto implicit destination --&gt;
    &lt;send/&gt;
&lt;/definitions&gt;</pre>

<p><strong>Objective: Introduction to ESB. Shows how a message could be made
to pass through ESB and logged before it is delivered to its
ultimate receiver.</strong> </p>

<p>The Stock quote client can operate in the following modes for this example. </p>
<ul>
  <li>Smart Client mode </li>
</ul>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ </pre>
<ul>
  <li>Using ESB as a HTTP Proxy </li>
</ul>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dprxurl=http://localhost:8280/</pre>
<ul>
  <li>Gateway Mode / Dumb Client </li>
</ul>
<p>See sample # 1 <br/></p>

<p><strong>Prerequisites:</strong>
<br />Start the Synapse configuration numbered 0: e.g. wso2esb-samples -sn 0
<br />Start the Axis2 server and deploy the SimpleStockQuoteService if not already
deployed <br/></p>

<p><strong>Execute the Smart Client </strong></p>

<p>By tracing the execution of ESB with the log output level set to DEBUG,
you will see the client request arriving at ESB with a WS-Addressing 'To' set
to EPR http://localhost:9000/services/SimpleStockQuoteService. The ESB engine
logs the message at the "full" log level (i.e. all the message headers and
the body) then sends the message to its implicit 'To' address which is
http://localhost:9000/services/SimpleStockQuoteService. You will see a message in
the Axis2 server console confirming that the message got routed to the sample
server and the sample service hosted at the sample server generating a stock
quote for the requested symbol. </p>
<pre xml:space="preserve">Sat Nov 18 21:01:23 IST 2006 SimpleStockQuoteService :: Generating quote for : IBM</pre>

<p>The response message generated by the service is again received by ESB,
and flows through the same mediation rules, which logs the response message
and then sends it back. This time to the client. On the client console you
should see an output similar to the following based on the message received
by the client. </p>
<pre xml:space="preserve">Standard :: Stock price = $95.26454380258552</pre>

<p><strong>Execute the Proxy Client </strong> </p>

<p>You will see the exact same behaviour as per the previous example when you
run this scenario. However this time the difference is at the client, as it
sends the message to the WS-Addressing 'To' address
http://localhost:9000/services/SimpleStockQuoteService, but the transport
specifies ESB as the http proxy. </p>

<h2><a name="Sample1">Sample 1: Simple content based routing (CBR) of messages</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;!-- filtering of messages with XPath and regex matches --&gt;
    &lt;filter source="get-property('To')" regex=".*/StockQuote.*"&gt;
        &lt;send&gt;
            &lt;endpoint&gt;
                &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
            &lt;/endpoint&gt;
        &lt;/send&gt;
        &lt;drop/&gt;
    &lt;/filter&gt;
    &lt;send/&gt;
&lt;/definitions&gt; </pre>

<p><strong>Objective: Introduction to simple content based routing. Shows how
a message could be made to pass through ESB using the Dumb Client mode, where
ESB acts as a gateway to accept all messages and then perform mediation and
routing based on message properties or content.</strong> </p>

<p><strong>Prerequisites:</strong><br/>
Start the Synapse configuration numbered 1: i.e. wso2esb-samples -sn 1<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
deployed<br />
</p>

<p>Execute the Dumb Client as: </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuote<br /></pre>

<p>This time you will see ESB receiving a message for which ESB was set as
the ultimate receiver of the message. Based on the 'To' EPR of
http://localhost:8280/services/StockQuote, ESB performs a match to the path
'/StockQuote' and as the request matches the XPath expression of the filter
mediator, the filter mediator's child mediators execute. This sends the
message to a different endpoint as specified by the endpoint definition. The
'drop' mediator terminates further processing of the current message in a
configuration. During response processing, the filter condition fails, and
thus the implicit 'send' mediator forwards the response back to the client.
</p>

<h2><a name="Sample2">Sample 2: CBR with the Switch-case mediator, using
message properties</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;switch source="//m0:getQuote/m0:request/m0:symbol" xmlns:m0="http://services.samples"&gt;
        &lt;case regex="IBM"&gt;
            &lt;!-- the property mediator sets a local property on the *current* message --&gt;
            &lt;property name="symbol" value="Great stock - IBM"/&gt;
        &lt;/case&gt;
        &lt;case regex="MSFT"&gt;
            &lt;property name="symbol" value="Are you sure? - MSFT"/&gt;
        &lt;/case&gt;
        &lt;default&gt;
            &lt;!-- it is possible to assign the result of an XPath expression as well --&gt;
            &lt;property name="symbol"
                  expression="fn:concat('Normal Stock - ', //m0:getQuote/m0:request/m0:symbol)"
                  xmlns:m0="http://services.samples"/&gt;
        &lt;/default&gt;
    &lt;/switch&gt;

    &lt;log level="custom"&gt;
        &lt;!-- the get-property() XPath extension function allows the lookup of local message properties
            as well as properties from the Axis2 or Transport contexts (i.e. transport headers) --&gt;
        &lt;property name="symbol" expression="get-property('symbol')"/&gt;
        &lt;!-- the get-property() function supports the implicit message headers To/From/Action/FaultTo/ReplyTo --&gt;
        &lt;property name="epr" expression="get-property('To')"/&gt;
    &lt;/log&gt;

    &lt;!-- Send the messages where they are destined to (i.e. the 'To' EPR of the message) --&gt;
    &lt;send/&gt;
&lt;/definitions&gt;</pre>

<p><strong>Objective: Introduce switch-case mediator and writing and reading
of local properties set on a message instance</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Synapse configuration numbered 2: i.e. wso2esb-samples -sn 2<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
done. </p>

<p>Execute the 'ant stockquote ..' request again in the smart client mode,
specifying 'IBM', 'MSFT' and 'SUN' as the stock symbols. When the symbol IBM
is requested, viewing the mediation logs you will see that the case
statements' first case for 'IBM' is executed and a local property named
'symbol' was set to 'Great stock - IBM'. Subsequently this local property
value is looked up by the log mediator and logged using the 'get-property()'
XPath extension function. </p>

<p>ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService
-Dtrpurl=http://localhost:8280/ -Dsymbol=IBM </p>
<pre xml:space="preserve">INFO LogMediator - symbol = Great stock - IBM, epr = http://localhost:9000/axis2/services/SimpleStockQuoteService </pre>

<p>ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService
-Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT </p>
<pre xml:space="preserve">INFO LogMediator - symbol = Are you sure? - MSFT, epr = http://localhost:9000/axis2/services/SimpleStockQuoteService</pre>

<h2><a name="Sample3">Sample 3: Local Registry entry definitions, reusable
endpoints and sequences</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;!-- define a string resource entry to the local registry --&gt;
    &lt;localEntry key="version"&gt;0.1&lt;/localEntry&gt;
    &lt;!-- define a reuseable endpoint definition --&gt;
    &lt;endpoint name="simple"&gt;
        &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
    &lt;/endpoint&gt;

    &lt;!-- define a reusable sequence --&gt;
    &lt;sequence name="stockquote"&gt;
        &lt;!-- log the message using the custom log level. illustrates custom properties for log --&gt;
        &lt;log level="custom"&gt;
            &lt;property name="Text" value="Sending quote request"/&gt;
            &lt;property name="version" expression="get-property('version')"/&gt;
            &lt;property name="direction" expression="get-property('direction')"/&gt;
        &lt;/log&gt;
        &lt;!-- send message to real endpoint referenced by key "simple" endpoint definition --&gt;
        &lt;send&gt;
            &lt;endpoint key="simple"/&gt;
        &lt;/send&gt;
    &lt;/sequence&gt;

    &lt;sequence name="main"&gt;
        &lt;in&gt;
            &lt;property name="direction" value="incoming"/&gt;
            &lt;sequence key="stockquote"/&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;</pre>

<p><strong>Objective: Illustrates local registry entry definitions, reusable
endpoints and sequences</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Synapse configuration numbered 3: i.e. wso2esb-samples -sn 3<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
done </p>

<p>This example uses a sequence named as "main" that specifies the main
mediation rules to be executed. This is equivalent to directly specifying the
mediators of the main sequence within the &lt;definitions&gt; tags. This is
the recommended and also a better approach for non-trivial configurations.
Execute the 'ant stockquote ..' request again, and following through the
mediation logs you will now notice that the sequence named "main" is
executed. Then for the incoming message flow the &lt;in&gt; mediator
executes, and it calls the sequence named "stockquote". </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</pre>
<pre xml:space="preserve">DEBUG SequenceMediator - Sequence mediator &lt;main&gt; :: mediate()<br />DEBUG InMediator - In mediator mediate()<br />DEBUG SequenceMediator - Sequence mediator &lt;stockquote&gt; :: mediate()</pre>

<p>As the "stockquote" sequence executes, the log mediator dumps a simple
text/string property, result of an XPath evaluation, that picks up the key
named "version", and a second result of an XPath evaluation that picks up a
local message property set previously by the &lt;property&gt; mediator. The
get-property() XPath extension function is able to read message properties
local to the current message, local or remote registry entries, Axis2 message
context properties as well as transport headers. The local entry definition
for "version" defines a simple text/string registry entry for that which is
visible to all messages that pass through ESB. </p>
<pre xml:space="preserve">[HttpServerWorker-1] INFO  LogMediator - Text = Sending quote request, version = 0.1, direction = incoming
[HttpServerWorker-1] DEBUG SendMediator - Send mediator :: mediate()
[HttpServerWorker-1] DEBUG AddressEndpoint - Sending To: http://localhost:9000/services/SimpleStockQuoteService </pre>

<h2><a name="Sample4">Sample 4: Introduction to error handling</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;!-- the default fault handling sequence used by Synapse - named 'fault' --&gt;
    &lt;sequence name="fault"&gt;
        &lt;log level="custom"&gt;
            &lt;property name="text" value="An unexpected error occured"/&gt;
            &lt;property name="message" expression="get-property('ERROR_MESSAGE')"/&gt;
        &lt;/log&gt;
        &lt;drop/&gt;
    &lt;/sequence&gt;

    &lt;sequence name="sunErrorHandler"&gt;
        &lt;log level="custom"&gt;
            &lt;property name="text" value="An unexpected error occured for stock SUN"/&gt;
            &lt;property name="message" expression="get-property('ERROR_MESSAGE')"/&gt;
        &lt;/log&gt;
        &lt;drop/&gt;
    &lt;/sequence&gt;

    &lt;!-- default message handling sequence used by Synapse - named 'main' --&gt;
    &lt;sequence name="main"&gt;
        &lt;in&gt;
            &lt;switch source="//m0:getQuote/m0:request/m0:symbol" xmlns:m0="http://services.samples"&gt;
                &lt;case regex="IBM"&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;&lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;&lt;/endpoint&gt;
                    &lt;/send&gt;
                &lt;/case&gt;
                &lt;case regex="MSFT"&gt;
                    &lt;send&gt;
                        &lt;endpoint key="bogus"/&gt;
                    &lt;/send&gt;
                &lt;/case&gt;
                &lt;case regex="SUN"&gt;
                    &lt;sequence key="sunSequence"/&gt;
                &lt;/case&gt;
            &lt;/switch&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

    &lt;sequence name="sunSequence" onError="sunErrorHandler"&gt;
        &lt;send&gt;
            &lt;endpoint key="sunPort"/&gt;
        &lt;/send&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt; </pre>

<p><strong>Objective: Introduction to error handling with the 'fault'
sequence</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Synapse configuration numbered 4: i.e. wso2esb-samples -sn 4<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
done </p>

<p>When the IBM stock quote is requested, the configuration routes it to the
defined inline endpoint, which routes the message to the
SimpleStockQuoteService on the local Axis2 instance. Hence a valid response
message is shown at the client. </p>

<p>If you lookup a stock quote for 'MSFT', ESB is instructed to route the
message to the endpoint defined as the 'bogus' endpoint, which does not
exist. ESB executes the specified error handler sequence closest to the point
where the error was encountered. In this case, the currently executing
sequence is 'main' and it does not specify an 'onError' attribute. Whenever
ESB cannot find an error handler, it looks for a sequence named 'fault'. Thus
the 'fault' sequence can be seen executing, and writing the generic error
message to the logs. </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT</pre>
<pre xml:space="preserve">[HttpServerWorker-1] DEBUG SendMediator - Send mediator :: mediate()
[HttpServerWorker-1] ERROR IndirectEndpoint - Reference to non-existent endpoint for key : bogus
[HttpServerWorker-1] DEBUG MediatorFaultHandler - MediatorFaultHandler :: handleFault
[HttpServerWorker-1] DEBUG SequenceMediator - Sequence mediator &lt;fault&gt; :: mediate()
[HttpServerWorker-1] DEBUG LogMediator - Log mediator :: mediate()
[HttpServerWorker-1] INFO  LogMediator - text = An unexpected error occured, message = Reference to non-existent endpoint for key : bogus</pre>

<p>When the 'SUN' quote is requested, a custom sequence 'sunSequence' is
invoked, and it specifies 'sunErrorHandler' as its error handler. Hence when
the send fails, you could see the proper error handler invocation and the
custom error message printed as follows. </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN</pre>
<pre xml:space="preserve">[HttpServerWorker-1] DEBUG SequenceMediator - Sequence mediator &lt;sunSequence&gt; :: mediate()
[HttpServerWorker-1] DEBUG SequenceMediator - Setting the onError handler for the sequence
[HttpServerWorker-1] DEBUG AbstractListMediator - Implicit Sequence &lt;SequenceMediator&gt; :: mediate()
[HttpServerWorker-1] DEBUG SendMediator - Send mediator :: mediate()
[HttpServerWorker-1] ERROR IndirectEndpoint - Reference to non-existent endpoint for key : sunPort
[HttpServerWorker-1] DEBUG MediatorFaultHandler - MediatorFaultHandler :: handleFault
[HttpServerWorker-1] DEBUG SequenceMediator - Sequence mediator &lt;sunErrorHandler&gt; :: mediate()
[HttpServerWorker-1] DEBUG AbstractListMediator - Implicit Sequence &lt;SequenceMediator&gt; :: mediate()
[HttpServerWorker-1] DEBUG LogMediator - Log mediator :: mediate()
[HttpServerWorker-1] INFO  LogMediator - text = An unexpected error occured for stock SUN, message = Reference to non-existent endpoint for key : sunPort</pre>

<h2><a name="Sample5">Sample 5: Creating SOAP fault messages and changing the
direction of a message</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;sequence name="myFaultHandler"&gt;
        &lt;makefault&gt;
            &lt;code value="tns:Receiver" xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/&gt;
            &lt;reason expression="get-property('ERROR_MESSAGE')"/&gt;
        &lt;/makefault&gt;

        &lt;send/&gt;
    &lt;/sequence&gt;

    &lt;sequence name="main" onError="myFaultHandler"&gt;
        &lt;in&gt;
            &lt;switch source="//m0:getQuote/m0:request/m0:symbol"
                    xmlns:m0="http://services.samples"&gt;
                &lt;case regex="MSFT"&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;&lt;address uri="http://bogus:9000/services/NonExistentStockQuoteService"/&gt;&lt;/endpoint&gt;
                    &lt;/send&gt;
                &lt;/case&gt;
                &lt;case regex="SUN"&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;&lt;address uri="http://localhost:9009/services/NonExistentStockQuoteService"/&gt;&lt;/endpoint&gt;
                    &lt;/send&gt;
                &lt;/case&gt;
            &lt;/switch&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</pre>

<p><strong>Objective: Makefault mediator and sending back error responses
</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Synapse configuration numbered 5: i.e. wso2esb-samples -sn 5<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
done </p>

<p>When the MSFT stock quote is requested, an unknown host exception would be
generated. A connection refused exception would be generated for the SUN
stock request. This error message is captured and returned to the original
client as a SOAP fault in this example. </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT</pre>

<p>returns, </p>
<pre xml:space="preserve">&lt;soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;faultcode&gt;soapenv:Client&lt;/faultcode&gt;
    &lt;faultstring&gt;Connection refused or failed for : bogus:9000 &lt;/faultstring&gt;&lt;detail /&gt;&lt;/soapenv:Fault&gt;</pre>

<p>And </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN</pre>

<p>returns, </p>
<pre xml:space="preserve">&lt;soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;faultcode&gt;soapenv:Client&lt;/faultcode&gt;
    &lt;faultstring&gt; Connection refused or failed for : localhost/127.0.0.1:9009&lt;/faultstring&gt;&lt;detail /&gt;&lt;/soapenv:Fault&gt;</pre>

<h2><a name="Sample6">Sample 6: Manipulating SOAP headers, and filtering
incoming and outgoing messages</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;in&gt;
        &lt;header name="To" value="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
    &lt;/in&gt;
    &lt;send/&gt;
&lt;/definitions&gt;</pre>

<p><strong>Objective: Introduction to header, in (out) mediators</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Synapse configuration numbered 6: i.e. wso2esb-samples -sn 6<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
done </p>

<p>In this example we use the stockquote client in the dumb client mode,
setting the 'To' EPR of the message to ESB. Then the 'in' mediator processes
the incoming messages, and manipulates the 'To' header to refer to the stock
quote service on the sample Axis2 server. Thus it is now possible to request
for a stock quote as follows. </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/</pre>

<h2><a name="Sample7">Sample 7: Introduction to local Registry entries and
using Schema validation</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;localEntry key="validate_schema"&gt;
        &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    xmlns="http://www.apache-synapse.org/test" elementFormDefault="qualified"
                    attributeFormDefault="unqualified"
                    targetNamespace="http://services.samples"&gt;
            &lt;xs:element name="getQuote"&gt;
                &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                        &lt;xs:element name="request"&gt;
                            &lt;xs:complexType&gt;
                                &lt;xs:sequence&gt;
                                    &lt;xs:element name="stocksymbol" type="xs:string"/&gt;
                                &lt;/xs:sequence&gt;
                            &lt;/xs:complexType&gt;
                        &lt;/xs:element&gt;
                    &lt;/xs:sequence&gt;
                &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
        &lt;/xs:schema&gt;
    &lt;/localEntry&gt;

    &lt;in&gt;
        &lt;validate&gt;
            &lt;schema key="validate_schema"/&gt;
            &lt;on-fail&gt;
                &lt;!-- if the request does not validate againt schema throw a fault --&gt;
                &lt;makefault&gt;
                    &lt;code value="tns:Receiver"
                            xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/&gt;
                    &lt;reason value="Invalid custom quote request"/&gt;
                &lt;/makefault&gt;
                &lt;property name="RESPONSE" value="true"/&gt;
                &lt;header name="To" expression="get-property('ReplyTo')"/&gt;
            &lt;/on-fail&gt;
        &lt;/validate&gt;
    &lt;/in&gt;
    &lt;send/&gt;
&lt;/definitions&gt; </pre>

<p><strong>Objective: Introduction to local (static) registry entries and the
validate mediator</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Synapse configuration numbered 7: i.e. wso2esb-samples -sn 7<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
done </p>

<p>This example shows how a static XML fragment could be made available to
the ESB local registry. Resources defined in the local registry are static
(i.e. never changes over the lifetime of the configuration) and may be
specified as a source URL, inline text or inline xml. In this example the
schema is made available under the key 'validate_schema'. </p>

<p>The validate mediator by default operates on the first child element of
the SOAP body. You may specify an XPath expression using the 'source'
attribute to override this behaviour. The validate mediator now uses the
'validate_schema' resource to validate the incoming message, and if the
message validatation fails it invokes the 'on-fail' sequence of mediators.
</p>

<p>If you send a stockquote request using 'ant stockquote ...' you will get a
fault back with the message 'Invalid custom quote request' as the schema
validation failed. This is because the schema used in the example expects a
slightly different message than what is created by the stock quote client.
(i.e. expects a 'stocksymbol' element instead of 'symbol' to specify the stock
symbol) </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</pre>

<h2><a name="Sample8">Sample 8: Introduction to static and dynamic registry
resources, and using XSLT transformations</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or http://) --&gt;
    &lt;registry provider="org.wso2.carbon.mediation.registry.ESBRegistry"&gt;
        &lt;!-- the root property of the simple URL registry helps resolve a resource URL as root + key --&gt;
        &lt;parameter name="root"&gt;file:./repository/samples/resources/&lt;/parameter&gt;
        &lt;!-- all resources loaded from the URL registry would be cached for this number of milli seconds --&gt;
        &lt;parameter name="cachableDuration"&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;!-- define the request processing XSLT resource as a static URL source --&gt;
    &lt;localEntry key="xslt-key-req" src="file:repository/samples/resources/transform/transform.xslt"/&gt;

    &lt;in&gt;
        &lt;!-- transform the custom quote request into a standard quote requst expected by the service --&gt;
        &lt;xslt key="xslt-key-req"/&gt;
    &lt;/in&gt;
    &lt;out&gt;
        &lt;!-- transform the standard response back into the custom format the client expects --&gt;
        &lt;!-- the key is looked up in the remote registry and loaded as a 'dynamic' registry resource --&gt;
        &lt;xslt key="transform/transform_back.xslt"/&gt;
    &lt;/out&gt;
    &lt;send/&gt;
&lt;/definitions&gt;</pre>

<p><strong>Objective: Introduction to static and dynamic registry resources
and the XSLT mediator</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Synapse configuration numbered 8: i.e. wso2esb-samples -sn 8<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
done </p>

<p>This example uses the XSLT mediator to perform transformations, and the
xslt transformations are specified as registry resources. The first resource
'xslt-key-req' is specified as a 'local' registry entry. Local entries do not
place the resource on the registry, but simply make it available to the local
configuration. If a local entry is defined with a key that already exists in
the remote registry, the local entry will get higher preference and override
the remote resource. </p>

<p>In this example you will notice the new 'registry' definition. ESB comes
with a simple URL based registry implementation SimpleURLRegistry. During
initialization of the registry, the SimpleURLRegistry expects to find a
property named 'root', which specifies a prefix for the registry keys used
later. When the SimpleURLRegistry is used, this root is prefixed to the entry
keys to form the complete URL for the resource being looked up. The registry
caches a resource once requested, and caches it internally for a specified
duration. Once this period expires, it will reload the meta information about
the resource and reload its cached copy if necessary, the next time the
resource is requested. </p>

<p>Hence the second XSLT resource key 'transform/transform_back.xslt'
concatenated with the 'root' of the SimpleURLRegistry
'file:repository/samples/resources/' forms the complete URL of the
resource as
'file:repository/samples/resources/transform/transform_back.xslt' and
caches its value for a period of 15000 ms. </p>

<p>Execute the custom quote client as 'ant stockquote -Dmode=customquote ...'
and analyze the the ESB debug log output </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote</pre>

<p>The incoming message is now transformed into a standard stock quote
request as expected by the SimpleStockQuoteService deployed on the local
Axis2 instance, by the XSLT mediator. The XSLT mediator uses Xalan-J to
perform the transformations. It is possible to configure the underlying
transformation engine using properties where necessary. The response from the
SimpleStockQuoteService is converted back into the custom format as expected
by the client during the out message processing. </p>

<p>During the response processing the SimpleURLRegistry fetches the resource.</p>

<p>If you run the client again immediately (i.e within 15 seconds of the
first request) you will not see the resource being reloaded by the registry
as the cached value would be still valid. </p>

<p>However if you leave the system idle for 15 seconds or more and then retry
the same request, you will now notice that the registry noticed the cached
resource has expired and will check the meta information about the resource
to check if the resource itself has changed and will require a fresh fetch
from the source URL. If the meta data / version number indicates that a
reload of the cached resource is not necessary (i.e. unless the resource
itself actually changed) the updated meta information is used and the cache
lease extended as appropriate. </p>
<pre xml:space="preserve">[HttpClientWorker-1] DEBUG AbstractRegistry - Cached object has expired for key : transform/transform_back.xslt
[HttpClientWorker-1] DEBUG SimpleURLRegistry - Perform RegistryEntry lookup for key : transform/transform_back.xslt
[HttpClientWorker-1] DEBUG AbstractRegistry - Expired version number is same as current version in registry
[HttpClientWorker-1] DEBUG AbstractRegistry - Renew cache lease for another 15s </pre>

<p>Now edit the
repository/samples/resources/transform/transform_back.xslt file and add a
blank line at the end. Now when you run the client again, and if the cache is
expired, the resource would be re-fetched from its URL by the registry and
this can be seen by the following debug log messages </p>
<pre xml:space="preserve">[HttpClientWorker-1] DEBUG AbstractRegistry - Cached object has expired for key : transform/transform_back.xslt
[HttpClientWorker-1] DEBUG SimpleURLRegistry - Perform RegistryEntry lookup for key : transform/transform_back.xslt</pre>

<p>Thus the SimpleURLRegistry allows resource to be cached, and updates
detected so that the changes could be reloaded without restarting the ESB
instance. </p>

<h2><a name="Sample9">Sample 9: Introduction to dynamic sequences with the
Registry</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;registry provider="org.wso2.carbon.mediation.registry.ESBRegistry"&gt;
        &lt;parameter name="root"&gt;file:./repository/samples/resources/&lt;/parameter&gt;
        &lt;parameter name="cachableDuration"&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;sequence key="sequence/dynamic_seq_1.xml"/&gt;
&lt;/definitions&gt; </pre>

<p><strong>Objective: Introduction to dynamic sequences with a
Registry</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Synapse configuration numbered 9: i.e. wso2esb-samples -sn 9<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
done </p>

<p>This example introduces the dynamic behaviour of ESB through the use of a
Registry. ESB supports dynamic definitions for sequences and endpoints, and
as seen before, for resources. In this example we define a Synapse
configuration which references a sequence definition specified as a registry
key. The registry key resolves to the actual content of the sequence which
would be loaded dynamically by ESB at runtime, and cached appropriately as
per its definition in the registry. Once the cache expires, ESB would recheck
the meta information for the definition and re-load the sequence definition
if necessary and re-cache it again. </p>

<p>Once ESB is started, execute the stock quote client as 'ant stockquote..'.
You will notice that that ESB fetches the definition of the sequence from the
registry and executes its rules as follows: </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</pre>
<pre xml:space="preserve">[HttpServerWorker-1] DEBUG SequenceMediator - Sequence mediator &lt;dynamic_sequence&gt; :: mediate()
...
[HttpServerWorker-1] INFO  LogMediator - message = *** Test Message 1 ***</pre>

<p>Now if you execute the client immediately (i.e. within 15 seconds of the
last execution) you will notice that the sequence was not reloaded. If you
edit the sequence definition in
repository/samples/resources/sequence/dynamic_seq_1.xml (i.e. edit the
log message to read as "*** Test Message 2 ***") and execute the client
again, you will notice that the new message is not yet visible (i.e. if you
execute this within 15 seconds of loading the resource for the first time)
However, after 15 seconds elapsed since the original caching of the sequence,
you will notice that the new sequence is loaded and executed by ESB from the
following log messages. </p>
<pre xml:space="preserve">[HttpServerWorker-1] DEBUG SequenceMediator - Sequence mediator &lt;dynamic_sequence&gt; :: mediate()
...
[HttpServerWorker-1] INFO  LogMediator - message = *** Test Message 2 ***</pre>

<p>The cache timeout could be tuned appropriately by configuring the URL
registry to suite the environment and the needs. </p>

<h2><a name="Sample10">Sample 10: Introduction to dynamic endpoints with the
Registry</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;registry provider="org.wso2.carbon.mediation.registry.ESBRegistry"&gt;
        &lt;parameter name="root"&gt;file:repository/samples/resources/&lt;/parameter&gt;
        &lt;parameter name="cachableDuration"&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;in&gt;
        &lt;send&gt;
            &lt;endpoint key="endpoint/dynamic_endpt_1.xml"/&gt;
        &lt;/send&gt;
    &lt;/in&gt;
    &lt;out&gt;
        &lt;send/&gt;
    &lt;/out&gt;
&lt;/definitions&gt; </pre>

<p><strong>Objective: Introduction to dynamic endpoints with the
Registry</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Synapse configuration numbered 10: i.e. wso2esb-samples -sn 10<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
done<br />
Start a second Axis2 server on http port 9001 and https port 9003 as follows:
</p>
<pre xml:space="preserve">./axis2server.sh -http 9001 -https 9003</pre>

<p>This example introduces dynamic endpoints, where the definition of an
endpoint is stored in the Registry. To follow this example execute the stock
quote client as 'ant stockquote..' and see that the message is routed to the
SimpleStockQuoteService on the default Axis2 instance on http port 9000.
Repeat the above example immediately again, and notice that the endpoint is
cached and reused by ESB - similarly to example # 8. </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/</pre>

<p>Now edit the repository/samples/resources/endpoint/dynamic_endpt_1.xml
definition and update the address to
"http://localhost:9001/services/SimpleStockQuoteService". After the cached
expires, the Registry loads the new definition of the endpoint, and then the
messages can be seen being routed to the second sample Axis2 server on http
port 9001. </p>

<h2><a name="Sample11">Sample 11: A full registry based configuration, and
sharing a configuration between multiple instances</a> </h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;registry provider="org.wso2.carbon.mediation.registry.ESBRegistry"&gt;
        &lt;parameter name="root"&gt;file:./repository/samples/resources/&lt;/parameter&gt;
        &lt;parameter name="cachableDuration"&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;
&lt;/definitions&gt; </pre>

<p><strong>Objective: A full registry based configuration</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Synapse configuration numbered 11: i.e. wso2esb-samples -sn 11<br />
Start the Axis2 server and deploy the SimpleStockQuoteService if not already
done </p>

<p>This example shows a full registry based ESB configuration. Thus it is
possible to start a remote configuration from multiple instances of ESB in a
clustered environment easily. The Synapse configuration held on a node
hosting ESB simply points to the registry and looks up the actual
configuration by requesting the key 'synapse.xml'. </p>

<p>(Note: Full registry based configuration is not dynamic atleast for the
moment. i.e. it is not reloading itself) </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</pre>
<pre xml:space="preserve">[HttpServerWorker-1] INFO LogMediator - message = This is a dynamic Synapse configuration</pre>

<p>The actual synapse.xml loaded is: </p>
<pre xml:space="preserve">&lt;!-- a registry based Synapse configuration --&gt;
&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;log level="custom"&gt;
        &lt;property name="message" value="This is a dynamic Synapse configuration $$$"/&gt;
    &lt;/log&gt;
    &lt;send/&gt;
&lt;/definitions&gt;</pre>

<h2><a name="Sample12">Sample 12: One way messaging / fireAndForget through
ESB</a> </h2>

<p><strong>Objective: Demonstrate one way messaging / fireAndForget through
ESB</strong> </p>

<p><strong>Prerequisites:</strong><br />
Start the Axis2 server and deploy the SimpleStockQuoteService (Refer steps
above)<br />
Start the Synapse configuration numbered 0: i.e. wso2esb-samples -sn 0</p>

<p>This example invokes the one-way 'placeOrder' operation on the
SimpleStockQuoteService using the custom client which uses the Axis2
ServiceClient.fireAndForget() API. To test this, use 'ant
-Dmode=placeorder...' and you will notice the one way message flowing through
ESB into the sample Axis2 server instance, which reports the acceptance of
the order as follows: </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=placeorder</pre>
<pre xml:space="preserve">SimpleStockQuoteService :: Accepted order for : 7482 stocks of IBM at $ 169.27205579038733</pre>

<p>If you send your client request through TCPmon, you will notice that the
SimpleStockQuoteService replies to ESB with a HTTP 202 reply, and that ESB
in-turn replies to the client with a HTTP 202 acknowledgement </p>

<h2>
<a name="Sample13">Sample 13: Dual channel invocation through synapse</a>
</h2>
<p>
<strong>Objective: Demonstrate dual channel messaging
through synapse</strong>
</p>
<p><strong>Prerequisites:</strong><br/> Start the Axis2 server
and deploy the SimpleStockQuoteService (Refer steps above)<br/> Start
the Synapse configuration numbered 0: i.e. wso2esb-samples.sh -sn 0
</p>
<p>
This example invokes the same 'getQuote' operation on the
SimpleStockQuoteService using the custom client which uses the Axis2
ServiceClient API with useSeparateListener set to true so that the response is
coming through a different channel than the one which is used to send the request
to a callback defined in the client.
To test this, use 'ant
-Dmode=dualquote...' and you will notice the dual channel invocation
through Synapse into the sample Axis2 server instance, which reports the response
back to the client over a different channel:
</p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=dualquote</pre>
<pre xml:space="preserve">Response received to the callback
    Standard dual channel :: Stock price = $57.16686934968289</pre>
<p>
If you send your client request through TCPmon, you will notice that
Synapse replies to the client with a HTTP 202 acknowledgment when you send the request and
the communication between synapse and the server happens on a single channel and then you
get the response back from synapse to the clients callback in a different channel (which
cannot be observed through TCPmon)
</p>
<p>
Also you could see the wsa:Reply-To header being something like
http://localhost:8200/axis2/services/anonService2 which implies that the reply
is being on a different channel listening on the port 8200. Please note that it is
required to engage addressing when using the dual channel invocation because it
requires the wsa:Reply-To header.
</p>


<h2>
<a name="Sample14">Sample 14: Sequences and Endpoints as local registry items</a>
</h2>

<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;
             xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
             xsi:schemaLocation=&quot;http://ws.apache.org/ns/synapse http://synapse.apache.org/ns/2010/04/configuration/synapse_config.xsd&quot;&gt;

    &lt;localEntry key=&quot;local-enrty-ep-key&quot;
                src=&quot;file:repository/conf/sample/resources/endpoint/dynamic_endpt_1.xml&quot;/&gt;

    &lt;localEntry key=&quot;local-enrty-sequence-key&quot;&gt;
        &lt;sequence name=&quot;dynamic_sequence&quot;&gt;
            &lt;log level=&quot;custom&quot;&gt;
                &lt;property name=&quot;message&quot; value=&quot;*** Test Message 1 ***&quot;/&gt;
            &lt;/log&gt;
        &lt;/sequence&gt;
    &lt;/localEntry&gt;

    &lt;sequence name=&quot;main&quot;&gt;
        &lt;in&gt;
            &lt;sequence key=&quot;local-enrty-sequence-key&quot;/&gt;
            &lt;send&gt;
                &lt;endpoint key=&quot;local-enrty-ep-key&quot;/&gt;
            &lt;/send&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;</pre>

<p>
<strong>Objective: Sequence and Endpoints as local registry entries</strong>
</p>
<p><strong>Prerequisites:</strong><br/> Start the Axis2 server
and deploy the SimpleStockQuoteService (Refer steps above)<br/> Start
the Synapse configuration numbered 14: i.e. wso2esb-samples.sh -sn 14
</p>
<p>
This example shows sequences and endpoints fetched from local registry.
Thus it is possible to have endpoints sequences as local registry entries including file entries.
Execute the following command to see the sample working, where you will be able to see the
log statement from the fetched sequence from the local entry and the endpoint will be fetched from
the specified file at runtime and be cached in the system</p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/</pre>



<h2>
<a name="Sample15">Sample 15: Message Enrichment through Synapse</a></h2>
<pre xml:space="preserve">
&lt;definitions xmlns=&quot;http://synapse.apache.org/ns/2010/04/configuration&quot;&gt;
    &lt;sequence name=&quot;main&quot;&gt;
        &lt;in&gt;
            &lt;enrich&gt;
                &lt;source type=&quot;custom&quot;
                        xpath=&quot;//m0:getQuote/m0:request/m0:symbol/text()&quot;
                        xmlns:m0=&quot;http://services.samples&quot;/&gt;
                &lt;target type=&quot;property&quot; property=&quot;ORIGINAL_REQ&quot;/&gt;
            &lt;/enrich&gt;
            &lt;enrich&gt;
                &lt;source type=&quot;body&quot;/&gt;
                &lt;target type=&quot;property&quot; property=&quot;REQUEST_PAYLOAD&quot;/&gt;
            &lt;/enrich&gt;

            &lt;enrich&gt;
                &lt;source type=&quot;inline&quot; key=&quot;init_req&quot;/&gt;
                &lt;target xmlns:m0=&quot;http://services.samples&quot;
                        xpath=&quot;//m0:getQuote/m0:request/m0:symbol/text()&quot;/&gt;
            &lt;/enrich&gt;

            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;drop/&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;header xmlns:urn=&quot;http://synapse.apache.org&quot; name=&quot;urn:lastTradeTimestamp&quot; value=&quot;foo&quot;/&gt;
            &lt;enrich&gt;
                &lt;source type=&quot;custom&quot;
                        xpath=&quot;//ns:getQuoteResponse/ns:return/ax21:lastTradeTimestamp&quot;
                        xmlns:ns=&quot;http://services.samples&quot;
                        xmlns:ax21=&quot;http://services.samples/xsd&quot;/&gt;
                &lt;target xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
                        xmlns:urn=&quot;http://synapse.apache.org&quot;
                        xpath=&quot;/soapenv:Envelope/soapenv:Header/urn:lastTradeTimestamp&quot;/&gt;
            &lt;/enrich&gt;
             &lt;log level=&quot;full&quot;/&gt;
            &lt;log&gt;
                &lt;property name=&quot;Original Request Symbol&quot; expression=&quot;get-property(&#39;ORIGINAL_REQ&#39;)&quot;/&gt;
                &lt;property name=&quot;Request Payload&quot; expression=&quot;get-property(&#39;REQUEST_PAYLOAD&#39;)&quot;/&gt;
            &lt;/log&gt;
            &lt;send/&gt;
        &lt;/out&gt;

    &lt;/sequence&gt;
    &lt;localEntry key=&quot;init_req&quot;&gt;MSFT&lt;/localEntry&gt;
    &lt;localEntry key=&quot;price_req&quot;&gt;
        &lt;m0:symbol xmlns:m0=&quot;http://services.samples&quot;&gt;MSFT&lt;/m0:symbol&gt;
    &lt;/localEntry&gt;

&lt;/definitions&gt;
</pre>
<p>
<strong>Objective: Introduction to Message Copying and Content Enriching with Enrich Mediator</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Synapse configuration numbered 15: i.e. synapse -sample 15
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done
</p>
<pre xml:space="preserve">./axis2server.sh</pre>
<p>This sample demonstrate the various capabilities of Enrich Mediator. Inside the in-sequence we store/copy different
    parts of the message to properties and just before sending the message to the StockQuoteService, we modify the
    request value based on the local entry value-init_req. Then in the out-sequence, the enrich mediator is used
    to enrich a soap header based on the 'lastTradeTimestamp' value of the response.
</p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuote</pre>
<p>You can try with different local entries as the source with the correct target xpath values. </p>

<h2>
<a name="Sample16">Sample 16: Introduction to dynamic and static registry keys</a></h2>
<pre xml:space="preserve">
&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or http://) --&gt;
    &lt;registry provider="org.wso2.carbon.mediation.registry.ESBRegistry"&gt;
        &lt;!-- the root property of the simple URL registry helps resolve a resource URL as root + key --&gt;
        &lt;parameter name="root"&gt;file:repository/samples/resources/&lt;/parameter&gt;
        &lt;!-- all resources loaded from the URL registry would be cached for this number of milli seconds --&gt;
        &lt;parameter name="cachableDuration"&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;sequence name="main"&gt;
        &lt;in&gt;
            &lt;!-- define the request processing XSLT resource as a property value --&gt;
            &lt;property name="symbol" value="transform/transform.xslt"/&gt;
            &lt;!-- {} denotes that this key is a dynamic one and it is not a static key --&gt;
            &lt;!-- use Xpath expression "get-property()" to evaluate real key from property --&gt;
            &lt;xslt key="{get-property('symbol')}"/&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;!-- transform the standard response back into the custom format the client expects --&gt;
            &lt;!-- the key is looked up in the remote registry using a static key --&gt;
            &lt;xslt key="transform/transform_back.xslt"/&gt;
        &lt;/out&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;
</pre>
<p>
<strong>Objective: Introduction to dynamic and static keys </strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Synapse configuration numbered 16: i.e. synapse -sample 16
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done
</p>
<pre xml:space="preserve">./axis2server.sh</pre>
<p>This Sample demonstrates the use of dynamic keys with mediators. XSLT mediator is used as an
    example for that and deference between static and dynamic usage of keys are shown with that.
</p>
<p>The first registry resource "transform/transform.xslt" is set as a property value. Inside the
    XSLT mediator the local property value is lookup using the Xpath expression "get-property()".
    Likewise any Xpath expression can be enclosed inside "{ }" to denote that it is a dynamic key.
    Then the mediator will evaluate the real value for that expression.
</p>
<p>The second XSLT resource "transform/transform_back.xslt" is used simply as a static key as
    usual. It is not included inside "{ }" and because of the mediator directly use the static
    value as the key.
</p>
<p>Execute the custom quote client as 'ant stockquote -Dmode=customquote' and analys the output
    which is similar to the Sample 8.
</p>

<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuote</pre>
<p>You can try with different local entries as the source with the correct target xpath values. </p>

</body>
</html>
