<?xml version="1.0"?>
<document>
<properties>
<title>Apache Synapse - Samples Guide</title></properties>
<head>
<style type="text/css" xml:space="preserve">    .command {
        border: 1px dashed #3c78b5;
        text-align: left;
        background-color: #f0f0f0;
        padding: 3px;
        font-size: 11px;
        font-family: Courier;
        margin: 10px;
        line-height: 13px;
    }
    .consoleOutput {
        border: 1px dashed #3c78b5;
        font-size: 11px;
        font-family: Courier;
        margin: 10px;
        line-height: 13px;
        background-color: #f0f0f0;
        border-bottom: 1px dashed #3c78b5;
        padding: 3px;
        border-style: solid;
    }
    .info {
        border-style: solid;
        border-width: 1px;
        border-color: #090;
        background-color: #dfd;
        text-align:left;
        margin-top: 5px;
        margin-bottom: 5px;
    }
    li {
        font-family: Verdana, arial, sans-serif;
        font-size: 11px;
        line-height: 16px;
        color: #000000;
        font-weight: normal;
    }
    p {
        font-family: Verdana, arial, sans-serif;
        font-size: 11px;
        line-height: 16px;
        color: #000000;
        font-weight: normal;
    }
    pre {
        padding: 0px;
        margin-top: 5px;
        margin-left: 15px;
        margin-bottom: 5px;
        margin-right: 5px;
        text-align: left;
        background-color: #f0f0f0;
        padding: 3px;
        border: 1px dashed #3c78b5;
        font-size: 11px;
        font-family: Courier;
        margin: 10px;
        line-height: 13px;
    }
    h1 {
        font-size: 24px;
        line-height: normal;
        font-weight: bold;
        background-color: #f0f0f0;
        color: #003366;
        border-bottom: 1px solid #3c78b5;
        padding: 2px;
        margin: 36px 0px 4px 0px;
    }
    h2 {
        font-size: 18px;
        line-height: normal;
        font-weight: bold;
        background-color: #f0f0f0;
        border-bottom: 1px solid #3c78b5;
        padding: 2px;
        margin: 27px 0px 4px 0px;
    }
    h3 {
        font-size: 14px;
        line-height: normal;
        font-weight: bold;
        background-color: #f0f0f0;
        padding: 2px;
        margin: 21px 0px 4px 0px;
    }
    h4 {
        font-size: 12px;
        line-height: normal;
        font-weight: bold;
        background-color: #f0f0f0;
        padding: 2px;
        margin: 18px 0px 4px 0px;
    }</style></head>
<body>
<div style="margin-top:-40px; float:right; _margin-top:0px;"></div>
<div>
<h1>Apache Synapse ESB - Running the Samples </h1></div>
<p>This guide will walk you through the built-in samples shipped with the product, which will cover most of the basic functional sceanrios and capabilities of Apache Synapse as an ESB. If you are unable to solve your problem by reading through and running these samples, feel free to raise your problem on the 
<a href="http://synapse.apache.org/mail-lists.html">mailing lists</a>.</p>
<h2>
<a name="TOC" id="TOC">Contents</a></h2>
<div class="section-content">
<ul>
<li>
<a href="Synapse_Samples_Setup.html#Overview">Overview</a></li>
<li>
<a href="#MediationSamples">Message mediation samples</a>
<ul>
<li>
<a href="#Sample0">Sample 0: Introduction to Synapse</a></li>
<li>
<a href="#Sample1">Sample 1: Simple content based routing (CBR) of messages</a></li>
<li>
<a href="#Sample2">Sample 2: CBR with the Switch-case mediator, using message properties</a></li>
<li>
<a href="#Sample3">Sample 3: Local Registry entry definitions, reusable endpoints and sequences</a></li>
<li>
<a href="#Sample4">Sample 4: Introduction to error handling</a></li>
<li>
<a href="#Sample5">Sample 5: Creating SOAP fault messages and changing the direction of a message</a></li>
<li>
<a href="#Sample6">Sample 6: Manipulating SOAP headers, and filtering incoming and outgoing messages</a></li>
<li>
<a href="#Sample7">Sample 7: Introduction to local Registry entries and using Schema validation</a></li>
<li>
<a href="#Sample8">Sample 8: Introduction to static and dynamic registry resources, and using XSLT transformations</a></li>
<li>
<a href="#Sample9">Sample 9: Introduction to dynamic sequences with the Registry</a></li>
<li>
<a href="#Sample10">Sample 10: Introduction to dynamic endpoints with the Registry</a></li>
<li>
<a href="#Sample11">Sample 11: A full registry based configuration, and sharing a configuration between multiple instances</a></li>
<li>
<a href="#Sample12">Sample 12: One way messaging / fireAndForget through Synapse</a></li>
<li>
<a href="#Sample13">Sample 13: Dual channel invocation through Synapse</a></li>
<li>
<a href="#Sample13">Sample 15: Message Enrichment through Synapse</a></li>
<li>
<a href="#Sample16">Sample 16: Introduction to dynamic and static registry keys</a></li>
</ul></li>

<li>
<a href="#Endpoints">Advanced mediations with endpoints</a>
<ul>
<li>
<a href="#Sample50">Sample 50: POX to SOAP conversion</a></li>
<li>
<a href="#Sample51">Sample 51: MTOM and SwA optimizations and request/response correlation</a></li>
<li>
<a href="#Sample52">Sample 52: Session less load balancing between 3 endpoints</a></li>
<li>
<a href="#Sample53">Sample 53: Failover sending among 3 endpoints</a></li>
<li>
<a href="#Sample54">Sample 54: Session affinity load balancing between 3 endpoints</a></li>
<li>
<a href="#Sample55">Sample 55: Session affinity load balancing between fail over endpoints</a></li>
<li>
<a href="#Sample56">Sample 56: WSDL endpoint</a></li>
<li>
<a href="#Sample57">Sample 57: Dynamic load balancing between 3 nodes</a></li>
<li>
<a href="#Sample58">Sample 58: Static load balancing between 3 nodes</a></li>
<li>
<a href="#Sample60">Sample 60: Routing a message to a static list of recipients</a></li>
<li>
<a href="#Sample61">Sample 61: Routing a message to a dynamic list of recipients</a></li>
<li>
<a href="#Sample62">Sample 62: Routing a message to a dynamic list of recipients and aggregating the responses</a></li></ul></li>
<li>
<a href="#MessageMediationQoS">Quality of Service addition or deduction samples in message mediation</a>
<ul>
<li>
<a href="#Sample100">Sample 100: Using WS-Security for outgoing messages</a></li>
<li>
<a href="#Sample101">Sample 101: Reliable message exchange between Synapse and the back-end server using WS-ReliableMessaging</a></li></ul></li>
<li>
<a href="#ProxyServices">Synapse Proxy service samples</a>
<ul>
<li>
<a href="#Sample150">Sample 150: Introduction to proxy services</a></li>
<li>
<a href="#Sample151">Sample 151: Custom sequences and endpoints with proxy services</a></li>
<li>
<a href="#Sample152">Sample 152: Switching transports and message format from SOAP to REST/POX</a></li>
<li>
<a href="#Sample153">Sample 153: Routing the messages arrived to a proxy service without processing the security headers</a></li>
<li>
<a href="#Sample154">Sample 154: Load Balancing with Proxy Service </a></li>
<li>
<a href="#Sample155">Sample 155: Dual channel invocation on both client side and server side of Synapse with Proxy Services</a></li></ul></li>
<li>
<a href="#ProxyServiceQoS">QoS addition and deduction for service mediation (proxy) samples</a>
<ul>
<li>
<a href="#Sample200">Sample 200: Using WS-Security with policy attachments for proxy services</a></li>
<li>
<a href="#Sample201">Sample 201: Reliable message exchange between the client and proxy services using WS-ReliableMessaging</a></li></ul></li>
<li>
<a href="#Transport">Transport samples and switching transports</a>
<ul>
<li>
<a href="#Sample250">Sample 250: Introduction to switching transports - JMS to http/s</a></li>
<li>
<a href="#Sample251">Sample 251: Switching from http/s to JMS</a></li>
<li>
<a href="#Sample252">Sample 252: Pure text/binary and POX message support with JMS</a></li>
<li>
<a href="#Sample253">Sample 253: One way bridging from JMS to http and replying with a 202 Accepted response</a></li>
<li>
<a href="#Sample254">Sample 254: Using the file system as transport medium using VFS transport listener and sender</a></li>
<li>
<a href="#Sample255">Sample 255: Switching from ftp transport listener to mail transport sender</a></li>
<li>
<a href="#Sample256">Sample 256: Proxy services with the mail transport</a></li>
<li>
<a href="#Sample257">Sample 257: Proxy services with the FIX transport</a></li>
<li>
<a href="#Sample258">Sample 258: Switching from HTTP to FIX </a></li>
<li>
<a href="#Sample259">Sample 259: Switching from FIX to HTTP </a></li>
<li>
<a href="#Sample260">Sample 260: Switching from FIX to AMQP </a></li>
<li>
<a href="#Sample261">Sample 261: Switch between FIX versions </a></li>
<li>
<a href="#Sample262">Sample 262: CBR of FIX messages </a></li>
<li>
<a href="#Sample263">Sample 263: Transport switching - JMS to http/s using JBoss Messaging(JBM) </a></li>
<li>
<a href="#Sample264">Sample 264: Transport switching - HTTP/S to JMS two way messages</a></li>
<li>
<a href="#Sample265">Sample 265: Switching from TCP to HTTP/S</a></li>
<li>
<a href="#Sample266">Sample 266: Switching from UDP to HTTP/S</a></li>    
</ul></li>
<li>
<a href="#Task">Introduction to Synapse tasks</a>
<ul>
<li>
<a href="#Sample300">Sample 300: Introduction to tasks with simple trigger</a></li></ul></li>
<li>
<a href="#AdvancedMediation">Advanced mediations with advanced mediators</a>
<ul>
<li>
<a href="#ScriptMediator">Using scripts in mediation (Script Mediator)</a>
<ul>
<li>
<a href="#Sample350">Sample 350: Introduction to the script mediator using js scripts</a></li>
<li>
<a href="#Sample351">Sample 351: In-line script mediation with JavaScript</a></li>
<li>
<a href="#Sample352">Sample 352: Accessing Synapse message context API methods using scripting language</a></li>
<li>
<a href="#Sample353">Sample 353: Using Ruby scripts for mediation</a></li>
<li>
<a href="#Sample354">Sample 354: Using In-lined Ruby scripts for mediation</a></li></ul></li>
<li>
<a href="#DBMediators">Database interactions in mediation (DBLookup / DBReport)</a>
<ul>
<li>
<a href="#Sample360">Sample 360: Introduction to dblookup mediator</a></li>
<li>
<a href="#Sample361">Sample 361: Introduction to dbreport mediator</a></li>
<li>
<a href="#Sample362">Sample 362: Action of dbreport and dblookup mediators together</a></li>
<li>
<a href="#Sample363">Sample 363: Reusable database connection pools</a></li>
<li>
<a href="#Sample364">Sample 364: Executing database Stored Procedures</a></li></ul></li>
<li>
<a href="#Throttle">Throttling messages (Throttle Mediator)</a>
<ul>
<li>
<a href="#Sample370">Sample 370: Introduction to throttle mediator and concurrency throttling</a></li>
<li>
<a href="#Sample371">Sample 371: Restricting requests based on policies</a></li>
<li>
<a href="#Sample372">Sample 372: Use of both concurrency throttling and request rate based throttling </a></li></ul></li>
<li>
<a href="#Class">Extending the mediation in java (Class Mediator)</a>
<ul>
<li>
<a href="#Sample380">Sample 380: Writing your own custom mediation in Java</a></li>
<li>
<a href="#Sample381">Sample 381: Class mediator to CBR binary messages</a></li></ul></li>
<li>
<a href="#XQuery">Evaluating XQuery for mediation (XQuery Mediator)</a>
<ul>
<li>
<a href="#Sample390">Sample 390: Introduction to the XQuery mediator</a></li>
<li>
<a href="#Sample391">Sample 391: How to use the data from an external XML document with in XQuery </a></li></ul></li>
<li>
<a href="#Splitter">Splitting messages in to parts and process in parallel (Iterate / Clone)</a>
<ul>
<li>
<a href="#Sample400">Sample 400: Message splitting and aggregating the responses</a></li></ul></li>
<li>
<a href="#Cache">Caching the responses over the requests</a>
<ul>
<li>
<a href="#Sample420">Sample 420: Simple cache implemented on Synapse for the actual service</a></li></ul></li>
<li>
<a href="#Callout">Synchronized Web Service invocations with Callout mediator</a>
<ul>
<li>
<a href="#Sample430">Sample 430: Simple Callout Mediator for synchronize web service invocation</a></li>
<li>
<a href="#Sample440">Sample 440: Exposing a SOAP service over JSON</a></li>
<li>
<a href="#Sample450">Sample 450: Introduction to the URL Rewrite mediator</a></li>
<li>
<a href="#Sample451">Sample 451: Conditional URL rewriting</a></li>
<li>
<a href="#Sample452">Sample 452: Conditional URL rewriting with multiple rules</a></li>
<li>
<a href="#Sample460">Sample 460: How to initialize and use a Spring Bean as a Mediator</a></li>
</ul></li></ul></li>
        <li>
          <a href="#Task">Introduction to Eventing</a>
          <ul>
            <li>
              <a href="#Sample500">Sample 500: Introduction to Eventing</a>
            </li>
            <li>
              <a href="#Sample501">Sample 501: EventSource with static subscriptions</a>
            </li>
            <li>
              <a href="#Sample502">Sample 502: Transform events before publish</a>
            </li>
          </ul>
        </li>
        <li>
            <a href="#Misc">Miscellaneous Samples</a>
            <ul>
                <li>
                    <a href="#Sample600">Sample 600: File hierarchy based configuration builder</a>
                </li>
                <li>
                    <a href="#Sample601">Sample 601: Using Synapse Observers</a>
                </li>
                <li>
                    <a href="#Sample650">Sample 650: Priority based Mediation</a>
                </li>
                <li>
                    <a href="#Sample651">Sample 651: NHTTP Transport Priority based dispatching</a>
                </li>
                <li>
                    <a href="#Sample652">Sample 652: Distributed transaction management</a>
                </li>
            </ul>
        </li>
         <li>
            <a href="#StoreNFwd">Store and Forward Messaging patterns with Message Stores and Message Processors</a>
            <ul>
                <li>
                    <a href="#Sample700">Sample 700: Introduction to Synapse Message Store </a>
                </li>
                <li>
                    <a href="#Sample701">Sample 701: Introduction to Synapse Message Sampling Processor</a>
                </li>
                <li>
                    <a href="#Sample702">Sample 702: Introduction to Synapse Message Forwarding Processor </a>
                </li>
            </ul>
        </li>
</ul></div>
<h1>
<a name="MediationSamples" id="MediationSamples">Message Mediation Samples</a> </h1>
<h2>
<a name="Sample0" id="Sample0">Sample 0: Introduction to Synapse</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;!-- log all attributes of messages passing through --&gt;
    &lt;log level=&quot;full&quot;/&gt;

    &lt;!-- Send the messageto implicit destination --&gt;
    &lt;send/&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Introduction to Synapse. Shows how a message could be made to pass through Synapse </strong>
<strong>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>
<ol>
<li>Smart Client mode </li>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ </pre>
<li>Using Synapse as a HTTP Proxy </li>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dprxurl=http://localhost:8280/</pre>
<li>Gateway Mode / Dumb Client </li>
<p>See sample # 1 </p></ol>
<p>
<strong>Prerequisites:
<br/> </strong>Start the Synapse configuration numbered 0: e.g. synapse -sample 0
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already deployed </p>
<p>
<strong>Execute the Smart Client </strong> </p>
<p>By tracing the execution of Synapse with the log output level set to DEBUG, you will see the client request arriving at Synapse with a WS-Addressing 'To' set to EPR http://localhost:9000/services/SimpleStockQuoteService. The Synapse engine logs the message at the &quot;full&quot; 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 Synapse, 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 Synapse as the HTTP proxy. </p>
<h2>
<a name="Sample1" id="Sample1">Sample 1: Simple content based routing (CBR) of messages</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;!-- filtering of messages with XPath and regex matches --&gt;
    &lt;filter source=&quot;get-property('To')&quot; regex=&quot;.*/StockQuote.*&quot;&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;/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 Synapse using the Dumb Client mode, where Synapse 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. synapse -sample 1
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already deployed</p>
<p>Execute the Dumb Client as: </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuote</pre>

<p>This time you will see Synapse receiving a message for which Synapse was set as the ultimate receiver
of the message. Based on the 'To' EPR of http://localhost:8280/services/StockQuote, Synapse 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 'send'
mediator forwards the response back to the client using the implicit 'To' address. </p>
    
<h2>
<a name="Sample2" id="Sample2">Sample 2: CBR with the Switch-case mediator, using message properties</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;switch source=&quot;//m0:getQuote/m0:request/m0:symbol&quot; xmlns:m0=&quot;http://services.samples&quot;&gt;
        &lt;case regex=&quot;IBM&quot;&gt;
            &lt;!-- the property mediator sets a local property on the *current* message --&gt;
            &lt;property name=&quot;symbol&quot; value=&quot;Great stock - IBM&quot;/&gt;
        &lt;/case&gt;
        &lt;case regex=&quot;MSFT&quot;&gt;
            &lt;property name=&quot;symbol&quot; value=&quot;Are you sure? - MSFT&quot;/&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=&quot;symbol&quot;
                  expression=&quot;fn:concat('Normal Stock - ', //m0:getQuote/m0:request/m0:symbol)&quot;
                  xmlns:m0=&quot;http://services.samples&quot;/&gt;
        &lt;/default&gt;
    &lt;/switch&gt;

    &lt;log level=&quot;custom&quot;&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=&quot;symbol&quot; expression=&quot;get-property('symbol')&quot;/&gt;
        &lt;!-- the get-property() function supports the implicit message headers To/From/Action/FaultTo/ReplyTo --&gt;
        &lt;property name=&quot;epr&quot; expression=&quot;get-property('To')&quot;/&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. synapse -sample 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>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</pre>
<pre xml:space="preserve">      INFO LogMediator - symbol = Great stock - IBM, epr = http://localhost:9000/axis2/services/SimpleStockQuoteService </pre>
<pre>ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT</pre>
<pre xml:space="preserve">      INFO LogMediator - symbol = Are you sure? - MSFT, epr = http://localhost:9000/axis2/services/SimpleStockQuoteService</pre>
<h2>
<a name="Sample3" id="Sample3">Sample 3: Local Registry entry definitions, reusable endpoints and sequences</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;!-- define a string resource entry to the local registry --&gt;
    &lt;localEntry key=&quot;version&quot;&gt;0.1&lt;/localEntry&gt;
    &lt;!-- define a reuseable endpoint definition --&gt;
    &lt;endpoint name=&quot;simple&quot;&gt;
        &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
    &lt;/endpoint&gt;

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

    &lt;sequence name=&quot;main&quot;&gt;
        &lt;in&gt;
            &lt;property name=&quot;direction&quot; value=&quot;incoming&quot;/&gt;
            &lt;sequence key=&quot;stockquote&quot;/&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. synapse -sample 3
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>
<p>This example uses a sequence named as &quot;main&quot; 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 &quot;main&quot; is executed. Then for the incoming message flow the &lt;in&gt; mediator executes, and it calls the sequence named &quot;stockquote&quot;. </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 &quot;stockquote&quot; sequence executes, the log mediator dumps a simple text/string property, result of an XPath evaluation, that picks up the key named &quot;version&quot;, 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 &quot;version&quot; defines a simple text/string registry entry for that which is visible to all messages that pass through Synapse. </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" id="Sample4">Sample 4: Introduction to error handling</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

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

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

    &lt;!-- default message handling sequence used by Synapse - named 'main' --&gt;
    &lt;sequence name=&quot;main&quot;&gt;
        &lt;in&gt;
            &lt;switch source=&quot;//m0:getQuote/m0:request/m0:symbol&quot; xmlns:m0=&quot;http://services.samples&quot;&gt;
                &lt;case regex=&quot;IBM&quot;&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;/case&gt;
                &lt;case regex=&quot;MSFT&quot;&gt;
                    &lt;send&gt;
                        &lt;endpoint key=&quot;bogus&quot;/&gt;
                    &lt;/send&gt;
                &lt;/case&gt;
                &lt;case regex=&quot;SUN&quot;&gt;
                    &lt;sequence key=&quot;sunSequence&quot;/&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=&quot;sunSequence&quot; onError=&quot;sunErrorHandler&quot;&gt;
        &lt;send&gt;
            &lt;endpoint key=&quot;sunPort&quot;/&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. synapse -sample 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 in-line 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', Synapse is instructed to route the message to the endpoint defined as the 'bogus' endpoint, which does not exist. Synapse 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 Synapse 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 = Couldn't find the endpoint with the 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 = Couldn't find the endpoint with the key : sunPort</pre>
<h2>
<a name="Sample5" id="Sample5">Sample 5: Creating SOAP fault messages and changing the direction of a message</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

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

    &lt;sequence name=&quot;main&quot; onError=&quot;myFaultHandler&quot;&gt;
        &lt;in&gt;
            &lt;switch source=&quot;//m0:getQuote/m0:request/m0:symbol&quot;
                    xmlns:m0=&quot;http://services.samples/xsd&quot;&gt;
                &lt;case regex=&quot;MSFT&quot;&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;&lt;address uri=&quot;http://bogus:9000/services/NonExistentStockQuoteService&quot;/&gt;&lt;/endpoint&gt;
                    &lt;/send&gt;
                &lt;/case&gt;
                &lt;case regex=&quot;SUN&quot;&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;&lt;address uri=&quot;http://localhost:9009/services/NonExistentStockQuoteService&quot;/&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. synapse -sample 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=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;faultcode&gt;soapenv:Client&lt;/faultcode&gt;
    &lt;faultstring&gt;java.net.UnknownHostException: bogus&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=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;&lt;faultcode&gt;soapenv:Client&lt;/faultcode&gt;
    &lt;faultstring&gt;java.net.ConnectException: Connection refused&lt;/faultstring&gt;&lt;detail /&gt;&lt;/soapenv:Fault&gt;</pre>
<h2>
<a name="Sample6" id="Sample6">Sample 6: Manipulating SOAP headers, and filtering incoming and outgoing messages</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;in&gt;
        &lt;header name=&quot;To&quot; value=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&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. synapse -sample 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 Synapse. 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" id="Sample7">Sample 7: Introduction to local Registry entries and using Schema validation</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;localEntry key=&quot;validate_schema&quot;&gt;
        &lt;xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;
                    xmlns=&quot;http://services.samples&quot; elementFormDefault=&quot;qualified&quot;
                    attributeFormDefault=&quot;unqualified&quot;
                    targetNamespace=&quot;http://services.samples&quot;&gt;
            &lt;xs:element name=&quot;getQuote&quot;&gt;
                &lt;xs:complexType&gt;
                    &lt;xs:sequence&gt;
                        &lt;xs:element name=&quot;request&quot;&gt;
                            &lt;xs:complexType&gt;
                                &lt;xs:sequence&gt;
                                    &lt;xs:element name=&quot;stocksymbol&quot; type=&quot;xs:string&quot;/&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=&quot;validate_schema&quot;/&gt;
            &lt;on-fail&gt;
                &lt;!-- if the request does not validate againt schema throw a fault --&gt;
                &lt;makefault response=&quot;true&quot;&gt;
                    &lt;code value=&quot;tns:Receiver&quot;
                            xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
                    &lt;reason value=&quot;Invalid custom quote request&quot;/&gt;
                &lt;/makefault&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. synapse -sample 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 Synapse 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, in-line text or in-line 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 validation 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" id="Sample8">Sample 8: Introduction to static and dynamic registry resources, and using XSLT transformations</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or http://) --&gt;
    &lt;registry provider=&quot;org.apache.synapse.registry.url.SimpleURLRegistry&quot;&gt;
        &lt;!-- the root property of the simple URL registry helps resolve a resource URL as root + key --&gt;
        &lt;parameter name=&quot;root&quot;&gt;file:./repository/conf/sample/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=&quot;cachableDuration&quot;&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

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

    &lt;in&gt;
        &lt;!-- transform the custom quote request into a standard quote requst expected by the service --&gt;
        &lt;xslt key=&quot;xslt-key-req&quot;/&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=&quot;transform/transform_back.xslt&quot;/&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. synapse -sample 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. Synapse 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/conf/sample/resources/' forms the complete URL of the resource as 'file:repository/conf/sample/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 Synapse 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 you could see the SimpleURLRegistry fetching the resource as shown by the log message below </p>
<pre xml:space="preserve">[HttpClientWorker-1] DEBUG SimpleURLRegistry ==&gt; Repository fetch of resource with key : transform/transform_back.xslt</pre>
<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/conf/sample/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
[HttpClientWorker-1] INFO  SimpleURLRegistry - ==&gt; Repository fetch of resource with 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 Synapse instance. </p>
<h2>
<a name="Sample9" id="Sample9">Sample 9: Introduction to dynamic sequences with the Registry</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;registry provider=&quot;org.apache.synapse.registry.url.SimpleURLRegistry&quot;&gt;
        &lt;parameter name=&quot;root&quot;&gt;file:./repository/conf/sample/resources/&lt;/parameter&gt;
        &lt;parameter name=&quot;cachableDuration&quot;&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;sequence name="main"&gt;
        &lt;sequence key=&quot;sequence/dynamic_seq_1.xml&quot;/&gt;
    &lt;/sequence&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. synapse -sample 9
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>
<p>This example introduces the dynamic behaviour of Synapse through the use of a registry. Synapse 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 Synapse at runtime, and cached appropriately as per its definition in the registry. Once the cache expires, Synapse would re-check the meta information for the definition and re-load the sequence definition if necessary and re-cache it again. </p>
<p>Once Synapse is started, execute the stock quote client as 'ant stockquote..'. You will notice that that Synapse 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  SimpleURLRegistry - ==&gt; Repository fetch of resource with key : sequence/dynamic_seq_1.xml
...
[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/conf/sample/resources/sequence/dynamic_seq_1.xml (i.e. edit the log message to read as &quot;*** Test Message 2 ***&quot;) 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 Synapse from the following log messages. </p>
<pre xml:space="preserve">[HttpServerWorker-1] DEBUG  SimpleURLRegistry - ==&gt; Repository fetch of resource with key : sequence/dynamic_seq_1.xml
...
[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 suit the environment and the needs. </p>
<h2>
<a name="Sample10" id="Sample10">Sample 10: Introduction to dynamic endpoints with the Registry</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;registry provider=&quot;org.apache.synapse.registry.url.SimpleURLRegistry&quot;&gt;
        &lt;parameter name=&quot;root&quot;&gt;file:repository/conf/sample/resources/&lt;/parameter&gt;
        &lt;parameter name=&quot;cachableDuration&quot;&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;in&gt;
        &lt;send&gt;
            &lt;endpoint key=&quot;endpoint/dynamic_endpt_1.xml&quot;/&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. synapse -sample 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 Synapse - similarly to example # 8. </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/</pre>
<p>Now edit the repository/conf/sample/resources/endpoint/dynamic_endpt_1.xml definition and update the address to &quot;http://localhost:9001/services/SimpleStockQuoteService&quot;. After the cached value 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" id="Sample11">Sample 11: A full registry based configuration, and sharing a configuration between multiple instances</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;registry provider=&quot;org.apache.synapse.registry.url.SimpleURLRegistry&quot;&gt;
        &lt;parameter name=&quot;root&quot;&gt;file:./repository/conf/sample/resources/&lt;/parameter&gt;
        &lt;parameter name=&quot;cachableDuration&quot;&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. synapse -sample 11
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>
<p>This example shows a full registry based Synapse configuration. Thus it is possible to start a remote configuration from multiple instances of Synapse in a clustered environment easily. The Synapse configuration held on a node hosting Synapse 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=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;log level=&quot;custom&quot;&gt;
        &lt;property name=&quot;message&quot; value=&quot;This is a dynamic Synapse configuration $$$&quot;/&gt;
    &lt;/log&gt;
    &lt;send/&gt;
&lt;/definitions&gt;</pre>
<h2>
<a name="Sample12" id="Sample12">Sample 12: One way messaging / fireAndForget through Synapse</a></h2>
<p>
<strong>Objective: Demonstrate one-way messaging / fireAndForget 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 1: i.e. synapse -sample 1 </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 Synapse 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 Synapse with a HTTP 202 reply, and that Synapse in turns replies to the client with a HTTP 202 acknowledgment </p>

<h2>
<a name="Sample13" id="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. synapse -sample 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="Sample10" id="Sample15">Sample 15: Message Enrichment through Synapse</a></h2>
<pre xml:space="preserve">
    &lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&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" id="Sample16">Sample 16: Introduction to dynamic and static registry keys</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or http://) --&gt;
    &lt;registry provider=&quot;org.apache.synapse.registry.url.SimpleURLRegistry&quot;&gt;
        &lt;!-- the root property of the simple URL registry helps resolve a resource URL as root + key --&gt;
        &lt;parameter name=&quot;root&quot;&gt;file:repository/conf/sample/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=&quot;cachableDuration&quot;&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;
    &lt;sequence name=&quot;main&quot;&gt;
        &lt;in&gt;
            &lt;!-- define the request processing XSLT resource as a property value --&gt;
            &lt;property name=&quot;symbol&quot; value=&quot;transform/transform.xslt&quot; xmlns:m0=&quot;http://services.samples&quot;/&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=&quot;{get-property('symbol')}&quot; /&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=&quot;transform/transform_back.xslt&quot;/&gt;
        &lt;/out&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;</pre>
    
<p>
<strong>Objective: Introduction to dynamic and static registry 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>
<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 &quot;transform/transform.xslt&quot; is set as a property value. Inside the XSLT mediator the local property value is lookup using the Xpath expression &quot;get-property()&quot;. Likewise any Xpath expression can be enclosed inside &quot;{ }&quot; 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 &quot;transform/transform_back.xslt&quot; is used simply as a static key as usual. It is not included inside &quot;{ }&quot; 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 -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote</pre>

<h1>
<a name="Endpoints" id="Endpoints">Advanced mediations with endpoints</a> </h1>
<h2>
<a name="Sample50" id="Sample50">Sample 50: POX to SOAP conversion</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;!-- filtering of messages with XPath and regex matches --&gt;
    &lt;filter source=&quot;get-property('To')&quot; regex=&quot;.*/StockQuote.*&quot;&gt;
        &lt;send&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot; format=&quot;soap11&quot;/&gt;
            &lt;/endpoint&gt;
        &lt;/send&gt;
        &lt;drop/&gt;
    &lt;/filter&gt;
    &lt;send/&gt;
&lt;/definitions&gt; </pre>
<p>
<strong>Objective: POX to SOAP conversion</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Synapse configuration numbered 50: i.e. synapse -sample 50 </p>
<p>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>
<p>Execute the 'ant stockquote' specifying that the request should be a REST request as follows: </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuote -Drest=true</pre>
<p>This example shows a HTTP REST request (as shown below) being transformed into a SOAP request and forwarded to the stock quote service. </p>
<pre xml:space="preserve">POST /soap/StockQuote HTTP/1.1
Content-Type: application/xml; charset=UTF-8;action=&quot;urn:getQuote&quot;;
SOAPAction: urn:getQuote
User-Agent: Axis2
Host: 127.0.0.1
Transfer-Encoding: chunked

75
&lt;m0:getQuote xmlns:m0=&quot;http://services.samples/xsd&quot;&gt;
   &lt;m0:request&gt;
      &lt;m0:symbol&gt;IBM&lt;/m0:symbol&gt;
   &lt;/m0:request&gt;
&lt;/m0:getQuote&gt;0</pre>



<h2>
<a name="Sample51" id="Sample51">Sample 51: MTOM and SwA optimizations and request/response correlation</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;in&gt;
        &lt;filter source=&quot;get-property('Action')&quot; regex=&quot;urn:uploadFileUsingMTOM&quot;&gt;
            &lt;property name=&quot;example&quot; value=&quot;mtom&quot;/&gt;
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;address uri=&quot;http://localhost:9000/services/MTOMSwASampleService&quot; optimize=&quot;mtom&quot;/&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
        &lt;/filter&gt;
        &lt;filter source=&quot;get-property('Action')&quot; regex=&quot;urn:uploadFileUsingSwA&quot;&gt;
            &lt;property name=&quot;example&quot; value=&quot;swa&quot;/&gt;
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;address uri=&quot;http://localhost:9000/services/MTOMSwASampleService&quot; optimize=&quot;swa&quot;/&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
        &lt;/filter&gt;
    &lt;/in&gt;
    &lt;out&gt;
        &lt;filter source=&quot;get-property('example')&quot; regex=&quot;mtom&quot;&gt;
            &lt;property name=&quot;enableMTOM&quot; value=&quot;true&quot; scope=&quot;axis2&quot;/&gt;
        &lt;/filter&gt;
        &lt;filter source=&quot;get-property('example')&quot; regex=&quot;swa&quot;&gt;
            &lt;property name=&quot;enableSwA&quot; value=&quot;true&quot; scope=&quot;axis2&quot;/&gt;
        &lt;/filter&gt;
        &lt;send/&gt;
    &lt;/out&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: MTOM and SwA optimizations and request/response correlation</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Synapse configuration numbered 51: i.e. synapse -sample 51
<br/> Start the Axis2 server and deploy the MTOMSwASampleService if not already done </p>
<p>Execute the 'ant optimizeclient' specifying MTOM optimization as follows: </p>
<pre xml:space="preserve">ant optimizeclient -Dopt_mode=mtom</pre>
<p>The configuration now sets a local message context property, and forwards the message to 'http://localhost:9000/services/MTOMSwASampleService' optimizing binary content as MTOM. By sending this message through TCPMon you would be able to see the actual message sent over the HTTP transport if required. Thus during response processing, by checking the local message property Synapse could identify the past information about the current message context, and uses this knowledge to transform the response back to the client in the same format as the original request. </p>
<p>When the client executes successfully, it will upload a file containing the ASF logo and receive its response back again and saves it into a temporary file. </p>
<pre xml:space="preserve">[java] Sending file : ./../../repository/conf/sample/resources/mtom/asf-logo.gif as MTOM
[java] Saved response to file : ./../../work/temp/sampleClient/mtom-4417.gif</pre>
<p>Next try SwA as: </p>
<pre xml:space="preserve">ant optimizeclient -Dopt_mode=swa</pre>
<pre xml:space="preserve">[java] Sending file : ./../../repository/conf/sample/resources/mtom/asf-logo.gif as SwA
[java] Saved response to file : ./../../work/temp/sampleClient/swa-30391.gif</pre>
<p>By using TCPMon and sending the message through it, one can inspect that the requests and responses sent are indeed MTOM optimized or sent as HTTP attachments as follows: </p>
<pre xml:space="preserve">POST http://localhost:9000/services/MTOMSwASampleService HTTP/1.1
Host: 127.0.0.1
SOAPAction: urn:uploadFileUsingMTOM
Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177413845353; type=&quot;application/xop+xml&quot;;
start=&quot;&lt;0.urn:uuid:B94996494E1DD5F9B51177413845354@apache.org&gt;&quot;; start-info=&quot;text/xml&quot;; charset=UTF-8
Transfer-Encoding: chunked
Connection: Keep-Alive
User-Agent: Synapse-HttpComponents-NIO

--MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177413845353241
Content-Type: application/xop+xml; charset=UTF-8; type=&quot;text/xml&quot;
Content-Transfer-Encoding: binary
Content-ID:
   &lt;0.urn:uuid:B94996494E1DD5F9B51177413845354@apache.org&gt;221b1
      &lt;?xml version='1.0' encoding='UTF-8'?&gt;
         &lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
            &lt;soapenv:Body&gt;
               &lt;m0:uploadFileUsingMTOM xmlns:m0=&quot;http://www.apache-synapse.org/test&quot;&gt;
                  &lt;m0:request&gt;
                     &lt;m0:image&gt;
                        &lt;xop:Include href=&quot;cid:1.urn:uuid:78F94BC50B68D76FB41177413845003@apache.org&quot; xmlns:xop=&quot;http://www.w3.org/2004/08/xop/include&quot; /&gt;
                     &lt;/m0:image&gt;
                  &lt;/m0:request&gt;
               &lt;/m0:uploadFileUsingMTOM&gt;
            &lt;/soapenv:Body&gt;
         &lt;/soapenv:Envelope&gt;
--MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177413845353217
Content-Type: image/gif
Content-Transfer-Encoding: binary
Content-ID:
         &lt;1.urn:uuid:78F94BC50B68D76FB41177413845003@apache.org&gt;22800GIF89a... &lt;&lt; binary content &gt;&gt;</pre>
<pre xml:space="preserve">POST http://localhost:9000/services/MTOMSwASampleService HTTP/1.1
Host: 127.0.0.1
SOAPAction: urn:uploadFileUsingSwA
Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177414170491; type=&quot;text/xml&quot;;
start=&quot;&lt;0.urn:uuid:B94996494E1DD5F9B51177414170492@apache.org&gt;&quot;; charset=UTF-8
Transfer-Encoding: chunked
Connection: Keep-Alive
User-Agent: Synapse-HttpComponents-NIO

--MIMEBoundaryurn_uuid_B94996494E1DD5F9B51177414170491225
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID:
   &lt;0.urn:uuid:B94996494E1DD5F9B51177414170492@apache.org&gt;22159
      &lt;?xml version='1.0' encoding='UTF-8'?&gt;
         &lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
            &lt;soapenv:Body&gt;
               &lt;m0:uploadFileUsingSwA xmlns:m0=&quot;http://www.apache-synapse.org/test&quot;&gt;
                  &lt;m0:request&gt;
                     &lt;m0:imageId&gt;urn:uuid:15FD2DA2584A32BF7C1177414169826&lt;/m0:imageId&gt;
                  &lt;/m0:request&gt;
               &lt;/m0:uploadFileUsingSwA&gt;
            &lt;/soapenv:Body&gt;
         &lt;/soapenv:Envelope&gt;22--34MIMEBoundaryurn_uuid_B94996494E1DD5F9B511774141704912
17
Content-Type: image/gif
Content-Transfer-Encoding: binary
Content-ID:
         &lt;urn:uuid:15FD2DA2584A32BF7C1177414169826&gt;22800GIF89a... &lt;&lt; binary content &gt;&gt;</pre>
<h2>
<a name="Sample52" id="Sample52">Sample 52: Session less load balancing between 3 endpoints</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;sequence name=&quot;main&quot; onError=&quot;errorHandler&quot;&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;loadbalance&gt;
                        &lt;endpoint&gt;
                            &lt;address uri=&quot;http://localhost:9001/services/LBService1&quot;&gt;
                                &lt;enableAddressing/&gt;
                                &lt;suspendDurationOnFailure&gt;60&lt;/suspendDurationOnFailure&gt;
                            &lt;/address&gt;
                        &lt;/endpoint&gt;
                        &lt;endpoint&gt;
                            &lt;address uri=&quot;http://localhost:9002/services/LBService1&quot;&gt;
                                &lt;enableAddressing/&gt;
                                &lt;suspendDurationOnFailure&gt;60&lt;/suspendDurationOnFailure&gt;
                            &lt;/address&gt;
                        &lt;/endpoint&gt;
                        &lt;endpoint&gt;
                            &lt;address uri=&quot;http://localhost:9003/services/LBService1&quot;&gt;
                                &lt;enableAddressing/&gt;
                                &lt;suspendDurationOnFailure&gt;60&lt;/suspendDurationOnFailure&gt;
                            &lt;/address&gt;
                        &lt;/endpoint&gt;
                    &lt;/loadbalance&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;!-- Send the messages where they have been sent (i.e. implicit To EPR) --&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

    &lt;sequence name=&quot;errorHandler&quot;&gt;
        &lt;makefault response=&quot;true&quot;&gt;
            &lt;code value=&quot;tns:Receiver&quot; xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
            &lt;reason value=&quot;COULDN'T SEND THE MESSAGE TO THE SERVER.&quot;/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the simple load balancing among a set of endpoints</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Start Synapse with sample configuration 52. (i.e. synapse -sample 52)
<br/>Deploy the LoadbalanceFailoverService by switching to &lt;Synapse installation directory&gt;/samples/axis2Server/src/LoadbalanceFailoverService directory and running ant.
<br/>Start three instances of sample Axis2 server on HTTP ports 9001, 9002 and 9003 and give some unique names to each server.</p>
<p>Example commands to run sample Axis2 servers from the &lt;Synapse installation directory&gt;/samples/axis2Server directory in Linux are listed below: </p>
<pre xml:space="preserve">./axis2server.sh -http 9001 -https 9005 -name MyServer1
./axis2server.sh -http 9002 -https 9006 -name MyServer2
./axis2server.sh -http 9003 -https 9007 -name MyServer3</pre>
<p>Now we are done with setting up the environment for load balance sample. Start the load balance and failover client using the following command: </p>
<pre xml:space="preserve">ant loadbalancefailover -Di=100</pre>
<p>This client sends 100 requests to the LoadbalanceFailoverService through Synapse. Synapse will distribute the load among the three endpoints mentioned in the configuration in round-robin manner. LoadbalanceFailoverService appends the name of the server to the response, so that client can determine which server has processed the message. If you examine the console output of the client, you can see that requests are processed by three servers as follows: </p>
<pre xml:space="preserve">[java] Request: 1 ==&gt; Response from server: MyServer1
[java] Request: 2 ==&gt; Response from server: MyServer2
[java] Request: 3 ==&gt; Response from server: MyServer3
[java] Request: 4 ==&gt; Response from server: MyServer1
[java] Request: 5 ==&gt; Response from server: MyServer2
[java] Request: 6 ==&gt; Response from server: MyServer3
[java] Request: 7 ==&gt; Response from server: MyServer1
...</pre>
<p>Now run the client without the -Di=100 parameter to send infinite requests. While running the client shutdown the server named MyServer1. You can observe that requests are only distributed among MyServer2 and MyServer3 after shutting down MyServer1. Console output before and after shutting down MyServer1 is listed below (MyServer1 was shutdown after request 63): </p>
<pre xml:space="preserve">...
[java] Request: 61 ==&gt; Response from server: MyServer1
[java] Request: 62 ==&gt; Response from server: MyServer2
[java] Request: 63 ==&gt; Response from server: MyServer3
[java] Request: 64 ==&gt; Response from server: MyServer2
[java] Request: 65 ==&gt; Response from server: MyServer3
[java] Request: 66 ==&gt; Response from server: MyServer2
[java] Request: 67 ==&gt; Response from server: MyServer3
...</pre>
<p>Now restart MyServer1. You can observe that requests will be again sent to all three servers roughly after 60 seconds. This is because we have specified &lt;suspendDurationOnFailure&gt; as 60 seconds in the configuration. Therefore, load balance endpoint will suspend any failed child endpoint only for 60 seconds after detecting the failure. </p>
<h2>
<a name="Sample53" id="Sample53">Sample 53: Failover sending among 3 endpoints</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;sequence name=&quot;main&quot; onError=&quot;errorHandler&quot;&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;failover&gt;
                        &lt;endpoint&gt;
                            &lt;address uri=&quot;http://localhost:9001/services/LBService1&quot;&gt;
                                &lt;enableAddressing/&gt;
                                &lt;suspendDurationOnFailure&gt;60&lt;/suspendDurationOnFailure&gt;
                            &lt;/address&gt;
                        &lt;/endpoint&gt;
                        &lt;endpoint&gt;
                            &lt;address uri=&quot;http://localhost:9002/services/LBService1&quot;&gt;
                                &lt;enableAddressing/&gt;
                                &lt;suspendDurationOnFailure&gt;60&lt;/suspendDurationOnFailure&gt;
                            &lt;/address&gt;
                        &lt;/endpoint&gt;
                        &lt;endpoint&gt;
                            &lt;address uri=&quot;http://localhost:9003/services/LBService1&quot;&gt;
                                &lt;enableAddressing/&gt;
                                &lt;suspendDurationOnFailure&gt;60&lt;/suspendDurationOnFailure&gt;
                            &lt;/address&gt;
                        &lt;/endpoint&gt;
                    &lt;/failover&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;!-- Send the messages where they have been sent (i.e. implicit To EPR) --&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

    &lt;sequence name=&quot;errorHandler&quot;&gt;
        &lt;makefault response=&quot;true&quot;&gt;
            &lt;code value=&quot;tns:Receiver&quot; xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
            &lt;reason value=&quot;COULDN'T SEND THE MESSAGE TO THE SERVER.&quot;/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the failover sending</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Start Synapse with sample configuration 53 (i.e. synapse -sample 53)
<br/>Deploy the LoadbalanceFailoverService and start three instances of sample Axis2 server as mentioned in sample 52.</p>
<p>Above configuration sends messages with the failover behavior. Initially the server at port 9001 is treated as primary and other two are treated as backups. Messages are always directed only to the primary server. If the primary server has failed, next listed server is selected as the primary. Thus, messages are sent successfully as long as there is at least one active server. To test this, run the loadbalancefailover client to send infinite requests as follows: </p>
<pre xml:space="preserve">ant loadbalancefailover</pre>
<p>You can see that all requests are processed by MyServer1. Now shutdown MyServer1 and inspect the console output of the client. You will observe that all subsequent requests are processed by MyServer2. </p>
<p>The console output with MyServer1 shutdown after request 127 is listed below: </p>
<pre xml:space="preserve">...
[java] Request: 125 ==&gt; Response from server: MyServer1
[java] Request: 126 ==&gt; Response from server: MyServer1
[java] Request: 127 ==&gt; Response from server: MyServer1
[java] Request: 128 ==&gt; Response from server: MyServer2
[java] Request: 129 ==&gt; Response from server: MyServer2
[java] Request: 130 ==&gt; Response from server: MyServer2
...</pre>
<p>You can keep on shutting down servers like this. Client will get a response till you shutdown all listed servers. Once all servers are shutdown, the error sequence is activated and a fault message is sent to the client as follows. </p>
<pre xml:space="preserve">[java] COULDN'T SEND THE MESSAGE TO THE SERVER.</pre>
<p>Once a server is detected as failed, it will be added to the active servers list again after 60 seconds (specified in &lt;suspendDurationOnFailure&gt; in the configuration). Therefore, if you have restarted any of the stopped servers and have shutdown all other servers, messages will be directed to the newly started server. </p>
<h2>
<a name="Sample54" id="Sample54">Sample 54: Session affinity load balancing between 3 endpoints</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;sequence name=&quot;main&quot; onError=&quot;errorHandler&quot;&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;!-- specify the session as the simple client session provided by Synapse for
                    testing purpose --&gt;
                    
                    <strong>&lt;session type=&quot;simpleClientSession&quot;/&gt;</strong>

                    &lt;loadbalance&gt;
                        &lt;endpoint&gt;
                            &lt;address uri=&quot;http://localhost:9001/services/LBService1&quot;&gt;
                                &lt;enableAddressing/&gt;
                            &lt;/address&gt;
                        &lt;/endpoint&gt;
                        &lt;endpoint&gt;
                            &lt;address uri=&quot;http://localhost:9002/services/LBService1&quot;&gt;
                                &lt;enableAddressing/&gt;
                            &lt;/address&gt;
                        &lt;/endpoint&gt;
                        &lt;endpoint&gt;
                            &lt;address uri=&quot;http://localhost:9003/services/LBService1&quot;&gt;
                                &lt;enableAddressing/&gt;
                            &lt;/address&gt;
                        &lt;/endpoint&gt;
                    &lt;/loadbalance&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;!-- Send the messages where they have been sent (i.e. implicit To EPR) --&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

    &lt;sequence name=&quot;errorHandler&quot;&gt;
        &lt;makefault response=&quot;true&quot;&gt;
            &lt;code value=&quot;tns:Receiver&quot; xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
            &lt;reason value=&quot;COULDN'T SEND THE MESSAGE TO THE SERVER.&quot;/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the loadbalancing with session affinity using client initiated sessions</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Start Synapse with sample configuration 54 (i.e. synapse -sample 54).
<br/>Deploy the LoadbalanceFailoverService and start three instances of the sample Axis2 server as in sample 52. </p>

<p>Above configuration is same as the load balancing configuration in sample 52, except that the session type is specified as &quot;simpleClientSession&quot;. This is a client initiated session, which means that the client generates the session identifier and sends it with each request. In this sample session type, client adds a SOAP header named ClientID containing the identifier of the client. Synapse binds this ID with a server on the first request and sends all successive requests containing that ID to the same server. Now switch to samples/axis2Client directory and run the client using the following command to check this in action. </p>
<pre xml:space="preserve">ant loadbalancefailover -Dmode=session</pre>
<p>In the session mode, client continuously sends requests with three different client (session) IDs. One ID is selected among these three IDs for each request randomly. Then client prints the session ID with the responded server for each request. Client output for the first 10 requests are shown below. </p>
<pre xml:space="preserve">[java] Request: 1 Session number: 1 Response from server: MyServer3
[java] Request: 2 Session number: 2 Response from server: MyServer2
[java] Request: 3 Session number: 0 Response from server: MyServer1
[java] Request: 4 Session number: 2 Response from server: MyServer2
[java] Request: 5 Session number: 1 Response from server: MyServer3
[java] Request: 6 Session number: 2 Response from server: MyServer2
[java] Request: 7 Session number: 2 Response from server: MyServer2
[java] Request: 8 Session number: 1 Response from server: MyServer3
[java] Request: 9 Session number: 0 Response from server: MyServer1
[java] Request: 10 Session number: 0 Response from server: MyServer1
... </pre>
<p>You can see that session number 0 is always directed to the server named MyServer1. That means session number 0 is bound to MyServer1. Similarly session 1 and 2 are bound to MyServer3 and MyServer2 respectively. </p>
<h2>
<a name="Sample55" id="Sample55">Sample 55: Session affinity load balancing between fail over endpoints</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;sequence name=&quot;main&quot; onError=&quot;errorHandler&quot;&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;!-- specify the session as the simple client session provided by Synapse for
                    testing purpose --&gt;
                    
                    <strong>&lt;session type=&quot;simpleClientSession&quot;/&gt;</strong>

                    &lt;loadbalance&gt;
                        &lt;endpoint&gt;
                            &lt;failover&gt;
                                &lt;endpoint&gt;
                                    &lt;address uri=&quot;http://localhost:9001/services/LBService1&quot;&gt;
                                        &lt;enableAddressing/&gt;
                                    &lt;/address&gt;
                                &lt;/endpoint&gt;
                                &lt;endpoint&gt;
                                    &lt;address uri=&quot;http://localhost:9002/services/LBService1&quot;&gt;
                                        &lt;enableAddressing/&gt;
                                    &lt;/address&gt;
                                &lt;/endpoint&gt;
                            &lt;/failover&gt;
                        &lt;/endpoint&gt;
                        &lt;endpoint&gt;
                            &lt;failover&gt;
                                &lt;endpoint&gt;
                                    &lt;address uri=&quot;http://localhost:9003/services/LBService1&quot;&gt;
                                        &lt;enableAddressing/&gt;
                                    &lt;/address&gt;
                                &lt;/endpoint&gt;
                                &lt;endpoint&gt;
                                    &lt;address uri=&quot;http://localhost:9004/services/LBService1&quot;&gt;
                                        &lt;enableAddressing/&gt;
                                    &lt;/address&gt;
                                &lt;/endpoint&gt;
                            &lt;/failover&gt;
                        &lt;/endpoint&gt;
                    &lt;/loadbalance&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;!-- Send the messages where they have been sent (i.e. implicit To EPR) --&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

    &lt;sequence name=&quot;errorHandler&quot;&gt;
        &lt;makefault response=&quot;true&quot;&gt;
            &lt;code value=&quot;tns:Receiver&quot; xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
            &lt;reason value=&quot;COULDN'T SEND THE MESSAGE TO THE SERVER.&quot;/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the session affinity based load balancing with failover capability</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Start Synapse with sample configuration 55 (i.e. synapse -sample 55).
<br/>Deploy the LoadbalanceFailoverService and start four sample Axis2 servers on HTTP ports 9001, 9002, 9003 and 9004 respectively (make sure to specify non-conflicting HTTPS ports). </p>
<p>This configuration also uses &quot;simpleClientSession&quot; to bind sessions as in the previous sample. But failover endpoints are specified as the child endpoints of the load balance endpoint. Therefore sessions are bound to the failover endpoints. Session information has to be replicated among the servers listed under each failover endpoint using some clustering mechanism. Therefore, if one endpoint bound to a session failed, successive requets for that session will be directed to the next endpoint in that failover group. Run the client using the following command to observe this behaviour. </p>
<pre xml:space="preserve">ant loadbalancefailover -Dmode=session</pre>
<p>You can see a client output as shown below. </p>
<pre xml:space="preserve">...
[java] Request: 222 Session number: 0 Response from server: MyServer1
[java] Request: 223 Session number: 0 Response from server: MyServer1
[java] Request: 224 Session number: 1 Response from server: MyServer1
[java] Request: 225 Session number: 2 Response from server: MyServer3
[java] Request: 226 Session number: 0 Response from server: MyServer1
[java] Request: 227 Session number: 1 Response from server: MyServer1
[java] Request: 228 Session number: 2 Response from server: MyServer3
[java] Request: 229 Session number: 1 Response from server: MyServer1
[java] Request: 230 Session number: 1 Response from server: MyServer1
[java] Request: 231 Session number: 2 Response from server: MyServer3
...</pre>
<p>Note that session 0 is always directed to MyServer1 and session 1 is directed to MyServer3. No requests are directed to MyServer2 and MyServer4 as they are kept as backups by failover endpoints. Now shutdown the server named MyServer1 while running the sample. You will observe that all successive requests for session 0 is now directed to MyServer2, which is the backup server for MyServer1's group. This is shown below, where MyServer1 was shutdown after the request 534. </p>
<pre xml:space="preserve">...
[java] Request: 529 Session number: 2 Response from server: MyServer3
[java] Request: 530 Session number: 1 Response from server: MyServer1
[java] Request: 531 Session number: 0 Response from server: MyServer1
[java] Request: 532 Session number: 1 Response from server: MyServer1
[java] Request: 533 Session number: 1 Response from server: MyServer1
[java] Request: 534 Session number: 1 Response from server: MyServer1
[java] Request: 535 Session number: 0 Response from server: MyServer2
[java] Request: 536 Session number: 0 Response from server: MyServer2
[java] Request: 537 Session number: 0 Response from server: MyServer2
[java] Request: 538 Session number: 2 Response from server: MyServer3
[java] Request: 539 Session number: 0 Response from server: MyServer2
...</pre>
<h2>
<a name="Sample56" id="Sample56">Sample 56: WSDL endpoint</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;sequence name="main"&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;!-- get epr from the given wsdl --&gt;
                &lt;endpoint&gt;
                    &lt;wsdl uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"
                          service="SimpleStockQuoteService"
                          port="SimpleStockQuoteServiceHttpSoap11Endpoint"/&gt;
                &lt;/endpoint&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: Demonstrate the use of WSDL endpoints</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Start the Synapse configuration numbered 56 (i.e. synapse -sample 56).
<br/>Deploy the SimpleStockQuoteService and start the sample Axis2 server. </p>

<p>This sample uses a WSDL endpoint inside the send mediator. WSDL endpoints can extract endpoint's address from the given WSDL. As WSDL documents can have many services and many ports inside each service, the service and port of the required endpoint has to be specified. As with address endpoints, QoS parameters for the endpoint can be specified in-line in the configuration. An excerpt taken from the sample_proxy_1.wsdl containing the specified service and port is listed below. </p>
<pre xml:space="preserve">&lt;wsdl:service name="SimpleStockQuoteService"&gt;
    &lt;wsdl:port name="SimpleStockQuoteServiceHttpSoap11Endpoint" binding="ns:SimpleStockQuoteServiceSoap11Binding"&gt;
        &lt;soap:address location="http://localhost:9000/services/SimpleStockQuoteService.SimpleStockQuoteServiceHttpSoap11Endpoint"/&gt;
    &lt;/wsdl:port&gt;
    &lt;wsdl:port name="SimpleStockQuoteServiceHttpSoap12Endpoint" binding="ns:SimpleStockQuoteServiceSoap12Binding"&gt;
        &lt;soap12:address location="http://localhost:9000/services/SimpleStockQuoteService.SimpleStockQuoteServiceHttpSoap12Endpoint"/&gt;
    &lt;/wsdl:port&gt;
&lt;/wsdl:service&gt;</pre>
<p>Specified service and port refers to the endpoint address &quot;http://localhost:9000/services/SimpleStockQuoteService.SimpleStockQuoteServiceHttpSoap11Endpoint&quot; according to the above WSDL. Now run the client using the following command. </p>
<pre xml:space="preserve">ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280</pre>
<p>Client will print the quote price for IBM received from the server running on port 9000. Observe the Axis2 console and the Synapse console to verify this behavior. </p>
<h2>
<a name="Sample57" id="Sample57">Sample 57: Dynamic load balancing between 3 nodes</a></h2>
<pre xml:space="preserve">
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;sequence name=&quot;main&quot; onError=&quot;errorHandler&quot;&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;endpoint name=&quot;dynamicLB&quot;&gt;
                    &lt;dynamicLoadbalance failover=&quot;true&quot;
                                           algorithm=&quot;org.apache.synapse.endpoints.algorithms.RoundRobin&quot;&gt;
                        &lt;membershipHandler
                                class=&quot;org.apache.synapse.core.axis2.Axis2LoadBalanceMembershipHandler&quot;&gt;
                            &lt;property name=&quot;applicationDomain&quot; value=&quot;apache.axis2.app.domain&quot;/&gt;
                        &lt;/membershipHandler&gt;
                    &lt;/dynamicLoadbalance&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

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

    &lt;sequence name=&quot;errorHandler&quot;&gt;
        &lt;makefault response=&quot;true&quot;&gt;
            &lt;code value=&quot;tns:Receiver&quot; xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
            &lt;eason value=&quot;COULDN'T SEND THE MESSAGE TO THE SERVER.&quot;/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;
</pre>
<p>
<strong>Objective: Demonstrate the simple dynamic load balancing among a set of nodes</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Enable clustering and load balancing in the &lt;Synapse installation directory&gt;/ repository/conf/axis2.xml file. This can be done by setting the &quot;enable&quot; attribute of the &quot;cluster&quot; and &quot;loadBalancer&quot; elements. Also provide the IP address of you machine as the values of the &quot;mcastBindAddress&quot; and &quot;localMemberHost&quot; parameters.
<br/>Start Synapse with sample configuration 57. (i.e. synapse -sample 57)
<br/>Deploy the LoadbalanceFailoverService by switching to &lt;Synapse installation directory&gt;/samples/axis2Server/src/LoadbalanceFailoverService directory and running ant.
<br/>Enable clustering in the &lt;Synapse installation directory&gt;/samples/axis2Server/ repository/conf/axis2.xml file. This can be done by setting the &quot;enable&quot; attribute of the &quot;cluster&quot; element. Also provide the IP address of you machine as the values of the &quot;mcastBindAddress&quot; and &quot;localMemberHost&quot; parameters. Make sure that the "applicationDomain" of the membershipHandler is the same as the domain name specified in the axis2.xml files of the Axis2 servers. Then Start three instances of sample Axis2 server on HTTP ports 9001, 9002 and 9003 and give some unique names to each server.</p>
<p>Example commands to run sample Axis2 servers from the &lt;Synapse installation directory&gt;/samples/axis2Server directory in Linux are listed below: </p>
<pre xml:space="preserve">./axis2server.sh -http 9001 -https 9005 -name MyServer1
./axis2server.sh -http 9002 -https 9006 -name MyServer2
./axis2server.sh -http 9003 -https 9007 -name MyServer3</pre>
<p>Now we are done with setting up the environment for load balance sample. Start the load balance and failover client using the following command: </p>
<pre xml:space="preserve">ant loadbalancefailover -Di=100</pre>
<p>This client sends 100 requests to the LoadbalanceFailoverService through Synapse. Synapse will distribute the load among the three nodes mentioned in the configuration in a round-robin manner. LoadbalanceFailoverService appends the name of the server to the response, so that client can determine which server has processed the message. If you examine the console output of the client, you can see that requests are processed by three servers as follows: </p>
<pre xml:space="preserve">[java] Request: 1 ==&gt; Response from server: MyServer1
[java] Request: 2 ==&gt; Response from server: MyServer2
[java] Request: 3 ==&gt; Response from server: MyServer3
[java] Request: 4 ==&gt; Response from server: MyServer1
[java] Request: 5 ==&gt; Response from server: MyServer2
[java] Request: 6 ==&gt; Response from server: MyServer3
[java] Request: 7 ==&gt; Response from server: MyServer1
...</pre>
<p>Now run the client without the -Di=100 parameter, i.e. ant loadbalancefailover, to send infinite requests. While running the client shutdown the server named MyServer1. You can observe that requests are only distributed among MyServer2 and MyServer3 after shutting down MyServer1. Console output before and after shutting down MyServer1 is listed below (MyServer1 was shutdown after request 63): </p>
<pre xml:space="preserve">...
[java] Request: 61 ==&gt; Response from server: MyServer1
[java] Request: 62 ==&gt; Response from server: MyServer2
[java] Request: 63 ==&gt; Response from server: MyServer3
[java] Request: 64 ==&gt; Response from server: MyServer2
[java] Request: 65 ==&gt; Response from server: MyServer3
[java] Request: 66 ==&gt; Response from server: MyServer2
[java] Request: 67 ==&gt; Response from server: MyServer3
...</pre>
<p>Now restart MyServer1. You can observe that requests will be again sent to all three servers. </p>
<h2>
<a name="Sample58" id="Sample58">Sample 58: Static load balancing between 3 nodes</a></h2>
<pre xml:space="preserve">
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;sequence name=&quot;main&quot; onError=&quot;errorHandler&quot;&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;loadbalance failover=&quot;true&quot;&gt;
                        &lt;member hostName=&quot;127.0.0.1&quot; httpPort=&quot;9001&quot; httpsPort=&quot;9005&quot;/&gt;
                        &lt;member hostName=&quot;127.0.0.1&quot; httpPort=&quot;9002&quot; httpsPort=&quot;9006&quot;/&gt;
                        &lt;member hostName=&quot;127.0.0.1&quot; httpPort=&quot;9003&quot; httpsPort=&quot;9007&quot;/&gt;
                    &lt;/loadbalance&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

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

    &lt;sequence name=&quot;errorHandler&quot;&gt;
        &lt;makefault response=&quot;true&quot;&gt;
            &lt;code value=&quot;tns:Receiver&quot; xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
            &lt;reason value=&quot;COULDN'T SEND THE MESSAGE TO THE SERVER.&quot;/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;
</pre>
<p>
<strong>Objective: Demonstrate the simple static load balancing among a set of nodes</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Start Synapse with sample configuration 58. (i.e. synapse -sample 58)
<br/>Deploy the LoadbalanceFailoverService by switching to &lt;Synapse installation directory&gt;/samples/axis2Server/src/LoadbalanceFailoverService directory and running ant.
<br/>Start three instances of sample Axis2 server on HTTP ports 9001, 9002 and 9003 and give some unique names to each server. </p>
<p>Example commands to run sample Axis2 servers from the &lt;Synapse installation directory&gt;/samples/axis2Server directory in Linux are listed below: </p>
<pre xml:space="preserve">./axis2server.sh -http 9001 -https 9005 -name MyServer1
./axis2server.sh -http 9002 -https 9006 -name MyServer2
./axis2server.sh -http 9003 -https 9007 -name MyServer3</pre>
<p>Now we are done with setting up the environment for load balance sample. Start the load balance and failover client using the following command: </p>
<pre xml:space="preserve">ant loadbalancefailover -Di=100</pre>
<p>This client sends 100 requests to the LoadbalanceFailoverService through Synapse. Synapse will distribute the load among the three nodes mentioned in the configuration in a round-robin manner. LoadbalanceFailoverService appends the name of the server to the response, so that client can determine which server has processed the message. If you examine the console output of the client, you can see that requests are processed by three servers as follows: </p>
<pre xml:space="preserve">[java] Request: 1 ==&gt; Response from server: MyServer1
[java] Request: 2 ==&gt; Response from server: MyServer2
[java] Request: 3 ==&gt; Response from server: MyServer3
[java] Request: 4 ==&gt; Response from server: MyServer1
[java] Request: 5 ==&gt; Response from server: MyServer2
[java] Request: 6 ==&gt; Response from server: MyServer3
[java] Request: 7 ==&gt; Response from server: MyServer1
...</pre>
<p>Now run the client without the -Di=100 parameter, i.e. ant loadbalancefailover, to send infinite requests. While running the client shutdown the server named MyServer1. You can observe that requests are only distributed among MyServer2 and MyServer3 after shutting down MyServer1. Console output before and after shutting down MyServer1 is listed below (MyServer1 was shutdown after request 63): </p>
<pre xml:space="preserve">...
[java] Request: 61 ==&gt; Response from server: MyServer1
[java] Request: 62 ==&gt; Response from server: MyServer2
[java] Request: 63 ==&gt; Response from server: MyServer3
[java] Request: 64 ==&gt; Response from server: MyServer2
[java] Request: 65 ==&gt; Response from server: MyServer3
[java] Request: 66 ==&gt; Response from server: MyServer2
[java] Request: 67 ==&gt; Response from server: MyServer3
...</pre>
<p>Now restart MyServer1. You can observe that requests will be again sent to all three servers. </p>

<h2><a name="Sample60">Sample 60: Routing a message to a static list of recipients</a></h2>
<pre xml:space="preserve">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;sequence name="main" onError="errorHandler"&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;!--List of Recipients (static)--&gt; 
                    &lt;recipientlist&gt;
                        &lt;endpoint&gt;
                            &lt;address uri="http://localhost:9001/services/SimpleStockQuoteService"/&gt;
                        &lt;/endpoint&gt;
                        &lt;endpoint&gt;
                            &lt;address uri="http://localhost:9002/services/SimpleStockQuoteService"/&gt;
                        &lt;/endpoint&gt;
			&lt;endpoint&gt;
                            &lt;address uri="http://localhost:9003/services/SimpleStockQuoteService"/&gt;
                        &lt;/endpoint&gt;
                    &lt;/recipientlist&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;log level="full"/&gt;
            &lt;drop/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

    &lt;sequence name="errorHandler"&gt;
        &lt;makefault response="true"&gt;
            &lt;code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/&gt;
            &lt;reason value="COULDN'T SEND THE MESSAGE TO THE SERVER."/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;
</pre>
<p><strong>Objective: Demonstrate message routing to a set of
static endpoints</strong> </p>

<p><strong>Prerequisites:</strong> </p>

<p>Start ESB with sample configuration 60. (i.e. synapse -sample 60) </p>

<p>Deploy the SimpleStockQuoteService and start three instances of sample Axis2 server as mentioned in sample 52.</p>

<p>Above configuration routes a cloned copy of a message to each recipient defined within the static recipient list.
<br/>To test this, run the stockquote client to send an out-only message: </p>
<pre xml:space="preserve">ant stockquote -Dmode=placeorder -Dtrpurl=http://localhost:8280/</pre>

<p>This client sends a request to the SimpleStockQuoteService through the
ESB. ESB will create cloned copies of the message and route to the three endpoints
mentioned in the configuration. SimpleStockQuoteService prints the details of the placed
order. If you examine the console output of each server, you can see that requests are 
processed by the three servers as follows: </p>
<pre xml:space="preserve">Accepted order #1 for : 15738 stocks of IBM at $ 185.51155223506518
</pre>

<p>Now shutdown MyServer1 and resend the request. You will observe that requests are still processed by MyServer2 and MyServer3.</p>

<h2><a name="Sample61">Sample 61: Routing a message to a dynamic list of recipients</a></h2>
<pre xml:space="preserve">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;sequence name="main" onError="errorHandler"&gt;
        &lt;in&gt;
	    &lt;!--Dynamic Reclipient List--&gt;	
	    &lt;property name="EP_LIST" value="http://localhost:9001/services/SimpleStockQuoteService,
	        http://localhost:9002/services/SimpleStockQuoteService,
	        http://localhost:9003/services/SimpleStockQuoteService"/&gt;	
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;recipientlist&gt;
                        &lt;endpoints value="{get-property('EP_LIST')}"/&gt;
                    &lt;/recipientlist&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;log level="full"/&gt;
            &lt;drop/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

    &lt;sequence name="errorHandler"&gt;
        &lt;makefault response="true"&gt;
            &lt;code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/&gt;
            &lt;reason value="COULDN'T SEND THE MESSAGE TO THE SERVER."/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;
</pre>
<p><strong>Objective: Demonstrate message routing to a set of
dynamic endpoints</strong> </p>

<p><strong>Prerequisites:</strong> </p>

<p>Start ESB with sample configuration 61. (i.e. synapse -sample 61) </p>

<p>Deploy the SimpleStockQuoteService and start three instances of sample Axis2 server as mentioned in sample 52.</p>

<p>This sample does the same thing as in sample 60. The difference is that unlike in sample 60, this sample defines
the endpoints as a dynamic list of recipients. 
<br/>To test this, run the stockquote client to send an out-only message: </p>
<pre xml:space="preserve">ant stockquote -Dmode=placeorder -Dtrpurl=http://localhost:8280/</pre>

<p>The behaviour of this sample should be similar to that of sample 60</p>

<h2><a name="Sample62">Sample 62: Routing a message to a dynamic list of recipients and aggregating responses</a></h2>
<pre xml:space="preserve">
&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;sequence name="main" onError="errorHandler"&gt;
        &lt;in&gt;
	    &lt;!--Dynamic Recipient List--&gt;
	    &lt;property name="EP_LIST" value="http://localhost:9001/services/SimpleStockQuoteService,
	    http://localhost:9002/services/SimpleStockQuoteService,
	    http://localhost:9003/services/SimpleStockQuoteService"/&gt;	
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;recipientlist&gt;
                        &lt;endpoints value="{get-property('EP_LIST')}"/&gt;
                    &lt;/recipientlist&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;drop/&gt;
        &lt;/in&gt;

        &lt;out&gt;
	    &lt;log level="full"/&gt;
	    &lt;!--Aggregate responses--&gt;
            &lt;aggregate&gt; 
              &lt;onComplete xmlns:m0="http://services.samples"
                          expression="//m0:getQuoteResponse"&gt;
                 &lt;send/&gt;
	      &lt;/onComplete&gt;    		
	    &lt;/aggregate&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

    &lt;sequence name="errorHandler"&gt;
        &lt;makefault response="true"&gt;
            &lt;code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/&gt;
            &lt;reason value="COULDN'T SEND THE MESSAGE TO THE SERVER."/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;
</pre>
<p><strong>Objective: Demonstrate message routing to a set of
dynamic endpoints and aggregate responses</strong> </p>

<p><strong>Prerequisites:</strong> </p>

<p>Start ESB with sample configuration 62. (i.e. synapse -sample 62) </p>

<p>Deploy the SimpleStockQuoteService and start three instances of sample Axis2 server as mentioned in sample 52.</p>

<p>Above configuration routes a cloned copy of a message to each recipient defined within the dynamic recipient list. 
Each recipient will respond back with a stock quote. When all the responses appear to synapse those resonses will be 
aggregated to form the resultant response which will be sent back to the client.  
<br/>To test this, invoke the client as follows: </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/</pre>

<p>If you sent your client request through a TCP based conversation monitoring tool such as TCPMon, you will notice the 
structrue of the aggregated response message.</p>

<h1>
<a name="MessageMediationQoS" id="MessageMediationQoS">Quality of Service addition or deduction samples in message mediation</a> </h1>
<h2>
<a name="Sample100" id="Sample100">Sample 100: Using WS-Security for outgoing messages</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;localEntry key=&quot;sec_policy&quot; src=&quot;file:repository/conf/sample/resources/policy/policy_3.xml&quot;/&gt;

    &lt;in&gt;
        &lt;send&gt;
            &lt;endpoint name=&quot;secure&quot;&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SecureStockQuoteService&quot;&gt;
                    &lt;enableSec policy=&quot;sec_policy&quot;/&gt;
                &lt;/address&gt;
            &lt;/endpoint&gt;
        &lt;/send&gt;
    &lt;/in&gt;
    &lt;out&gt;
        &lt;header name=&quot;wsse:Security&quot; action=&quot;remove&quot;
                xmlns:wsse=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd&quot;/&gt;
        &lt;send/&gt;
    &lt;/out&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Connecting to endpoints with WS-Security for outgoing messages</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>You may also need to download and install the unlimited strength policy files for your JDK before using Apache Rampart (e.g. see http://java.sun.com/javase/downloads/index_jdk5.jsp)
<br/>Start the Synapse configuration numbered 100: i.e. synapse -sample 100
<br/>Start the Axis2 server and deploy the SecureStockQuoteService if not already done</p>

<p>Use the stock quote client to send a request without WS-Security. Synapse is configured to enable WS-Security as per the policy specified by 'policy_3.xml' for the outgoing messages to the SecureStockQuoteService endpoint hosted on the Axis2 instance. The debug log messages on Synapse shows the encrypted message flowing to the service and the encrypted response being received by Synapse. The wsse:Security header is then removed from the decrypted message and the response is delivered back to the client, as expected. You may execute the client as follows: </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/</pre>
<p>The message sent by Synapse to the secure service can be seen as follows, when TCPMon is used. </p>
<pre xml:space="preserve">POST http://localhost:9001/services/SecureStockQuoteService HTTP/1.1
Host: 127.0.0.1
SOAPAction: urn:getQuote
Content-Type: text/xml; charset=UTF-8
Transfer-Encoding: chunked
Connection: Keep-Alive
User-Agent: Synapse-HttpComponents-NIO

800
&lt;?xml version='1.0' encoding='UTF-8'?&gt;
   &lt;soapenv:Envelope xmlns:xenc=&quot;http://www.w3.org/2001/04/xmlenc#&quot; xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot; ..&gt;
      &lt;soapenv:Header&gt;
         &lt;wsse:Security ..&gt;
            &lt;wsu:Timestamp ..&gt;
               ...
            &lt;/wsu:Timestamp&gt;
            &lt;xenc:EncryptedKey..&gt;
               ...
            &lt;/xenc:EncryptedKey&gt;
            &lt;wsse:BinarySecurityToken ...&gt;
               &lt;ds:SignedInfo&gt;
               ...
               &lt;/ds:SignedInfo&gt;
               &lt;ds:SignatureValue&gt;
               ...
               &lt;/ds:SignatureValue&gt;
               &lt;ds:KeyInfo Id=&quot;KeyId-29551621&quot;&gt;
                  ...
               &lt;/ds:KeyInfo&gt;
            &lt;/ds:Signature&gt;
         &lt;/wsse:Security&gt;
         &lt;wsa:To&gt;http://localhost:9001/services/SecureStockQuoteService&lt;/wsa:To&gt;
         &lt;wsa:MessageID&gt;urn:uuid:1C4CE88B8A1A9C09D91177500753443&lt;/wsa:MessageID&gt;
         &lt;wsa:Action&gt;urn:getQuote&lt;/wsa:Action&gt;
      &lt;/soapenv:Header&gt;
      &lt;soapenv:Body xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot; wsu:Id=&quot;Id-3789605&quot;&gt;
         &lt;xenc:EncryptedData Id=&quot;EncDataId-3789605&quot; Type=&quot;http://www.w3.org/2001/04/xmlenc#Content&quot;&gt;
            &lt;xenc:EncryptionMethod Algorithm=&quot;http://www.w3.org/2001/04/xmlenc#aes256-cbc&quot; /&gt;
            &lt;xenc:CipherData&gt;
                &lt;xenc:CipherValue&gt;Layg0xQcnH....6UKm5nKU6Qqr&lt;/xenc:CipherValue&gt;
            &lt;/xenc:CipherData&gt;
         &lt;/xenc:EncryptedData&gt;
      &lt;/soapenv:Body&gt;
   &lt;/soapenv:Envelope&gt;0</pre>

<h2>
<a name="Sample101" id="Sample101">Sample 101: Reliable message exchange between Synapse and the back-end server using WS-ReliableMessaging</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;in&gt;
        &lt;RMSequence single=&quot;true&quot; version=&quot;1.0&quot;/&gt;
        &lt;send&gt;
           &lt;endpoint name=&quot;reliable&quot;&gt;
              &lt;address uri=&quot;http://localhost:9000/services/ReliableStockQuoteService&quot;&gt;
                 &lt;enableRM/&gt;
                 &lt;enableAddressing/&gt;
              &lt;/address&gt;
           &lt;/endpoint&gt;
        &lt;/send&gt;
    &lt;/in&gt;
    &lt;out&gt;
        &lt;header name=&quot;wsrm:SequenceAcknowledgement&quot; action=&quot;remove&quot;
                xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;/&gt;
        &lt;header name=&quot;wsrm:Sequence&quot; action=&quot;remove&quot;
                xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;/&gt;
        &lt;send/&gt;
    &lt;/out&gt;

&lt;/definitions&gt;</pre>
<strong>Objective: Demonstrate the message exchange between Synapse and the server using WS-ReliableMessaging (WS-RM)</strong>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the ReliableStockQuoteService in the sample Axis2 server by switching to the samples/axis2Server/src/ReliableStockQuoteService directory and running the command 'ant'.
<br/>Start the sample Axis2 server on port 9000.
<br/>Start Synapse with the sample configuration 101 (i.e. synapse -sample 101).</p>

<p>In the above configuration, WS-RM is engaged to the endpoint using the &lt;enableRM/&gt; tag. It is possible to engage WS-RM to both Address and WSDL endpoints using this tag. In addition to the RM enabled endpoint, RMSequence mediator is specified before the send mediator. This mediator is used to specify the set of messages to be sent using a single RM sequence. In this sample it is specified as single message per sequence. It also specifies the version of the WS-RM to be used. Refer to the Synapse configuration language documentation for more information about the RMSequence mediator. RM related SOAP headers are removed form the message in the out mediator as WS-RM message exchange takes place only between the Synapse and the server. Now run the sample client using the following command. </p>
<pre xml:space="preserve">ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280</pre>
<p>You can observe the client output displaying the quote price for IBM as follows: </p>
<pre xml:space="preserve">[java] Standard :: Stock price = $189.2521262517493</pre>
<p>There is no difference to be observed between the normal message exchange and WS-RM enabled message exchange as far as client and server outputs are considered. But if you look at the wire level messages, you would observe additional WS-RM messages and WS-RM elements. Synapse, the initiator of the RM sequence, first try to create a sequence by sending a message with CreateSequence element. </p>
<pre xml:space="preserve">...
&lt;soapenv:Body&gt;
   &lt;wsrm:CreateSequence xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;&gt;
      &lt;wsrm:AcksTo&gt;
         &lt;wsa:Address&gt;http://www.w3.org/2005/08/addressing/anonymous&lt;/wsa:Address&gt;
      &lt;/wsrm:AcksTo&gt;
      &lt;wsrm:Offer&gt;
         &lt;wsrm:Identifier&gt;urn:uuid:546F6F33FB7D8BBE351179807372769&lt;/wsrm:Identifier&gt;
      &lt;/wsrm:Offer&gt;
   &lt;/wsrm:CreateSequence&gt;
&lt;/soapenv:Body&gt;
...</pre>
<p>Sample Axis2 server responds to CreateSequence request with the following message: </p>
<pre xml:space="preserve">...
&lt;soapenv:Body&gt;
   &lt;wsrm:CreateSequenceResponse xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;&gt;
      &lt;wsrm:Identifier&gt;urn:uuid:879853A6871A66641C1179807373270&lt;/wsrm:Identifier&gt;
      &lt;wsrm:Accept&gt;
         &lt;wsrm:AcksTo&gt;
            &lt;wsa:Address&gt;http://localhost:9000/services/ReliableStockQuoteService&lt;/wsa:Address&gt;
         &lt;/wsrm:AcksTo&gt;
      &lt;/wsrm:Accept&gt;
   &lt;/wsrm:CreateSequenceResponse&gt;
&lt;/soapenv:Body&gt;
...</pre>
<p>Once the sequence is established, Synapse sends the request to the server with the pre-negotiated sequence ID. </p>
<pre xml:space="preserve">&lt;soapenv:Envelope xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;
                  xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
    &lt;soapenv:Header&gt;
        &lt;wsa:To&gt;http://localhost:9000/services/ReliableStockQuoteService&lt;/wsa:To&gt;
        &lt;wsa:MessageID&gt;urn:uuid:DB9A5257B637DDA38B1179807372560712002-1515891720&lt;/wsa:MessageID&gt;
        &lt;wsa:Action&gt;urn:getQuote&lt;/wsa:Action&gt;
        &lt;wsrm:Sequence xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;
                       soapenv:mustUnderstand=&quot;1&quot;&gt;
            &lt;wsrm:Identifier&gt;urn:uuid:879853A6871A66641C1179807373270&lt;/wsrm:Identifier&gt;
            &lt;wsrm:MessageNumber&gt;1&lt;/wsrm:MessageNumber&gt;
            &lt;wsrm:LastMessage/&gt;
        &lt;/wsrm:Sequence&gt;
    &lt;/soapenv:Header&gt;
    &lt;soapenv:Body&gt;
        &lt;m0:getQuote xmlns:m0=&quot;http://services.samples/xsd&quot;&gt;
            &lt;m0:request&gt;
                &lt;m0:symbol&gt;IBM&lt;/m0:symbol&gt;
            &lt;/m0:request&gt;
        &lt;/m0:getQuote&gt;
    &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</pre>
<p>Synapse keeps on sending above message till the server responds with a valid response message with 200 OK HTTP header. If the server is not ready with a response, it will respond with 202 Accepted HTTP header for all requests. Once the server is ready with a response it will send the response message with sequence ID as follows. </p>
<pre xml:space="preserve">&lt;soapenv:Envelope xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;
                  xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
    &lt;soapenv:Header&gt;
        &lt;wsa:MessageID&gt;urn:uuid:879853A6871A66641C1179807373804&lt;/wsa:MessageID&gt;
        &lt;wsa:Action&gt;http://services.samples/ReliableStockQuoteServicePortType/getQuoteResponse
        &lt;/wsa:Action&gt;
        &lt;wsa:RelatesTo&gt;urn:uuid:DB9A5257B637DDA38B1179807372560712002-1515891720&lt;/wsa:RelatesTo&gt;
        &lt;wsrm:Sequence xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;
                       soapenv:mustUnderstand=&quot;1&quot;&gt;
            &lt;wsrm:Identifier&gt;urn:uuid:546F6F33FB7D8BBE351179807372769&lt;/wsrm:Identifier&gt;
            &lt;wsrm:MessageNumber&gt;1&lt;/wsrm:MessageNumber&gt;
            &lt;wsrm:LastMessage/&gt;
        &lt;/wsrm:Sequence&gt;
        &lt;wsrm:SequenceAcknowledgement xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;
                                      soapenv:mustUnderstand=&quot;1&quot;&gt;
            &lt;wsrm:Identifier&gt;urn:uuid:879853A6871A66641C1179807373270&lt;/wsrm:Identifier&gt;
            &lt;wsrm:AcknowledgementRange Lower=&quot;1&quot; Upper=&quot;1&quot;/&gt;
        &lt;/wsrm:SequenceAcknowledgement&gt;
    &lt;/soapenv:Header&gt;
    &lt;soapenv:Body&gt;
        &lt;ns:getQuoteResponse xmlns:ns=&quot;http://services.samples/xsd&quot;&gt;
...</pre>
<p>Now both Synapse and the server are done with the actual message exchange. Then Synapse sends a request to terminate the sequence as follows: </p>
<pre xml:space="preserve">&lt;soapenv:Envelope xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;
                  xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
    &lt;soapenv:Header&gt;
        &lt;wsa:To&gt;http://localhost:9000/services/ReliableStockQuoteService&lt;/wsa:To&gt;
        &lt;wsa:MessageID&gt;urn:uuid:546F6F33FB7D8BBE351179807379591&lt;/wsa:MessageID&gt;
        &lt;wsa:Action&gt;http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence&lt;/wsa:Action&gt;
        &lt;wsrm:SequenceAcknowledgement xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;
                                      soapenv:mustUnderstand=&quot;1&quot;&gt;
            &lt;wsrm:Identifier&gt;urn:uuid:546F6F33FB7D8BBE351179807372769&lt;/wsrm:Identifier&gt;
            &lt;wsrm:AcknowledgementRange Lower=&quot;1&quot; Upper=&quot;1&quot;/&gt;
        &lt;/wsrm:SequenceAcknowledgement&gt;
    &lt;/soapenv:Header&gt;
    &lt;soapenv:Body&gt;
        &lt;wsrm:TerminateSequence xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;&gt;
            &lt;wsrm:Identifier&gt;urn:uuid:879853A6871A66641C1179807373270&lt;/wsrm:Identifier&gt;
        &lt;/wsrm:TerminateSequence&gt;
    &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</pre>
<p>Server responds to the sequence termination message, accepting to terminate the sequence as follows. </p>
<pre xml:space="preserve">&lt;soapenv:Envelope xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;
                  xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
    &lt;soapenv:Header&gt;
        &lt;wsa:ReplyTo&gt;
            &lt;wsa:Address&gt;http://localhost:9000/services/ReliableStockQuoteService&lt;/wsa:Address&gt;
        &lt;/wsa:ReplyTo&gt;
        &lt;wsa:MessageID&gt;urn:uuid:879853A6871A66641C1179807380190&lt;/wsa:MessageID&gt;
        &lt;wsa:Action&gt;http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence&lt;/wsa:Action&gt;
    &lt;/soapenv:Header&gt;
    &lt;soapenv:Body&gt;
        &lt;wsrm:TerminateSequence xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;&gt;
            &lt;wsrm:Identifier&gt;urn:uuid:546F6F33FB7D8BBE351179807372769&lt;/wsrm:Identifier&gt;
        &lt;/wsrm:TerminateSequence&gt;
    &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</pre>
<p>Note that although each of above messages are separate SOAP messages, in most cases they will be exchanged in a single socket connection as HTTP Keep-Alive header is used. </p>
<h1>
<a name="ProxyServices" id="ProxyServices">Synapse Proxy service samples</a> </h1>

<h2>
<a name="Sample150" id="Sample150">Sample 150: Introduction to proxy services</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot;&gt;
        &lt;target&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
            &lt;/endpoint&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Introduction to Synapse proxy services</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Synapse configuration numbered 150: i.e. synapse -sample 150
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>
<p>Once Synapse starts, you could go to http://localhost:8280/services/StockQuoteProxy?wsdl and view the WSDL generated for the proxy service defined in the configuration. This WSDL is based on the source WSDL supplied in the proxy service definition, and is updated to reflect the proxy service EPR. </p>
<p>Execute the stock quote client by requesting for a stock quote on the proxy service as follows: </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy</pre>
<p>An 'inSequence' or 'endpoint' or both of these would decide how the message would be handled after the proxy service receives the message. In the above example, the request received is forwarded to the sample service hosted on Axis2. The 'outSequence' defines how the response is handled before it is sent back to the client. By default, a proxy service is exposed over all transports configured for Synapse, unless these are specifically mentioned through the 'transports' attribute. </p>
<h2>
<a name="Sample151" id="Sample151">Sample 151: Custom sequences and endpoints with proxy services</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;sequence name=&quot;proxy_1&quot;&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;/sequence&gt;
    &lt;sequence name=&quot;out&quot;&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;
    &lt;endpoint name=&quot;proxy_2_endpoint&quot;&gt;
        &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
    &lt;/endpoint&gt;
    &lt;localEntry key=&quot;proxy_wsdl&quot; src=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;

    &lt;proxy name=&quot;StockQuoteProxy1&quot;&gt;
        &lt;publishWSDL key=&quot;proxy_wsdl&quot;/&gt;
        &lt;target inSequence=&quot;proxy_1&quot; outSequence=&quot;out&quot;/&gt;
    &lt;/proxy&gt;

    &lt;proxy name=&quot;StockQuoteProxy2&quot;&gt;
        &lt;publishWSDL key=&quot;proxy_wsdl&quot;/&gt;
        &lt;target endpoint=&quot;proxy_2_endpoint&quot; outSequence=&quot;out&quot;/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Using custom sequences and endpoints for message mediation with proxy services</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Synapse configuration numbered 151: i.e. synapse -sample 151
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>

<p>This configuration creates two proxy services. The first proxy service 'StockQuoteProxy1' uses the sequence named 'proxy_1' to process incoming messages and the sequence named &quot;out&quot; to process outgoing responses. The second proxy service 'StockQuoteProxy2' is set to directly forward messages that are received to the endpoint named 'proxy_2_endpoint' without any mediation. </p>
<p>You could send a stock quote request to each of these proxy services and receive the reply generated by the actual service hosted on the Axis2 server instance. </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy1
<br/>ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy2</pre>
<h2>
<a name="Sample152" id="Sample152">Sample 152: Switching transports and message format from SOAP to REST/POX</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot; transports=&quot;https&quot;&gt;
        &lt;target&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot; format=&quot;pox&quot;/&gt;
            &lt;/endpoint&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Switching transports and message format from SOAP to REST/POX</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Synapse configuration numbered 152: i.e. synapse -sample 152
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>

<p>This configuration demonstrates how a proxy service could be exposed on a subset of available transports, and how it could switch from one transport to another. This example exposes the created proxy service only on HTTPS, and thus if the user tries to access it over HTTP, would result in a fault. </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuoteProxy
...
     [java] org.apache.axis2.AxisFault: The service cannot be found for the endpoint reference (EPR) /soap/StockQuoteProxy</pre>

<p>Accessing this over HTTPS (ant stockquote -Dtrpurl=https://localhost:8243/services/StockQuoteProxy) causes the proxy service to access the SimpleStockQuoteService on the sample Axis2 server using REST/POX. This could be seen if the message exchange was captured using TCPMon as follows. The REST/POX response is now transformed back into a SOAP message and returned to the client. </p>
<pre xml:space="preserve">POST http://localhost:9000/services/SimpleStockQuoteService HTTP/1.1
Host: 127.0.0.1
SOAPAction: urn:getQuote
Content-Type: application/xml; charset=UTF-8;action=&quot;urn:getQuote&quot;;
Transfer-Encoding: chunked
Connection: Keep-Alive
User-Agent: Synapse-HttpComponents-NIO

75
&lt;m0:getQuote xmlns:m0=&quot;http://services.samples/xsd&quot;&gt;
   &lt;m0:request&gt;
      &lt;m0:symbol&gt;IBM&lt;/m0:symbol&gt;
   &lt;/m0:request&gt;
&lt;/m0:getQuote&gt;</pre>
<pre xml:space="preserve">HTTP/1.1 200 OK
Content-Type: application/xml; charset=UTF-8;action=&quot;http://services.samples/SimpleStockQuoteServicePortType/getQuoteResponse&quot;;
Date: Tue, 24 Apr 2007 14:42:11 GMT
Server: Synapse-HttpComponents-NIO
Transfer-Encoding: chunked
Connection: Keep-Alive

2b3
&lt;ns:getQuoteResponse xmlns:ns=&quot;http://services.samples/xsd&quot;&gt;
   &lt;ns:return&gt;
      &lt;ns:change&gt;3.7730036841862384&lt;/ns:change&gt;
      &lt;ns:earnings&gt;-9.950236235550818&lt;/ns:earnings&gt;
      &lt;ns:high&gt;-80.23868444613285&lt;/ns:high&gt;
      &lt;ns:last&gt;80.50750970812187&lt;/ns:last&gt;
      &lt;ns:lastTradeTimestamp&gt;Tue Apr 24 20:42:11 LKT 2007&lt;/ns:lastTradeTimestamp&gt;
      &lt;ns:low&gt;-79.67368355714606&lt;/ns:low&gt;
      &lt;ns:marketCap&gt;4.502043663670823E7&lt;/ns:marketCap&gt;
      &lt;ns:name&gt;IBM Company&lt;/ns:name&gt;
      &lt;ns:open&gt;-80.02229531286982&lt;/ns:open&gt;
      &lt;ns:peRatio&gt;25.089295161182022&lt;/ns:peRatio&gt;
      &lt;ns:percentageChange&gt;4.28842665653824&lt;/ns:percentageChange&gt;
      &lt;ns:prevClose&gt;87.98107059692451&lt;/ns:prevClose&gt;
      &lt;ns:symbol&gt;IBM&lt;/ns:symbol&gt;
      &lt;ns:volume&gt;19941&lt;/ns:volume&gt;
   &lt;/ns:return&gt;&lt;/ns:getQuoteResponse&gt;</pre>

<h2>
<a name="Sample153" id="Sample153">Sample 153: Routing the messages arrived to a proxy service without processing the security headers</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;property name="preserveProcessedHeaders" value="true"/&gt;
                &lt;send&gt;
                    &lt;endpoint&gt;
                        &lt;address uri=&quot;http://localhost:9000/services/SecureStockQuoteService&quot;/&gt;
                    &lt;/endpoint&gt;
                &lt;/send&gt;
            &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Routing the messages arrived to a proxy service without processing the MustUnderstand headers (Security header)</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> You may also need to download and install the unlimited strength policy files for your JDK before using Apache Rampart (e.g. see http://java.sun.com/javase/downloads/index_jdk5.jsp)
<br/>Start the Synapse configuration numbered 153: i.e. synapse -sample 153
<br/> Start the Axis2 server and deploy the SecureStockQuoteService if not already done </p>

<p>The proxy service will receive secure messages with security headers which are MustUnderstand. But hence element 'engageSec' is not present in the proxy configuration Synapse will not engage that Apache Rampart on this proxy service. It is expected that an MustUnderstand failure exception on the AxisEngine would occur before the message arrives Synapse. But Synapse handles this message and gets it in by setting all the headers which are MustUnderstand and not processed to processed state. This will enable Synapse to route the messages without reading the Security headers (just routing the messages from client to service, both of which are secure). To execute the client, send a stock quote request to the proxy service, and sign and encrypt the request by specifying the client side security policy as follows: </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuoteProxy -Dpolicy=./../../repository/conf/sample/resources/policy/client_policy_3.xml</pre>
<p>By following through the debug logs or TCPMon output, you could see that the request received by the proxy service was signed and encrypted. Also, looking up the WSDL of the proxy service by requesting the URL http://localhost:8280/services/StockQuoteProxy?wsdl reveals the security policy attachments are not there and security is not engaged. When sending the message to the backend service, you could verify that the security headers were there as in the original message to Synapse from client, and that the response received does use WS-Security, and forwarded back to the client without any modification. You should note that this wont be a security hole because the message inside Synapse is signed and encrypted and can only be forwarded to a secure service to be useful. </p>
<h2>
<a name="Sample154" id="Sample154">Sample 154: Load Balancing with Proxy Services </a></h2>
<div>
<pre xml:space="preserve">   &lt;!-- A proxy service with a loadbalace endpoint --&gt;
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;LBProxy&quot; transports=&quot;https http&quot; startOnLoad=&quot;true&quot;&gt;
        &lt;target faultSequence=&quot;errorHandler&quot;&gt;
            &lt;inSequence&gt;
                &lt;send&gt;
                    &lt;endpoint&gt;
                        &lt;session type=&quot;simpleClientSession&quot;/&gt;
                        &lt;loadbalance algorithm=&quot;org.apache.synapse.endpoints.algorithms.RoundRobin&quot;&gt;
                            &lt;endpoint&gt;
                                &lt;address uri=&quot;http://localhost:9001/services/LBService1&quot;&gt;
                                    &lt;enableAddressing/&gt;
                                    &lt;suspendDurationOnFailure&gt;20&lt;/suspendDurationOnFailure&gt;
                                &lt;/address&gt;
                            &lt;/endpoint&gt;
                            &lt;endpoint&gt;
                                &lt;address uri=&quot;http://localhost:9002/services/LBService1&quot;&gt;
                                    &lt;enableAddressing/&gt;
                                    &lt;suspendDurationOnFailure&gt;20&lt;/suspendDurationOnFailure&gt;
                                &lt;/address&gt;
                            &lt;/endpoint&gt;
                            &lt;endpoint&gt;
                                &lt;address uri=&quot;http://localhost:9003/services/LBService1&quot;&gt;
                                    &lt;enableAddressing/&gt;
                                    &lt;suspendDurationOnFailure&gt;20&lt;/suspendDurationOnFailure&gt;
                                &lt;/address&gt;
                            &lt;/endpoint&gt;
                        &lt;/loadbalance&gt;
                    &lt;/endpoint&gt;
                &lt;/send&gt;
                &lt;drop/&gt;
            &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_2.wsdl&quot;/&gt;
    &lt;/proxy&gt;
    &lt;sequence name=&quot;errorHandler&quot;&gt;
        &lt;makefault response=&quot;true&quot;&gt;
            &lt;code value=&quot;tns:Receiver&quot; xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
            &lt;reason value=&quot;COULDN'T SEND THE MESSAGE TO THE SERVER.&quot;/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt; </pre>
<p>
<strong>Objective: Load Balancing with Proxy Services </strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Sample setup is same as LoadBalance endpoints (#53 to #54)
<br/>Start the Synapse configuration numbered 154: i.e. synapse -sample 154
<br/>Start the Axis2 server and deploy the SecureStockQuoteService if not already done </p>
<p>Run the client with </p>
<pre xml:space="preserve">  ant loadbalancefailover -Dmode=session -Dtrpurl=http://localhost:8280/services/LBProxy </pre>
<p>Functionality is similar to the sample #54. </p></div>
<h2>
<a name="Sample155" id="Sample155">Sample 155: Dual channel invocation on both client side and serverside of Synapse with Proxy Services</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot;&gt;
        &lt;target&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;&gt;
                    &lt;enableAddressing separateListener=&quot;true&quot;/&gt;
                &lt;/address&gt;
            &lt;/endpoint&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the dual channel invocation with Synapse proxy services</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Synapse configuration numbered 150: i.e. synapse -sample 155
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>

<p>This sample will show the action of the dual channel invocation within client and Synapse as well as within Synapse and the actual server. Note that if you want to enable dual channel invocation you need to set the separateListener attribute to true of the enableAddressing element of the endpoint. </p>
<p>Execute the stock quote client by requesting for a stock quote on a dual channel from the proxy service as follows: </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dmode=dualquote</pre>
<p>In the above example, the request received is forwarded to the sample service hosted on Axis2 and the endpoint specifies to enable addressing and do the invocation over a dual channel. If you observe this message flow by using a TCPmon, you could see that on the channel you send the request to Synapse the response has been written as an HTTP 202 Accepted, where as the real response from Synapse will come over a different channel which cannot be obsesrved unless you use tcpdump to dump all the TCP level messages. </p>
<p>At the same time you can observe the behaviour of the invocation between Synapse and the actual Axis2 service, where you can see a 202 Accepted message being delivered to Synapse as the response to the request. The actual response will be delivered to Synapse over a different channel. </p>
<h1>
<a name="ProxyServiceQoS" id="ProxyServiceQoS">QoS addition and deduction for service mediation (proxy) samples</a> </h1>
<h2>
<a name="Sample200" id="Sample200">Sample 200: Using WS-Security with policy attachments for proxy services</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;localEntry key=&quot;sec_policy&quot; src=&quot;file:repository/conf/sample/resources/policy/policy_3.xml&quot;/&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;header name=&quot;wsse:Security&quot; action=&quot;remove&quot;
                        xmlns:wsse=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd&quot;/&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;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
        &lt;policy key=&quot;sec_policy&quot;/&gt;
        &lt;enableSec/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Using WS-Security signing and encryption with proxy services through WS-Policy</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> You may also need to download and install the unlimited strength policy files for your JDK before using Apache Rampart (e.g. see http://java.sun.com/javase/downloads/index_jdk5.jsp) </p>
<p>Start the Synapse configuration numbered 200: i.e. synapse -sample 200
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>

<p>The proxy service expects to receive a signed and encrypted message as specified by the security policy. Please see Apache Rampart and Axis2 documentation on the format of the policy file. The element 'engageSec' specifies that Apache Rampart should be engaged on this proxy service. Hence if Rampart rejects any request messages that does not conform to the specified policy, those messages will never reach the 'inSequence' to be processed. Since the proxy service is forwarding the received request to the simple stock quote service that does not use WS-Security, we are instructing Synapse to remove the wsse:Security header from the outgoing message. To execute the client, send a stock quote request to the proxy service, and sign and encrypt the request by specifying the client side security policy as follows: </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuoteProxy -Dpolicy=./../../repository/conf/sample/resources/policy/client_policy_3.xml</pre>
<p>By following through the debug logs or TCPMon output, you could see that the request received by the proxy service was signed and encrypted. Also, looking up the WSDL of the proxy service by requesting the URLhttp://localhost:8280/services/StockQuoteProxy?wsdl reveals the security policy attachment to the supplied base WSDL. When sending the message to the backend service, you could verify that the security headers were removed, and that the response received does not use WS-Security, but that the response being forwarded back to the client is signed and encrypted as expected by the client. </p>
<h2>
<a name="Sample201" id="Sample201">Sample 201: Reliable message exchange between the client and proxy services using WS-ReliableMessaging</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;header name=&quot;wsrm:SequenceAcknowledgement&quot; action=&quot;remove&quot;
                        xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;/&gt;
                &lt;header name=&quot;wsrm:Sequence&quot; action=&quot;remove&quot;
                        xmlns:wsrm=&quot;http://schemas.xmlsoap.org/ws/2005/02/rm&quot;/&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;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
        &lt;enableRM/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<strong>Objective: Demonstrate the reliable message exchange between the client and Synapse using WS-ReliableMessaging (WS-RM)</strong>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in the sample Axis2 server and start it on port 9000.
<br/>Start Synapse with the sample configuration number 201 (i.e. synapse -sample 201). </p>

<p>In the above configuration, a proxy service is created with WS-RM enabled using the &lt;enableRM/&gt; tag. Therefore, this proxy service is capable of communicating with a WS-RM client. It also removes the WS-RM headers in the In Sequence before the message is sent to the backend server. This is required as the reliable messaging is applicable only between the client and Synapse. Now start the client with WS-RM as follows: </p>
<pre xml:space="preserve">ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dwsrm=true</pre>
<p>In this case, client sends a WS-RM enabled request to Synapse where Synapse sends normal request to the server. This can be observed by examining the wire level messages between the client and Synapse. These messages would be similar to the wire level messages shown in sample 101. Each message would perform a similar function to the messages discussed in sample 53. </p>

<h1>
<a name="Transport" id="Transport">Transport samples and switching transports</a> </h1>
<h2>
<a name="Sample250" id="Sample250">Sample 250: Introduction to switching transports - JMS to http/s</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;proxy name=&quot;StockQuoteProxy&quot; transports=&quot;jms&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot;/&gt;
            &lt;/inSequence&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
            &lt;/endpoint&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
        &lt;parameter name=&quot;transport.jms.ContentType&quot;&gt;
            &lt;rules&gt;
                &lt;jmsProperty&gt;contentType&lt;/jmsProperty&gt;
                &lt;default&gt;application/xml&lt;/default&gt;
            &lt;/rules&gt;
        &lt;/parameter&gt;
    &lt;/proxy&gt;

&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Introduction to switching transports with proxy services</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Axis2 server with the SimpleStockQuoteService deployed
<br/> Download, install and start a JMS server, and configure Synapse to listen on JMS (refer notes below)
<br/> Start the Synapse configuration numbered 250: i.e. synapse -sample 250</p>

<p> For this example we will use <a href="http://activemq.apache.org">Apache ActiveMQ</a> as the JMS provider.
Simply download the binary distribution, extract it and launch the startup script to start the JMS broker.</p>
<p>Now you have to enable the JMS transport receiver of Synapse. Start by deploying the ActiveMQ client
libraries into the Synapse runtime. Simply copy the following jars from the ActiveMQ distribution into
SYNAPSE_HOME/lib directory:</p>
<ul>
    <li>activemq-core.jar</li>
    <li>geronimo-j2ee_management.jar</li>
    <li>geronimo-jms.jar</li>
</ul>
<p>Now you need to add some entries into the axis2.xml file. For a default ActiveMQ v5.x installation, you may
uncomment the Axis2 transport listener configuration found at repository/conf/axis2.xml as </p>
<pre xml:space="preserve">&lt;transportReceiver name=&quot;jms&quot; class=&quot;org.apache.axis2.transport.jms.JMSListener&quot;&gt; ...</pre>

<p>Once you start the Synapse configuration and request for the WSDL of the proxy service (http://localhost:8280/services/StockQuoteProxy?wsdl)
you will notice that its exposed only on the JMS transport. This is because the configuration specified this requirement in the
proxy service definition. </p>
<p>Now lets send a stock quote request on JMS, using the dumb stock quote client as follows: </p>
<pre xml:space="preserve">ant jmsclient -Djms_type=pox -Djms_dest=dynamicQueues/StockQuoteProxy -Djms_payload=MSFT</pre>
<p>On the Synapse debug log you will notice that the JMS listener received the request message as: </p>
<pre xml:space="preserve">DEBUG -Proxy Service StockQuoteProxy received a new message...</pre>
<p>Now if you examine the console running the sample Axis2 server, you will see a message indicating that the server has accepted an order as follows: </p>
<pre xml:space="preserve">Accepted order for : 16517 stocks of MSFT at $ 169.14622538721846</pre>
<p>In this sample, the client sends the request message to the proxy service exposed over JMS in Synsape. Synapse forwards this message to the HTTP EPR of the simple stock quote service hosted on the sample Axis2 server.
Note that the operation is out-only and no response is sent back to the client. The transport.jms.ContentType property
is necessary to allow the JMS transport to determine the content type of incoming messages. With the given configuration
it will first try to read the content type from the 'contentType' message property and fall back to 'application/xml'
(i.e. POX) if this property is not set. Note that the JMS client used in this example doesn't send any content type information.</p>
<p>Note: It is possible to instruct a JMS proxy service to listen to an already existing destination without creating a new one. To do this, use the parameter elements on the proxy service definition to specify the destination and connection factory etc. </p>
<p>e.g. </p>
<pre xml:space="preserve">&lt;parameter name=&quot;transport.jms.Destination&quot;&gt;dynamicTopics/something.TestTopic&lt;/parameter&gt;</pre>
<h2>
<a name="Sample251" id="Sample251">Sample 251: Switching from http/s to JMS</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;proxy name=&quot;StockQuoteProxy&quot; transports=&quot;http&quot;&gt;
        &lt;target&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;amp;
                   java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;amp;java.naming.provider.url=tcp://localhost:61616&quot;/&gt;
            &lt;/endpoint&gt;
            &lt;inSequence&gt;
                &lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot;/&gt;
            &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;

&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate switching from HTTP to JMS</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Download, install and start a JMS server
<br/> Configure sample Axis2 server for JMS (refer notes below)
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService (see below)
<br/> Configure the Synase JMS transport (refer notes above - sample 250)
<br/> Start the Synapse configuration numbered 251: i.e. synapse -sample 251 </p>
    
<p>To switch from HTTP to JMS, edit the samples/axis2Server/repository/conf/axis2.xml for the sample Axis2 server and enable JMS (refer notes above), and restart the server. Now you can see that the simple stock quote service is available in both JMS and HTTP in the sample Axis2 server. To see this, point your browser to the WSDL of the service at http://localhost:9000/services/SimpleStockQuoteService?wsdl. JMS URL for the service is mentioned as below: </p>
<pre xml:space="preserve">jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=
QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;
java.naming.provider.url=tcp://localhost:61616</pre>
<p>You may also notice that the simple stock quote proxy service exposed in Synapse is now available only in HTTP as we have specified transport for that service as HTTP. To observe this, access the WSDL of stock quote proxy service at http://localhost:8280/services/StockQuoteProxy?wsdl. </p>
<p>This Synapse configuration creates a proxy service over HTTP and forwards received messages to the above EPR using JMS, and sends back the response to the client over HTTP once the simple stock quote service responds with the stock quote reply over JMS to the Synapse server. To test this, send a place order request to Synapse using HTTP as follows: </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dmode=placeorder -Dsymbol=MSFT</pre>
<p>The sample Axis2 server console will print a message indicating that it has accepted the order as follows: </p>
<pre xml:space="preserve">Accepted order for : 18406 stocks of MSFT at $ 83.58806051152119</pre>
<h2>
<a name="Sample252" id="Sample252">Sample 252: Pure text/binary and POX message support with JMS</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;sequence name=&quot;text_proxy&quot;&gt;
        &lt;log level=&quot;full&quot;/&gt;
        &lt;header name=&quot;Action&quot; value=&quot;urn:placeOrder&quot;/&gt;
        &lt;script language=&quot;js&quot;&gt;&lt;![CDATA[
            var args = mc.getPayloadXML().toString().split(&quot; &quot;);
            mc.setPayloadXML(
            &lt;placeOrder xmlns=&quot;http://services.samples&quot;&gt;
                &lt;order xmlns=&quot;http://services.samples/xsd&quot;&gt;
                    &lt;price&gt;{args[0]}&lt;/price&gt;
                    &lt;quantity&gt;{args[1]}&lt;/quantity&gt;
                    &lt;symbol&gt;{args[2]}&lt;/symbol&gt;
                &lt;/order&gt;
            &lt;/placeOrder&gt;);
        ]]&gt;&lt;/script&gt;
        &lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot;/&gt;
        &lt;log level=&quot;full&quot;/&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;/sequence&gt;

    &lt;sequence name=&quot;mtom_proxy&quot;&gt;
        &lt;log level=&quot;full&quot;/&gt;
        &lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot;/&gt;
        &lt;header name=&quot;Action&quot; value=&quot;urn:oneWayUploadUsingMTOM&quot;/&gt;
        &lt;send&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/MTOMSwASampleService&quot; optimize=&quot;mtom&quot;/&gt;
            &lt;/endpoint&gt;
        &lt;/send&gt;
    &lt;/sequence&gt;

    &lt;sequence name=&quot;pox_proxy&quot;&gt;
        &lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot;/&gt;
        &lt;header name=&quot;Action&quot; value=&quot;urn:placeOrder&quot;/&gt;
        &lt;send&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot; format=&quot;soap11&quot;/&gt;
            &lt;/endpoint&gt;
        &lt;/send&gt;
    &lt;/sequence&gt;

    &lt;sequence name=&quot;out&quot;&gt;
		&lt;send/&gt;
	&lt;/sequence&gt;

    &lt;proxy name=&quot;JMSFileUploadProxy&quot; transports=&quot;jms&quot;&gt;
        &lt;target inSequence=&quot;mtom_proxy&quot; outSequence=&quot;out&quot;/&gt;
        &lt;parameter name=&quot;transport.jms.ContentType&quot;&gt;
            &lt;rules&gt;
                &lt;bytesMessage&gt;application/octet-stream&lt;/bytesMessage&gt;
            &lt;/rules&gt;
        &lt;/parameter&gt;
        &lt;parameter name=&quot;Wrapper&quot;&gt;{http://services.samples/xsd}element&lt;/parameter&gt;
    &lt;/proxy&gt;
    &lt;proxy name=&quot;JMSTextProxy&quot; transports=&quot;jms&quot;&gt;
        &lt;target inSequence=&quot;text_proxy&quot; outSequence=&quot;out&quot;/&gt;
        &lt;parameter name=&quot;transport.jms.ContentType&quot;&gt;
            &lt;rules&gt;
                &lt;textMessage&gt;text/plain&lt;/textMessage&gt;
            &lt;/rules&gt;
        &lt;/parameter&gt;
        &lt;parameter name=&quot;Wrapper&quot;&gt;{http://services.samples/xsd}text&lt;/parameter&gt;
    &lt;/proxy&gt;
    &lt;proxy name=&quot;JMSPoxProxy&quot; transports=&quot;jms&quot;&gt;
        &lt;target inSequence=&quot;pox_proxy&quot; outSequence=&quot;out&quot;/&gt;
        &lt;parameter name=&quot;transport.jms.ContentType&quot;&gt;application/xml&lt;/parameter&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Pure POX/Text and Binary JMS Proxy services - including MTOM</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Configure JMS for Synapse (Refer notes)
<br/> Start the Synapse configuration numbered 252: i.e. synapse -sample 252
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService and the MTOMSwASampleService if not already done </p>

<p>This configuration creates three JMS proxy services named JMSFileUploadProxy, JMSTextProxy and JMSPoxProxy exposed over JMS queues with the same names as the services. The first part of this example demonstrates the pure text message support with JMS, where a user sends a space separated text JMS message of the form &quot;&lt;price&gt; &lt;qty&gt; &lt;symbol&gt;&quot;. Synapse converts this message into a SOAP message and sends this to the SimpleStockQuoteServices' placeOrder operation. Synapse uses the script mediator to transform the text message into a XML payload using the JavaScript support available to tokenize the string. The proxy service property named &quot;Wrapper&quot; defines a custom wrapper element QName, to be used when wrapping text/binary content into a SOAP envelope. </p>

<p>Execute JMS client as follows. This will post a pure text JMS message with the content defined (e.g. &quot;12.33 1000 ACP&quot;) to the specified JMS destination - dynamicQueues/JMSTextProxy </p>
<pre xml:space="preserve">ant jmsclient -Djms_type=text -Djms_payload=&quot;12.33 1000 ACP&quot; -Djms_dest=dynamicQueues/JMSTextProxy</pre>
<p>Following the logs, you could notice that Synapse received the JMS text message and transformed it into a SOAP payload as follows. Notice that the wrapper element &quot;{http://services.samples/xsd}text&quot; has been used to hold the text message content. </p>
<pre xml:space="preserve">INFO - To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: ID:orcus.veithen.net-50631-1225235276233-1:0:1:1:1, Direction: request,
Envelope:
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
  &lt;soapenv:Body&gt;
    &lt;axis2ns1:text xmlns:axis2ns1=&quot;http://services.samples/xsd&quot;&gt;12.33 1000 ACP&lt;/axis2ns1:text&gt;
  &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</pre>
<p>Now, you could see how the script mediator created a stock quote request by tokenizing the text as follows, and sent the message to the placeOrder operation of the SimpleStockQuoteService. </p>
<pre xml:space="preserve">INFO - To: , WSAction: urn:placeOrder, SOAPAction: urn:placeOrder, MessageID: ID:orcus.veithen.net-50631-1225235276233-1:0:1:1:1, Direction: request,
Envelope:
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
  &lt;soapenv:Body&gt;
    &lt;placeOrder xmlns=&quot;http://services.samples&quot;&gt;
      &lt;order xmlns=&quot;http://services.samples/xsd&quot;&gt;
        &lt;price&gt;12.33&lt;/price&gt;
        &lt;quantity&gt;1000&lt;/quantity&gt;
        &lt;symbol&gt;ACP&lt;/symbol&gt;
      &lt;/order&gt;
    &lt;/placeOrder&gt;
  &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</pre>
<p>The sample Axis2 server would now accept the one-way message and issue the following message: </p>
<pre xml:space="preserve">samples.services.SimpleStockQuoteService :: Accepted order for : 1000 stocks of ACP at $ 12.33</pre>

<p>The next section of this example demonstrates how a pure binary JMS message could be received and processed through Synapse. The configuration creates a proxy service named 'JMSFileUploadProxy' that accepts binary messages and wraps them into a custom element '{http://services.samples/xsd}element'. The received message is then forwarded to the MTOMSwASampleService using the SOAP action 'urn:oneWayUploadUsingMTOM' and optimizing binary content using MTOM. To execute this sample, use the JMS client to publish a pure binary JMS message containing the file './../../repository/conf/sample/resources/mtom/asf-logo.gif' to the JMS destination 'dynamicQueues/JMSFileUploadProxy' as follows: </p>
<pre xml:space="preserve">ant jmsclient -Djms_type=binary -Djms_dest=dynamicQueues/JMSFileUploadProxy \
              -Djms_payload=./../../repository/conf/sample/resources/mtom/asf-logo.gif</pre>
<p>Examining the Synapse debug logs reveals that the binary content was received over JMS and wrapped with the specified element into a SOAP infoset as follows: </p>
<pre xml:space="preserve">INFO - To: , WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: ID:orcus.veithen.net-50702-1225236039556-1:0:1:1:1, Direction: request,
Envelope:
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
  &lt;soapenv:Body&gt;
    &lt;axis2ns1:element xmlns:axis2ns1=&quot;http://services.samples/xsd&quot;&gt;R0lGODlhgw...AAOw==&lt;/axis2ns1:element&gt;
  &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</pre>
<p>Thereafter the message was sent as a MTOM optimized message as specified by the 'format=mtom' attribute of the endpoint, to the MTOMSwASampleService using the SOAP action 'urn:oneWayUploadUsingMTOM'. Once received by the sample service, it is saved into a temporary file and could be verified for correctness. </p>
<pre xml:space="preserve">Wrote to file : ./../../work/temp/sampleServer/mtom-4417.gif</pre>

<p>The final section of this example shows how a POX JMS message received by Synapse is sent to the SimpleStockQuoteService as a SOAP message. Use the JMS client as follows to create a POX (Plain Old XML) message with a stock quote request payload (without a SOAP envelope), and send it to the JMS destination 'dynamicQueues/JMSPoxProxy' as follows: </p>
<pre xml:space="preserve">ant jmsclient -Djms_type=pox -Djms_dest=dynamicQueues/JMSPoxProxy -Djms_payload=MSFT</pre>
<p>Synapse converts the POX message into a SOAP payload and sends to the SimpleStockQuoteService after setting the SOAP action as 'urn:placeOrder'.
The sample Axis2 server displays a successful message on the receipt of the message as: </p>
<pre xml:space="preserve">samples.services.SimpleStockQuoteService :: Accepted order for : 19211 stocks of MSFT at $ 172.39703010684752</pre>
<h2>
<a name="Sample253" id="Sample253">Sample 253: One way bridging from JMS to http and replying with a 202 Accepted response</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;proxy name=&quot;JMStoHTTPStockQuoteProxy&quot; transports=&quot;jms&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot;/&gt;
            &lt;/inSequence&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
            &lt;/endpoint&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;

    &lt;proxy name=&quot;OneWayProxy&quot; transports=&quot;http&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;log level=&quot;full&quot;/&gt;
            &lt;/inSequence&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
            &lt;/endpoint&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;

&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate one-way message bridging from JMS to HTTP and replying with a HTTP 202 Accepted response</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done
<br/>Start the Synapse configuration numbered 253: i.e. synapse -sample 253 </p>

<p>This example invokes the one-way 'placeOrder' operation on the SimpleStockQuoteService using the Axis2 ServiceClient.fireAndForget() API at the client. To test this, use 'ant -Dmode=placeorder...' and you will notice the one-way JMS message flowing through Synapse into the sample Axis2 server instance over HTTP, and Axis2 acknowledging it with a HTTP 202 Accepted response. </p>
<pre xml:space="preserve">ant stockquote -Dmode=placeorder -Dtrpurl=&quot;jms:/JMStoHTTPStockQuoteProxy?\
transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory\
&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory\
&amp;java.naming.provider.url=tcp://localhost:61616\
&amp;transport.jms.ContentTypeProperty=Content-Type&amp;transport.jms.DestinationType=queue&quot;</pre>
<pre xml:space="preserve">SimpleStockQuoteService :: Accepted order for : 7482 stocks of IBM at $ 169.27205579038733</pre>
<p>The second example shows how Synapse could be made to respond with a HTTP 202 Accepted response to a request received. The proxy service simply logs the message received and acknowledges it. On the Synapse console you could see the logged message, and if TCPMon was used at the client, you would see the 202 Accepted response sent back to the client from Synapse </p>
<pre xml:space="preserve">ant stockquote -Dmode=placeorder -Dtrpurl=http://localhost:8280/services/OneWayProxy</pre>
<pre xml:space="preserve">HTTP/1.1 202 Accepted
Content-Type: text/xml; charset=UTF-8
Host: 127.0.0.1
SOAPAction: &quot;urn:placeOrder&quot;
Date: Sun, 06 May 2007 17:20:19 GMT
Server: Synapse-HttpComponents-NIO
Transfer-Encoding: chunked

0</pre>
<h2>
<a name="Sample254" id="Sample254">Sample 254: Using the file system as transport medium using VFS transport listener and sender</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot; transports=&quot;vfs&quot;&gt;
        &lt;parameter name=&quot;transport.vfs.FileURI&quot;&gt;file:///home/user/test/in&lt;/parameter&gt; &lt;!--CHANGE--&gt;
        &lt;parameter name=&quot;transport.vfs.ContentType&quot;&gt;text/xml&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.vfs.FileNamePattern&quot;&gt;.*\.xml&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.PollInterval&quot;&gt;15&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.vfs.MoveAfterProcess&quot;&gt;file:///home/user/test/original&lt;/parameter&gt; &lt;!--CHANGE--&gt;
        &lt;parameter name=&quot;transport.vfs.MoveAfterFailure&quot;&gt;file:///home/user/test/original&lt;/parameter&gt; &lt;!--CHANGE--&gt;
        &lt;parameter name=&quot;transport.vfs.ActionAfterProcess&quot;&gt;MOVE&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.vfs.ActionAfterFailure&quot;&gt;MOVE&lt;/parameter&gt;

        &lt;target&gt;
            &lt;endpoint&gt;
                &lt;address format=&quot;soap12&quot; uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
            &lt;/endpoint&gt;
            &lt;outSequence&gt;
                &lt;property name=&quot;transport.vfs.ReplyFileName&quot;
                          expression=&quot;fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.xml')&quot; scope=&quot;transport&quot;/&gt;
                &lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot;/&gt;
                &lt;send&gt;
                    &lt;endpoint&gt;
                        &lt;address uri=&quot;vfs:file:///home/user/test/out&quot;/&gt; &lt;!--CHANGE--&gt;
                    &lt;/endpoint&gt;
                &lt;/send&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Using the file system as transport medium using VFS transport listener and sender</strong> </p>

<p>
<strong>Prerequisites:</strong>
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done
<br/>Create three new directories in a test directory. e.g. in, out, original in /home/user/test. Open SYNAPSE_HOME/repository/conf/sample/synapse_sample_254.xml and edit the following values. Change transport.vfs.FileURI, transport.vfs.MoveAfterProcess, transport.vfs.MoveAfterFailure parameter values to the above in, original, original directories respectively. Change outSequence endpoint address uri to out directory with the prefix
<em>vfs:</em>. Values you have to change are marked with &lt;!--CHANGE--&gt;
<br/>Start the Synapse configuration numbered 254: i.e. synapse -sample 254 </p>

<p>Copy SYNAPSE_HOME/repository/conf/sample/resources/vfs/test.xml to the directory given in transport.vfs.FileURI above. </p>
<p>test.xml file content is as follows </p>
<pre xml:space="preserve">&lt;?xml version='1.0' encoding='UTF-8'?&gt;
    &lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;&gt;
    &lt;soapenv:Body&gt;
            &lt;m0:getQuote xmlns:m0=&quot;http://services.samples&quot;&gt;
                    &lt;m0:request&gt;
                            &lt;m0:symbol&gt;IBM&lt;/m0:symbol&gt;
                    &lt;/m0:request&gt;
            &lt;/m0:getQuote&gt;
    &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</pre>
<p>VFS transport listener will pick the file from 
<em>in</em> directory and send it to the Axis2 service. The request XML file will be moved to 
<em>original</em> directory. The response from the Axis2 server will be saved to 
<em>out</em> directory. </p>
<h2>
<a name="Sample255" id="Sample255">Sample 255: Switching from ftp transport listener to mail transport sender</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot; transports=&quot;vfs&quot;&gt;
            &lt;parameter name=&quot;transport.vfs.FileURI&quot;&gt;vfs:ftp://guest:guest@localhost/test?vfs.passive=true&lt;/parameter&gt; &lt;!--CHANGE--&gt;
            &lt;parameter name=&quot;transport.vfs.ContentType&quot;&gt;text/xml&lt;/parameter&gt;
            &lt;parameter name=&quot;transport.vfs.FileNamePattern&quot;&gt;.*\.xml&lt;/parameter&gt;
            &lt;parameter name=&quot;transport.PollInterval&quot;&gt;15&lt;/parameter&gt;

            &lt;target&gt;
                    &lt;inSequence&gt;
                            &lt;header name=&quot;Action&quot; value=&quot;urn:getQuote&quot;/&gt;
                    &lt;/inSequence&gt;
                    &lt;endpoint&gt;
                            &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
                    &lt;/endpoint&gt;
                    &lt;outSequence&gt;
                            &lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot;/&gt;
                            &lt;send&gt;
                                    &lt;endpoint&gt;
                                            &lt;address uri=&quot;mailto:user@host&quot;/&gt; &lt;!--CHANGE--&gt;
                                    &lt;/endpoint&gt;
                            &lt;/send&gt;
                    &lt;/outSequence&gt;
            &lt;/target&gt;
            &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt; </pre>
<p>
<strong>Objective: Switching from FTP transport listener to mail transport sender</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> You will need access to an FTP server and an SMTP server to try this sample. </p>
<p>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>
<p>Enable mail transport sender in the Synapse axis2.xml. See 
<a href="Synapse_Samples_Setup.html       #mailsender">Setting up mail transport sender</a> </p>
<p>Create a new test directory in the FTP server. Open SYNAPSE_HOME/repository/conf/sample/synapse_sample_116.xml and edit the following values. Change transport.vfs.FileURI parameter value point to the test directory at the FTP server. Change outSequence endpoint address uri email address to a working email address. Values you have to change are marked with &lt;!--CHANGE--&gt;. </p>
<p>Start the Synapse configuration numbered 255: i.e. synapse -sample 255 </p>
<p>Copy SYNAPSE_HOME/repository/conf/sample/resources/vfs/test.xml to the ftp directory given in transport.vfs.FileURI above. </p>
<p>VFS transport listener will pick the file from the directory in the FTP server and send it to the Axis2 service. The file in the FTP directory will be deleted. The response will be sent to the given email address. </p>
<h2>
<a name="Sample256" id="Sample256">Sample 256: Proxy services with the mail transport </a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot; transports=&quot;mailto&quot;&gt;

        &lt;parameter name=&quot;transport.mail.Address&quot;&gt;synapse.demo.1@gmail.com&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.mail.Protocol&quot;&gt;pop3&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.PollInterval&quot;&gt;5&lt;/parameter&gt;
        &lt;parameter name=&quot;mail.pop3.host&quot;&gt;pop.gmail.com&lt;/parameter&gt;
        &lt;parameter name=&quot;mail.pop3.port&quot;&gt;995&lt;/parameter&gt;
        &lt;parameter name=&quot;mail.pop3.user&quot;&gt;synapse.demo.1&lt;/parameter&gt;
        &lt;parameter name=&quot;mail.pop3.password&quot;&gt;mailpassword&lt;/parameter&gt;
        &lt;parameter name=&quot;mail.pop3.socketFactory.class&quot;&gt;javax.net.ssl.SSLSocketFactory&lt;/parameter&gt;
        &lt;parameter name=&quot;mail.pop3.socketFactory.fallback&quot;&gt;false&lt;/parameter&gt;
        &lt;parameter name=&quot;mail.pop3.socketFactory.port&quot;&gt;995&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.mail.ContentType&quot;&gt;application/xml&lt;/parameter&gt;

        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;property name=&quot;senderAddress&quot; expression=&quot;get-property(&quot;transport&quot;, &quot;From&quot;)&quot;/&gt;
                &lt;log level=&quot;full&quot;&gt;
                    &lt;property name=&quot;Sender Address&quot; expression=&quot;get-property(&quot;senderAddress&quot;)&quot;/&gt;
                &lt;/log&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;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;property name=&quot;Subject&quot; value=&quot;Custom Subject for Response&quot; scope=&quot;transport&quot;/&gt;
                &lt;header name=&quot;To&quot; expression=&quot;fn:concat(&quot;mailto:&quot;, get-property(&quot;senderAddress&quot;))&quot;/&gt;
                &lt;log level=&quot;full&quot;&gt;
                    &lt;property name=&quot;message&quot; value=&quot;Response message&quot;/&gt;
                    &lt;property name=&quot;Sender Address&quot; expression=&quot;get-property(&quot;senderAddress&quot;)&quot;/&gt;
                &lt;/log&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Using the mail transport with Proxy services</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> You will need access to an email account
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done
<br/>Enable mail transport sender in the Synapse axis2.xml. See
<a href="Synapse_Samples_Setup.html#mailsender">Setting up mail transport sender</a>
<br/>Start the Synapse configuration numbered 256: i.e. synapse -sample 256 </p>
<p>Send an email with the following body and any custom Subject from your mail account. </p>
<pre xml:space="preserve">&lt;getQuote xmlns=&quot;http://services.samples&quot;&gt;
   &lt;request xmlns=&quot;http://services.samples/xsd&quot;&gt;
       &lt;symbol&gt;IBM&lt;/symbol&gt;
   &lt;/request&gt;
&lt;/getQuote&gt;</pre>
<p>After a few seconds (e.g. 30s), you should receive a POX response in your email account with the stock quote reply. </p>
<p>Note that in this sample we used the <tt>transport.mail.ContentType</tt> property to make sure that the transport parses
the request message as POX. If you remove this property, you may still be able to send requests using a standard
mail client if instead of writing the XML in the body of the message, you add it as an attachment. In that case, you
should use <tt>.xml</tt> as a suffix for the attachment and format the request as a SOAP 1.1 message. Indeed,
for a file with suffix <tt>.xml</tt> the mail client will most likely use <tt>text/xml</tt> as the content type, exactly
as required for SOAP 1.1. Sending a POX message using this approach will be a lot trickier, because most standard
mail clients don't allow the user to explicitly set the content type.</p>
<h2>
<a name="Sample257" id="Sample257">Sample 257: Proxy services with the FIX transport </a></h2>
<pre xml:space="preserve">&lt;!-- Using the FIX transport --&gt;
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;FIXProxy&quot; transports=&quot;fix&quot;&gt;

        &lt;parameter name=&quot;transport.fix.AcceptorConfigURL&quot;&gt;file:/home/synapse_user/fix-config/fix-synapse.cfg&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.InitiatorConfigURL&quot;&gt;file:/home/synapse_user/fix-config/synapse-sender.cfg&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.AcceptorMessageStore&quot;&gt;file&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.InitiatorMessageStore&quot;&gt;file&lt;/parameter&gt;

        &lt;target&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;fix://localhost:19876?BeginString=FIX.4.0&amp;amp;SenderCompID=SYNAPSE&amp;amp;TargetCompID=EXEC&quot;/&gt;
            &lt;/endpoint&gt;
	    &lt;inSequence&gt;
		&lt;log level=&quot;full&quot;/&gt;
	    &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;log level=&quot;full&quot;/&gt;
		&lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt; </pre>
<p>
<strong>Objective: Demonstrate the usage of the FIX (Financial Information eXchange) transport with proxy services</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> You will need the two sample FIX applications that come with Quickfix/J (Banzai and Executor). Configure the two applications to establish sessions with Synapse. See
<a href="Synapse_Samples_Setup.html#fixsamplesconfig">Configuring Sample FIX Applications</a>
<br/>Start Banzai and Executor
<br/>Enable FIX transport in the Synapse axis2.xml. See
<a href="Synapse_Samples_Setup.html#fixtransport">Setting up FIX transport </a>
<br/>Configure Synapse for FIX samples. See
<a href="Synapse_Samples_Setup.html#fixsamples">Configuring Synapse for FIX Samples</a>
<br/>Open up the SYNAPSE_HOME/repository/conf/sample/synapse_sample_257.xml file and make sure that transport.fix.AcceptorConfigURL property points to the fix-synapse.cfg file you created. Also make sure that transport.fix. InitiatorConfigURL property points to the synapse-sender.cfg file you created. Once done you can start the Synapse configuration numbered 257: i.e. synapse -sample 257. Note that Synapse creates new FIX sessions with Banzai and Executor at this point. </p>
<p>Send an order request from Banzai to Synapse. </p>
<p>Synapse will forward the order request to the session with the Executor. The responses coming from the Executor will be sent back to Banzai. </p>
<p>To get an idea about the various transport parameters being used in this sample see 
<a href="Synapse_Samples_Setup.html#fixparameters">FIX Transport Parameters </a>. </p>
<h2>
<a name="Sample258" id="Sample258">Sample 258: Switching from HTTP to FIX </a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;FIXProxy&quot; transport&quot;http&quot;&gt;

        &lt;parameter name=&quot;transport.fix.InitiatorConfigURL&quot;&gt;file:/home/synapse_user/fix-config/synapse-sender.cfg&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.InitiatorMessageStore&quot;&gt;file&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.SendAllToInSequence&quot;&gt;false&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.DropExtraResponses&quot;&gt;true&lt;/parameter&gt;

        &lt;target&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;fix://localhost:19876?BeginString=FIX.4.0&amp;amp;SenderCompID=SYNAPSE&amp;amp;TargetCompID=EXEC&quot;/&gt;
            &lt;/endpoint&gt;
	    &lt;inSequence&gt;
	    	&lt;property name=&quot;transport.fix.ServiceName&quot; value=&quot;FIXProxy&quot; scope=&quot;axis2-client&quot;/&gt;
			&lt;log level=&quot;full&quot;/&gt;
	    &lt;/inSequence&gt;
        &lt;outSequence&gt;
            &lt;log level=&quot;full&quot;/&gt;
			&lt;send/&gt;
        &lt;/outSequence&gt;
        &lt;/target&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt; </pre>
<p>
<strong>Objective: Demonstrate switching from HTTP to FIX</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> You will need the Executor sample application that comes with Quickfix/J. Configure Executor to establish a session with Synapse. See
<a href="Synapse_Samples_Setup.html#fixsamplesconfig">Configuring Sample FIX Applications</a>
<br/>Start Executor
<br/>Enable FIX transport sender in the Synapse axis2.xml. See
<a href="Synapse_Samples_Setup.html#fixtransport">Setting up FIX transport </a>
<br/>Configure Synapse for FIX samples. See
<a href="Synapse_Samples_Setup.html#fixsamples">Configuring Synapse for FIX Samples</a>. There is no need to create the fix-synapse.cfg file for this sample. Having only the synapse-sender.cfg file is sufficient.
<br/>Go to the SYNAPSE_HOME/repository/conf/sample/synapse_sample_258.xml file and make sure that transport.fix.InitiatorConfigURL property points to the synapse-sender.cfg file you created. Once done you can start the Synapse configuration numbered 258: i.e. synapse -sample 258 </p>

<p>Invoke the FIX Client as follows. This command sends a FIX message embedded in a SOAP message over HTTP. 
<pre>ant fixclient -Dsymbol=IBM -Dqty=5 -Dmode=buy -Daddurl=http://localhost:8280/services/FIXProxy</pre> </p>
<p>Synapse will forward the order request to the session with the Executor. The first response coming from the Executor will be sent back over HTTP. Executor generally sends two responses for each incoming order request. But since the response has to be forwarded over HTTP only one can be sent back to the client. </p>
<h2>
<a name="Sample259" id="Sample259">Sample 259: Switch from FIX to HTTP </a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;localEntry key=&quot;xslt-key-req&quot; src=&quot;file:repository/conf/sample/resources/transform/transform_fix_to_http.xslt&quot; /&gt;
    &lt;proxy name=&quot;FIXProxy&quot; transports=&quot;fix&quot;&gt;
        &lt;target&gt;
            &lt;endpoint&gt;
                &lt;address
                    uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot; /&gt;
            &lt;/endpoint&gt;
            &lt;inSequence&gt;
                &lt;log level=&quot;full&quot; /&gt;
                &lt;xslt key=&quot;xslt-key-req&quot; /&gt;
                &lt;log level=&quot;full&quot; /&gt;
            &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;log level=&quot;full&quot; /&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
    &lt;parameter name=&quot;transport.fix.AcceptorConfigURL&quot;&gt;
        file:repository/conf/sample/resources/fix/fix-synapse.cfg
    &lt;/parameter&gt;
    &lt;parameter name=&quot;transport.fix.AcceptorMessageStore&quot;&gt;
        file
    &lt;/parameter&gt;
   &lt;/proxy&gt;
&lt;/definitions&gt;
      </pre>
<p>
<strong>Objective: Demonstrate the capability of switching between FIX to HTTP</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> You will need the sample FIX blotter that come with Quickfix/J (Banzai). Configure the blotter to establish sessions with Synapse. See
<a href="Synapse_Samples_Setup.html#fixsamplesconfig">Configuring Sample FIX Applications</a>
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already deployed
<br/>Start Banzai
<br/>Enable FIX transport in the Synapse axis2.xml. See
<a href="Synapse_Samples_Setup.html#fixtransport">Setting up FIX transport </a>
<br/>Configure Synapse for FIX samples. See
<a href="Synapse_Samples_Setup.html#fixsamples">Configuring Synapse for FIX Samples</a>
<br/>Open up the SYNAPSE_HOME/repository/conf/sample/synapse_sample_259.xml file and make sure that transport.fix.AcceptorConfigURL property points to the fix-synapse.cfg file you created. Once done you can start the Synapse configuration numbered 259: i.e. synapse -sample 259. Note that Synapse creates a new FIX session with Banzai at this point. </p>
    
<p>Send an order request from Banzai to Synapse. e.g. Buy DELL 1000 @ 100. User has to send a 'Limit' Order because price is a mandatory field for 'placeOrder' operation. </p>
<p>Synapse will forward the order request to one-way 'placeOrder' operation on the SimpleStockQuoteService. Synapse uses a simple XSLT mediator to transform the incoming FIX to a SOAP message. </p>
<pre xml:space="preserve">&lt;xsl:stylesheet version=&quot;2.0&quot;
    xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
    xmlns:fn=&quot;http://www.w3.org/2005/02/xpath-functions&quot;&gt;
    &lt;xsl:output method=&quot;xml&quot; omit-xml-declaration=&quot;yes&quot; indent=&quot;yes&quot; /&gt;
  &lt;xsl:template match=&quot;/&quot;&gt;
    &lt;m0:placeOrder xmlns:m0=&quot;http://services.samples&quot;&gt;
        &lt;m0:order&gt;
            &lt;m0:price&gt;&lt;xsl:value-of select=&quot;//message/body/field[@id='44']&quot;/&gt;&lt;/m0:price&gt;
            &lt;m0:quantity&gt;&lt;xsl:value-of select=&quot;//message/body/field[@id='38']&quot;/&gt;&lt;/m0:quantity&gt;
            &lt;m0:symbol&gt;&lt;xsl:value-of select=&quot;//message/body/field[@id='55']&quot;/&gt;&lt;/m0:symbol&gt;
        &lt;/m0:order&gt;
    &lt;/m0:placeOrder&gt;
   &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
      </pre>
<p>To get an idea about the various transport parameters being used in this sample see 
<a href="Synapse_Samples_Setup.html#fixparameters">FIX Transport Parameters </a>. </p>
<h2>
<a name="Sample260" id="Sample260">Sample 260: Switch from FIX to AMQP </a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
	&lt;proxy name=&quot;FIXProxy&quot; transports=&quot;fix&quot;&gt;
		&lt;target&gt;
			&lt;endpoint&gt;
				&lt;address uri=&quot;jms:/QpidStockQuoteService?transport.jms.ConnectionFactoryJNDIName=qpidConnectionfactory&amp;amp;java.naming.factory.initial=org.apache.qpid.jndi.PropertiesFileInitialContextFactory&amp;amp;java.naming.provider.url=repository/conf/sample/resources/fix/con.properties&amp;amp;transport.jms.ReplyDestination=replyQueue&quot;/&gt;
			&lt;/endpoint&gt;
			&lt;inSequence&gt;
				&lt;log level=&quot;full&quot; /&gt;
			&lt;/inSequence&gt;
			&lt;outSequence&gt;
			    &lt;property name=&quot;transport.fix.ServiceName&quot;
					value=&quot;FIXProxy&quot; scope=&quot;axis2-client&quot; /&gt;
				&lt;log level=&quot;full&quot; /&gt;
		                &lt;send /&gt;
			&lt;/outSequence&gt;
		&lt;/target&gt;
		&lt;parameter name=&quot;transport.fix.AcceptorConfigURL&quot;&gt;
			file:repository/conf/sample/resources/fix/fix-synapse.cfg
		&lt;/parameter&gt;
		&lt;parameter name=&quot;transport.fix.AcceptorMessageStore&quot;&gt;
			file
		&lt;/parameter&gt;
	&lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the capability of switching between FIX and AMQP protocols</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> You will need the sample FIX blotter that comes with Quickfix/J (Banzai). Configure the blotter to establish sessions with Synapse. See
<a href="Synapse_Samples_Setup.html#fixsamplesconfig">Configuring Sample FIX Applications</a> </p>
<p>Configure the AMQP transport for Synapse. See 
<a href="Synapse_Samples_Setup.html#setupamqpjms">Configure Synapse for AMQP Transport</a> </p>
<p>Start the AMQP consumer, by switching to samples/axis2Client directory and running the consumer using the following command. Consumer will listen to the queue 'QpidStockQuoteService', accept the orders and reply to the queue 'replyQueue'. </p>
<pre xml:space="preserve">ant amqpconsumer -Dpropfile=$SYNAPSE_HOME/repository/conf/sample/resources/fix/direct.properties</pre>
<p>Start Banzai </p>
<p>Enable FIX transport in the Synapse axis2.xml. See 
<a href="Synapse_Samples_Setup.html#fixtransport">Setting up FIX transport </a> </p>
<p>Configure Synapse for FIX samples. See 
<a href="Synapse_Samples_Setup.html#fixsamples">Configuring Synapse for FIX Samples</a> </p>
<p>Open up the SYNAPSE_HOME/repository/conf/sample/synapse_sample_260.xml file and make sure that the transport.fix.AcceptorConfigURL property points to the fix-synapse.cfg file you created. Once done you can start the Synapse configuration numbered 260: i.e. synapse -sample 260. Note that Synapse creates a new FIX session with Banzai at this point. </p>
<p>Send an order request from Banzai to Synapse. e.g. Buy DELL 1000 @ MKT. </p>
<p>Synapse will forward the order request by binding it to a JMS message payload and sending it to the AMQP consumer. AMQP consumer will send a execution back to Banzai. </p>
<p>To get an idea about the various transport parameters being used in this sample see 
<a href="Synapse_Samples_Setup.html#fixparameters">FIX Transport Parameters </a>. </p>
<h2>
<a name="Sample261" id="Sample261">Sample 261: Switch between FIX versions </a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
     &lt;proxy name=&quot;OrderProcesserProxy41&quot; transports=&quot;fix&quot;&gt;
        &lt;target&gt;
           &lt;endpoint&gt;
              &lt;address uri=&quot;fix://localhost:19877?BeginString=FIX.4.1&amp;amp;SenderCompID=SYNAPSE&amp;amp;TargetCompID=EXEC&quot;/&gt;
           &lt;/endpoint&gt;
           &lt;inSequence&gt;&lt;log level=&quot;full&quot;/&gt;&lt;/inSequence&gt;
           &lt;outSequence&gt;&lt;log level=&quot;full&quot;/&gt;&lt;send/&gt;&lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;parameter name=&quot;transport.fix.AcceptorConfigURL&quot;&gt;file:repository/conf/sample/resources/fix/fix-synapse-m40.cfg&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.AcceptorMessageStore&quot;&gt;file&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.InitiatorConfigURL&quot;&gt;file:repository/conf/sample/resources/fix/synapse-sender-m.cfg&lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.InitiatorMessageStore&quot;&gt;file&lt;/parameter&gt;
     &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the capability of switching between FIX versions e.g. FIX4.0 to FIX4.1</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> You will need the two sample FIX applications that come with Quickfix/J (Banzai and Executor). Configure the two applications to establish sessions with Synapse. See
<a href="Synapse_Samples_Setup.html#fixsamplesconfig">Configuring Sample FIX Applications.</a> </p>
<p>Add the following lines to the Banzai configuration file (banzai.cfg). </p>
<pre xml:space="preserve">DataDictionary=~/etc/spec/FIX40-synapse.xml</pre>
<p>Note: FIX40-synapse.xml can be found at $SYNAPSE_HOME/repository/conf/samples/resources/fix. This is a custom FIX data dictionary file that has added tag 150,151 to the execution messages (35=8) of FIX4.0. Make sure the DataDictionary property of the banzai.cfg points to this data dictionary file. </p>
<p>Add the following lines to the Executor configuration file (executor.cfg). </p>
<pre xml:space="preserve">[session]
BeginString=FIX.4.1
SocketAcceptPort=19877</pre>
<p>Start Banzai and Executor using the custom configuration files. </p>
<p>Enable FIX transport in the Synapse axis2.xml. See 
<a href="Synapse_Samples_Setup.html#fixtransport">Setting up FIX transport </a> </p>
<p>Configure Synapse for FIX samples. We will be using two custom configuration files for Synapse in this sample. These two custom configuration files can be found at SYNAPSE_HOME/repository/conf/sample/resources/fix directory. The two files are called fix-synapse-m40.cfg and synapse-sender-m.cfg. You can point your Synapse configuration to these two files (this is already done in the supplied synapse_sample_261.xml file) or you may create copies of them and point the Synapse configuration to the copies. In either case make sure that the properties like FileStorePath and FileLogPath in the two files point to valid locations in your local file system. </p>
<p>Open up the SYNAPSE_HOME/repository/conf/sample/synapse_sample_261.xml file and make sure that transport.fix.AcceptorConfigURL property points to the fix-synapse-m40.cfg file described above and transport.fix.InitiatorConfigURL points to the synapse-sender-m.cfg file described above. Once done you can start the Synapse configuration numbered 261: i.e. synapse -sample 261. Note that Synapse creates a new FIX session with Banzai at this point. </p>
<p>Send an order request from Banzai to Synapse. e.g. Buy DELL 1000 @ MKT. </p>
<p>Synapse will forward the order request from FIX4.0 to the Executor that accepts FIX4.1 messages. Executor will send an ack and an execution back to Banzai. </p>
<p>To get an idea about the various transport parameters being used in this sample see 
<a href="Synapse_Samples_Setup.html#fixparameters">FIX Transport Parameters </a>. </p>
<h2>
<a name="Sample262" id="Sample262">Sample 262: CBR of FIX messages</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;sequence name=&quot;CBR_SEQ&quot;&gt;
        &lt;in&gt;
            &lt;switch source=&quot;//message/body/field[@id='55']&quot;&gt;
                &lt;case regex=&quot;GOOG&quot;&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;
                            &lt;address
                                uri=&quot;fix://localhost:19876?BeginString=FIX.4.0&amp;amp;SenderCompID=SYNAPSE&amp;amp;TargetCompID=EXEC&quot; /&gt;
                        &lt;/endpoint&gt;
                    &lt;/send&gt;
                &lt;/case&gt;
                &lt;case regex=&quot;MSFT&quot;&gt;
                    &lt;send&gt;
                        &lt;endpoint&gt;
                            &lt;address
                                uri=&quot;fix://localhost:19877?BeginString=FIX.4.1&amp;amp;SenderCompID=SYNAPSE&amp;amp;TargetCompID=EXEC&quot; /&gt;
                        &lt;/endpoint&gt;
                    &lt;/send&gt;
                &lt;/case&gt;
                &lt;default&gt;&lt;/default&gt;
            &lt;/switch&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;send /&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;
    &lt;proxy name=&quot;FIXProxy&quot; transports=&quot;fix&quot;&gt;
        &lt;target inSequence=&quot;CBR_SEQ&quot; /&gt;
        &lt;parameter name=&quot;transport.fix.AcceptorConfigURL&quot;&gt;
            file:repository/conf/sample/resources/fix/fix-synapse.cfg
        &lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.AcceptorMessageStore&quot;&gt;
            file
        &lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.InitiatorConfigURL&quot;&gt;
            file:repository/conf/sample/resources/fix/synapse-sender.cfg
        &lt;/parameter&gt;
        &lt;parameter name=&quot;transport.fix.InitiatorMessageStore&quot;&gt;
            file
        &lt;/parameter&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the capability of CBR FIX messages</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> You will need the two sample FIX applications that come with Quickfix/J (Banzai and Executor). Configure the two applications to establish sessions with Synapse. See
<a href="Synapse_Samples_Setup.html#fixsamplesconfig">Configuring Sample FIX Applications</a> </p>
<p>Add the following lines to banzai.cfg. </p>
<pre xml:space="preserve">DataDictionary=~/etc/spec/FIX40-synapse.xml</pre>
<p>Note: FIX40-synapse.xml can be found at $SYNAPSE_HOME/repository/conf/samples/resources/fix. This is a custom FIX data dictionary file that has added tag 150,151 to the execution messages (35=8) of FIX4.0. Make sure the DataDictionary property of the banzai.cfg points to this data dictionary file. </p>
<p>Add the following lines to executor.cfg </p>
<pre xml:space="preserve">[session]
BeginString=FIX.4.1
SocketAcceptPort=19877</pre>
<p>Start Banzai and Executor using the custom config files. </p>
<p>Enable FIX transport in the Synapse axis2.xml. See 
<a href="Synapse_Samples_Setup.html#fixtransport">Setting up FIX transport </a> </p>
<p>Configure Synapse for FIX samples. See 
<a href="Synapse_Samples_Setup.html#fixsamples">Configuring Synapse for FIX Samples</a> </p>
<p>Open up the SYNAPSE_HOME/repository/conf/sample/synapse_sample_262.xml file and make sure that transport.fix.AcceptorConfigURL property points to the fix-synapse.cfg file you created and transport.fix.InitiatorConfigURL points to the synapse-sender.cfg file you created. Once done you can start the Synapse configuration numbered 262: i.e. synapse -sample 262. Note that Synapse creates a new FIX session with Banzai at this point. </p>
<p>Send an order request from Banzai to Synapse. e.g. Buy GOOG 1000 @ MKT, Buy MSFT 3000 @ MKT, Buy SUNW 500 @ 100.20 </p>
<p>Synapse will forward the order requests with symbol 'GOOG' to FIX endpoint FIX-4.0 @ localhost:19876.</p>
<p>Synapse will forward the order requests with symbol 'MSFT' to FIX endpoint FIX-4.1 @ localhost:19877.</p>
<p>Synapse will not forward the orders with other symbols to any endpoint. (default case has kept blank in the configuration)</p>
<p>To get an idea about the various transport parameters being used in this sample see 
<a href="Synapse_Samples_Setup.html#fixparameters">FIX Transport Parameters </a>. </p>  
  
<h2>
<a name="Sample263" id="Sample263">Sample 263: Transport switching - JMS to http/s using JBoss Messaging(JBM) </a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot; transports=&quot;jms&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot;/&gt;
            &lt;/inSequence&gt;
            &lt;endpoint&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
            &lt;/endpoint&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
        &lt;parameter name=&quot;transport.jms.ContentType&quot;&gt;
            &lt;rules&gt;
                &lt;jmsProperty&gt;contentType&lt;/jmsProperty&gt;
                &lt;default&gt;application/xml&lt;/default&gt;
            &lt;/rules&gt;
        &lt;/parameter&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Introduction to switching transports with proxy services. The JMS provider will be <a href="http://jboss.org/jbossmessaging/">JBoss Messaging(JBM).</a></strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService (Refer steps above)
<br/> <a href="http://jboss.org/jbossmessaging/">Download</a>, install and start JBM server, and configure Synapse to listen on JBM (refer notes below)
<br/> Start the Synapse configuration numbered 250: i.e. synapse -sample 250
<br/> We need to configure the required queues in JBM. Add the following entry to JBM jms configuration inside file-config/stand-alone/non-clustered/jbm-jms.xml.
    Once JBM is installed and started you should get a message as follows: </p>
<pre xml:space="preserve">
&lt;queue name=&quot;StockQuoteProxy&quot;&gt;
    &lt;entry name=&quot;StockQuoteProxy&quot;/&gt;
&lt;/queue&gt;
</pre>
<p>Once you started the JBM server with the above changes you'll be able to see the following on STDOUT.</p>
<pre xml:space="preserve">10:18:02,673 INFO [org.jboss.messaging.core.server.impl.MessagingServerImpl]  JBoss Messaging Server version 2.0.0.BETA3 (maggot, 104) started </pre>
<p>You will now need to configure the Axis2 instance used by Synapse (not the sample Axis2 server) to enable JMS support using the above provider. Refer Axis2 documentation on setting up JMS in detail (http://ws.apache.org/axis2/1_1/jms-transport.html). You will also need to copy the jbm-core-client.jar, jbm-jms-client.jar, jnp-client.jar(these jars are inside client folder ) and
    jbm-transports.jar, netty.jar(these jars are from lib folder) jars from JBM into the lib directory to allow Synapse to connect to the JBM JMS provider. This was tested with JBM 2.0.0.BETA3 </p>

<p>You need to add the following configuration for Axis2 JMS transport listener in axis2.xml found at repository/conf/axis2.xml.</p>
<pre xml:space="preserve">
&lt;transportReceiver name=&quot;jms&quot; class=&quot;org.apache.axis2.transport.jms.JMSListener&quot;&gt;
    &lt;parameter name=&quot;java.naming.factory.initial&quot;&gt;org.jnp.interfaces.NamingContextFactory&lt;/parameter&gt;
    &lt;parameter name=&quot;java.naming.provider.url&quot;&gt;jnp://localhost:1099&lt;/parameter&gt;
    &lt;parameter name=&quot;java.naming.factory.url.pkgs&quot;&gt;org.jboss.naming:org.jnp.interfaces&lt;/parameter&gt;
    &lt;parameter name=&quot;transport.jms.ConnectionFactoryJNDIName&quot;&gt;ConnectionFactory&lt;/parameter&gt;
&lt;/transportReceiver&gt;
</pre>
<p>And also uncomment the section for JMS transport sender in the same file.</p>
<p>Once you start the Synapse configuration 250 and request for the WSDL of the proxy service (http://localhost:8280/services/StockQuoteProxy?wsdl) you will notice that its exposed only on the JMS transport. This is because the configuration specified this requirement in the proxy service definition. </p>
<p>Now lets send a stock quote request on JMS, using the dumb stock quote client as follows: </p>
<pre xml:space="preserve">ant jmsclient -Djms_type=pox -Djms_dest=StockQuoteProxy -Djms_payload=MSFT -Djava.naming.provider.url=jnp://localhost:1099 -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -D=java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces</pre>
<p>On the Synapse debug log you will notice that the JMS listener received the request message as: </p>
<pre xml:space="preserve">DEBUG - Proxy Service StockQuoteProxy received a new message...</pre>
<p>Now if you examine the console running the sample Axis2 server, you will see a message indicating that the server has accepted an order as follows: </p>
<pre xml:space="preserve">Accepted order for : 16517 stocks of MSFT at $ 169.14622538721846</pre>
<p>In this sample, the client sends the request message to the proxy service exposed over JMS in Synsape. Synapse forwards this message to the HTTP EPR of the simple stock quote service hosted on the sample Axis2 server.
Note that the operation is out-only and no response is sent back to the client. The transport.jms.ContentType property
is necessary to allow the JMS transport to determine the content type of incoming messages. With the given configuration
it will first try to read the content type from the 'contentType' message property and fall back to 'application/xml'
(i.e. POX) if this property is not set. Note that the JMS client used in this example doesn't send any content type information.</p>
<p>Note: It is possible to instruct a JMS proxy service to listen to an already existing destination without creating a new one. To do this, use the parameter elements on the proxy service definition to specify the destination and connection factory etc. </p>
<p>e.g. </p>
<pre xml:space="preserve">&lt;parameter name=&quot;transport.jms.Destination&quot;&gt;dynamicTopics/something.TestTopic&lt;/parameter&gt;</pre>

  <h2>
    <a name="Sample264" id="Sample264">Sample 264: Sending Two-Way Messages Using JMS transport</a>
  </h2>
  <pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot; transports=&quot;http&quot;&gt;
        &lt;target&gt;        
            &lt;endpoint&gt;
		            &lt;address uri=&quot;jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;
                  java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616&amp;transport.jms.DestinationType=queue&quot;/&gt;
            &lt;/endpoint&gt;            
            &lt;inSequence&gt;                            
                &lt;property action=&quot;set&quot; name=&quot;transport.jms.ContentTypeProperty&quot; value=&quot;Content-Type&quot; scope=&quot;axis2&quot;/&gt;
            &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;property action=&quot;remove&quot; name=&quot;TRANSPORT_HEADERS&quot; scope=&quot;axis2&quot;/&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;        
        &lt;target&gt; 
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;        
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
  <p>
    <strong>Objective: Demonstrate sending request response scenario with JMS transport</strong>
  </p>
  <p>
    <strong>Prerequisites:</strong>
    <br/>You need to set up synpase and axis2 server to use the JMS transport. See
    <a href="#Sample251">Sample 251</a> for more details.
  </p>
  <p>
    This sample is similar to the <a href="#Sample251">Sample 251</a>. Only difference is we are expecting a response from the server. JMS transport uses <strong>transport.jms.ContentTypeProperty</strong> to
    determine the content type of the response message. If this property is not set JMS transport treats the incoming message as plain text.
  </p>
  <p>
    In the out path we remove the message context property <strong>TRANSPORT_HEADERS</strong>. If these property is not removed JMS headers will be passed to the client.
  </p>
  <p>Start Synpase using sample 264.</p>
  <pre xml:space="preserve">synapse.bat/synapse.sh -sample 264</pre>
  <p>Start Axis2 server with SimpleStockService deployed</p>
  <p>Invoke the stockquote client using the following command.</p>
  <pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dsymbol=MSFT</pre>
  <p>The sample Axis2 server console will print a message indicating that it has received the request: </p>
  <pre xml:space="preserve">Generating quote for : MSFT</pre>
  <p>In the client side it shoud print a message indicating it has received the price.</p>
  <pre xml:space="preserve"> Standard :: Stock price = $154.31851804993238</pre>

  <h2>
    <a name="Sample265" id="Sample265">Sample 265: Switching from TCP to HTTP/S</a>
  </h2>
  <pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;proxy name="StockQuoteProxy" transports="tcp"&gt;
        &lt;target&gt;
            &lt;endpoint&gt;
		        &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
            &lt;/endpoint&gt;
            &lt;inSequence&gt;
                &lt;log level="full"/&gt;
                &lt;property name="OUT_ONLY" value="true"/&gt;
            &lt;/inSequence&gt;
        &lt;/target&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
  <p>
    <strong>Objective: Demonstrate receiving SOAP messages over TCP and forwarding them over HTTP</strong>
  </p>
  <p>
    <strong>Prerequisites:</strong>
    <br/>You need to configure Synpase to use the TCP transport. The sample Axis2 client should also
      be setup to send TCP requests. Refer <a href="Synapse_Samples_Setup.html#tcp">Setting
      Up the TCP Transport</a> section in the sample setup guide for more details.
    <br/>Start Synpase using sample 265: ie synapse -sample 265
    <br/>Start Axis2 server with SimpleStockService deployed  
  </p>
  <p>
    This sample is similar to <a href="#Sample250">Sample 250</a>. Only difference is instead of the JMS transport
    we will be using the TCP transport to receive messages. TCP is not an application layer protocol. Hence there
    are no application level headers available in the requests. Synapse has to simply read the XML content coming
    through the socket and dispatch it to the right proxy service based on the information available in the message
    payload itself. The TCP transport is capable of dispatching requests based on addressing headers or the first
    element in the SOAP body. In this sample, we will get the sample client to send WS-Addressing headers in the
    request. Therefore the dispatching will take place based on the addressing header values.
  </p>
  <p>Invoke the stockquote client using the following command. Note the TCP URL in the command.</p>
  <pre xml:space="preserve">ant stockquote -Daddurl=tcp://localhost:6060/services/StockQuoteProxy -Dmode=placeorder</pre>
  <p>The TCP transport will receive the message and hand it over to the mediation engine. Synapse will
  dispatch the request to the StockQuoteProxy service based on the addressing header values.</p>
  <p>The sample Axis2 server console will print a message indicating that it has received the request: </p>
  <pre xml:space="preserve">Thu May 20 12:25:01 IST 2010 samples.services.SimpleStockQuoteService  :: Accepted order #1 for : 17621 stocks of IBM at $ 73.48068475255796
</pre>

  <h2>
    <a name="Sample266" id="Sample266">Sample 266: Switching from UDP to HTTP/S</a>
  </h2>
  <pre xml:space="preserve">&lt;proxy xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteProxy" transports="udp"&gt;
   &lt;target&gt;
	&lt;endpoint&gt;
	   &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
	&lt;/endpoint&gt;
	&lt;inSequence&gt;
	   &lt;log level="full"/&gt;
	   &lt;property name="OUT_ONLY" value="true"/&gt;
	&lt;/inSequence&gt;
   &lt;/target&gt;
   &lt;parameter name="transport.udp.port"&gt;9999&lt;/parameter&gt;
   &lt;parameter name="transport.udp.contentType"&gt;text/xml&lt;/parameter&gt;
   &lt;publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/&gt;
&lt;/proxy&gt;</pre>
  <p>
    <strong>Objective: Demonstrate receiving SOAP messages over UDP and forwarding them over HTTP</strong>
  </p>
  <p>
    <strong>Prerequisites:</strong>
    <br/>You need to configure Synpase to use the UDP transport. The sample Axis2 client should also
      be setup to send UDP requests. Refer <a href="Synapse_Samples_Setup.html#udp">Setting
      Up the UDP Transport</a> section in the sample setup guide for more details.
    <br/>Start Synpase using sample 266: i.e. synapse -sample 266
    <br/>Start Axis2 server with SimpleStockService deployed
  </p>    
  <p>
    This sample is similar to <a href="#Sample265">Sample 265</a>. Only difference is instead of the TCP transport
    we will be using the UDP transport to receive messages.
  </p>
  <p>Invoke the stockquote client using the following command. Note the UDP URL in the command.</p>
  <pre xml:space="preserve">ant stockquote -Daddurl=udp://localhost:9999?contentType=text/xml -Dmode=placeorder</pre>
  <p>Since we have configured the content type as text/xml for the proxy service, incoming messages will be processed
  as SOAP 1.1 messages.</p>
  <p>The sample Axis2 server console will print a message indicating that it has received the request: </p>
  <pre xml:space="preserve">Thu May 20 12:25:01 IST 2010 samples.services.SimpleStockQuoteService  :: Accepted order #1 for : 17621 stocks of IBM at $ 73.48068475255796
</pre>

  <h1>
<a name="Task" id="Task">Introduction to Synapse Tasks</a> </h1>
<h2>
<a name="Sample300" id="Sample300">Sample 300: Introduction to Tasks with simple trigger</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;task class=&quot;org.apache.synapse.startup.tasks.MessageInjector&quot; name=&quot;CheckPrice&quot;&gt;
        &lt;property name=&quot;to&quot; value=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
        &lt;property name=&quot;soapAction&quot; value=&quot;urn:getQuote&quot;/&gt;
        &lt;property name=&quot;message&quot;&gt;
            &lt;m0:getQuote xmlns:m0=&quot;http://services.samples/xsd&quot;&gt;
                &lt;m0:request&gt;
                    &lt;m0:symbol&gt;IBM&lt;/m0:symbol&gt;
                &lt;/m0:request&gt;
            &lt;/m0:getQuote&gt;
        &lt;/property&gt;
        &lt;trigger interval=&quot;5&quot;/&gt;
    &lt;/task&gt;

    &lt;in&gt;
        &lt;send/&gt;
    &lt;/in&gt;
    &lt;out&gt;
        &lt;log level=&quot;custom&quot;&gt;
            &lt;property name=&quot;Stock_Quote_on&quot; expression=&quot;//ns:return/ns:lastTradeTimestamp/child::text()&quot; xmlns:ns=&quot;http://services.samples/xsd&quot;/&gt;
            &lt;property name=&quot;For_the_organization&quot; expression=&quot;//ns:return/ns:name/child::text()&quot; xmlns:ns=&quot;http://services.samples/xsd&quot;/&gt;
            &lt;property name=&quot;Last_Value&quot; expression=&quot;//ns:return/ns:last/child::text()&quot; xmlns:ns=&quot;http://services.samples/xsd&quot;/&gt;
        &lt;/log&gt;
    &lt;/out&gt;

&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Introduce the concept of tasks and how simple trigger works</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/> Build the SimpleStockQuoteService as mentioned above and start the sample Axis2 server
<br/> Start Synapse using sample 300: ie synapse -sample 300</p>
<p>When ever Synapse gets started with this configuration, a task will run periodically in 5 second
    intervals. You could limit the number of times that you want to run this task by adding a count
    attribute with an integer as the value, if the count is not present as in this sample this task
    will run until the server is shutdown.</p>
<p>One can write his/her own task class implementing the org.apache.synapse.task.Task interface and
    implementing the execute method to run the necessary logic. For this particular sample we have used the
    MessageInjector class which just injects a message specified into Synapse environment. </p>
    
<h1>
<a name="AdvancedMediation" id="AdvancedMediation">Advanced mediations with advanced mediators</a> </h1>
<h2>
<a name="ScriptMediator" id="ScriptMediator">Using scripts in mediation (Script Mediator)</a></h2>
<p>The Synapse Script Mediator is a Synapse extension, and thus all prerequisites are not bundled by default with the Synapse distribution. Before you use some script mediators you may need to manually add the required jar files to the Synapse lib directory, and optionally perform other installation tasks as may be required by the individual scripting language. This is explained in the 
<a href="Synapse_Samples_Setup.html#script">Samples Setup guide</a>. </p>
<h2>
<a name="Sample350" id="Sample350">Sample 350: Introduction to the script mediator using js scripts</a></h2>
<pre xml:space="preserve">

&lt;!-- Introduction to the script mediator using js scripts --&gt;
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;registry provider=&quot;org.apache.synapse.registry.url.SimpleURLRegistry&quot;&gt;
        &lt;!-- the root property of the simple URL registry helps resolve a resource URL as root + key --&gt;
        &lt;parameter name=&quot;root&quot;&gt;file:repository/conf/sample/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=&quot;cachableDuration&quot;&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;localEntry key=&quot;stockquoteScript&quot;
                src=&quot;file:repository/conf/sample/resources/script/stockquoteTransformRequest.js&quot;/&gt;

    &lt;in&gt;
        &lt;!-- transform the custom quote request into a standard quote request expected by the service --&gt;
        &lt;script language=&quot;js&quot; key=&quot;stockquoteScript&quot; function=&quot;transformRequest&quot;/&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;/in&gt;

    &lt;out&gt;
        &lt;!-- transform the standard response back into the custom format the client expects --&gt;
        &lt;script language=&quot;js&quot; key=&quot;script/stockquoteTransformResponse.js&quot;
                function=&quot;transformResponse&quot;/&gt;
        &lt;send/&gt;
    &lt;/out&gt;
&lt;/definitions&gt;
 </pre>

<pre xml:space="preserve">&lt;x&gt;&lt;![CDATA[
  function transformRequest(mc) {
     var symbol = mc.getPayloadXML()..*::Code.toString();
     mc.setPayloadXML(
        &lt;m:getQuote xmlns:m=&quot;http://services.samples&quot;&gt;
           &lt;m:request&gt;
              &lt;m:symbol&gt;{symbol}&lt;/m:symbol&gt;
           &lt;/m:request&gt;
        &lt;/m:getQuote&gt;);
  }

  function transformResponse(mc) {
     var symbol = mc.getPayloadXML()..*::symbol.toString();
     var price = mc.getPayloadXML()..*::last.toString();
     mc.setPayloadXML(
        &lt;m:CheckPriceResponse xmlns:m=&quot;http://www.apache-synapse.org/test&quot;&gt;
   &lt;m:Code&gt;{symbol}&lt;/m:Code&gt;
   &lt;m:Price&gt;{price}&lt;/m:Price&gt;
        &lt;/m:CheckPriceResponse&gt;);
  }
]]&gt;&lt;/x&gt;</pre>
<p>
<strong>Objective: Introduction to the script mediator</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Start the Synapse configuration numbered 350: i.e. synapse -sample 350
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>

<p>This sample is similar to sample 8 but instead of using XSLT, the transformation is done with JavaScript and E4X. Note that the script source loaded from a resource must be specified within a CDATA tag within an XML element. The script used in this example has two functions, 'transformRequest' and 'transformResponse', and the Synapse configuration uses the function attribute to specify which function should be invoked. Use the stock quote client to issue a custom quote client as follows.: </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote</pre>
<p>Synapse uses the script mediator and the specified JavaScript function to convert the custom request to a standard quote request. Subsequently the response received is transformed and sent back to the client. </p>
<h2>
<a name="Sample351" id="Sample351">Sample 351: In-line script mediation with JavaScript</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;in&gt;
        &lt;!-- transform the custom quote request into a standard quote requst expected by the service --&gt;
        &lt;script language=&quot;js&quot;&gt;&lt;![CDATA[
               var symbol = mc.getPayloadXML()..*::Code.toString();
               mc.setPayloadXML(
                  &lt;m:getQuote xmlns:m=&quot;http://services.samples&quot;&gt;
                     &lt;m:request&gt;
                        &lt;m:symbol&gt;{symbol}&lt;/m:symbol&gt;
                     &lt;/m:request&gt;
                  &lt;/m:getQuote&gt;);
        ]]&gt;&lt;/script&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;/in&gt;
    &lt;out&gt;
        &lt;!-- transform the standard response back into the custom format the client expects --&gt;
        &lt;script language=&quot;js&quot;&gt;&lt;![CDATA[
               var symbol = mc.getPayloadXML()..*::symbol.toString();
               var price = mc.getPayloadXML()..*::last.toString();
               mc.setPayloadXML(
                  &lt;m:CheckPriceResponse xmlns:m=&quot;http://www.apache-synapse.org/test&quot;&gt;
               &lt;m:Code&gt;{symbol}&lt;/m:Code&gt;
               &lt;m:Price&gt;{price}&lt;/m:Price&gt;
                  &lt;/m:CheckPriceResponse&gt;);
            ]]&gt;&lt;/script&gt;
        &lt;send/&gt;
    &lt;/out&gt;
&lt;/definitions&gt; </pre>
<p>
<strong>Objective: Introduction to in-line script mediation</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Start the Synapse configuration numbered 351: i.e. synapse -sample 351
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>

<p>This example is functionally equivalent to sample # 350 and sample # 8, and demonstrates in-line script mediation in Synapse. Use the stock quote client to send a custom quote as in example # 350 to try this example. </p>

<h2>
<a name="Sample352" id="Sample352">Sample 352: Accessing Synapse message context API methods using scripting language</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;in&gt;
       &lt;!-- change the MessageContext into a response and set a response payload --&gt;
       &lt;script language=&quot;js&quot;&gt;&lt;![CDATA[
          mc.setTo(mc.getReplyTo());
          mc.setProperty(&quot;RESPONSE&quot;, &quot;true&quot;);
          mc.setPayloadXML(
             &lt;ns:getQuoteResponse xmlns:ns=&quot;http://services.samples/xsd&quot;&gt;
                &lt;ns:return&gt;
                   &lt;ns:last&gt;99.9&lt;/ns:last&gt;
                &lt;/ns:return&gt;
             &lt;/ns:getQuoteResponse&gt;);
       ]]&gt;&lt;/script&gt;
    &lt;/in&gt;
    &lt;send/&gt;
&lt;/definitions&gt; </pre>
<p>
<strong>Objective: Accessing the Synapse APIs from scripting languages</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Start the Synapse configuration numbered 352: i.e. bin/synapse -sample 352</p>

<p>This example shows how an in-line JavaScript mediator script could access the Synapse message context API to set its 'To' EPR and to set a custom property to mark it as a response. Execute the stock quote client, and you will receive the response &quot;99.9&quot; as the last sale price as per the above script. </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/
...
stockquote:
     [java] Standard :: Stock price = $99.9</pre>
<h2>
<a name="Sample353" id="Sample353">Sample 353: Using Ruby scripts for mediation</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;localEntry key=&quot;stockquoteScript&quot; src=&quot;file:repository/conf/sample/resources/script/stockquoteTransform.rb&quot;/&gt;
    &lt;in&gt;
        &lt;!-- transform the custom quote request into a standard quote request expected by the service --&gt;
        &lt;script language=&quot;rb&quot; key=&quot;stockquoteScript&quot; function=&quot;transformRequest&quot;/&gt;

        &lt;!-- send message to real endpoint referenced by name &quot;stockquote&quot; and stop --&gt;
        &lt;send&gt;
            &lt;endpoint name=&quot;stockquote&quot;&gt;
                &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
            &lt;/endpoint&gt;
        &lt;/send&gt;
    &lt;/in&gt;
    &lt;out&gt;
        &lt;!-- transform the standard response back into the custom format the client expects --&gt;
        &lt;script language=&quot;rb&quot; key=&quot;stockquoteScript&quot; function=&quot;transformResponse&quot;/&gt;
        &lt;send/&gt;
    &lt;/out&gt;
&lt;/definitions&gt; </pre>
<pre xml:space="preserve">&lt;x&gt;&lt;![CDATA[
require 'rexml/document'
include REXML

def transformRequest(mc)
   newRequest= Document.new '&lt;m:getQuote xmlns:m=&quot;http://services.samples&quot;&gt;'&lt;&lt;
      '&lt;m:request&gt;&lt;m:symbol&gt;&lt;/m:symbol&gt;&lt;/m:request&gt;&lt;/m:getQuote&gt;'
   newRequest.root.elements[1].elements[1].text = mc.getPayloadXML().root.elements[1].get_text
   mc.setPayloadXML(newRequest)
end

def transformResponse(mc)
   newResponse = Document.new '&lt;m:CheckPriceResponse xmlns:m=&quot;http://www.apache-synapse.org/test&quot;&gt;&lt;m:Code&gt;' &lt;&lt;
      '&lt;/m:Code&gt;&lt;m:Price&gt;&lt;/m:Price&gt;&lt;/m:CheckPriceResponse&gt;'
   newResponse.root.elements[1].text = mc.getPayloadXML().root.elements[1].elements[1].get_text
   newResponse.root.elements[2].text = mc.getPayloadXML().root.elements[1].elements[2].get_text
   mc.setPayloadXML(newResponse)
end
]]&gt;&lt;/x&gt;</pre>
<p>
<strong>Objective: Script mediators using Ruby</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>This sample uses Ruby so first setup support for this in Synapse as described at
<a href="Synapse_Samples_Setup.html#script">Configuring JRuby</a>
<br/>Start the Synapse configuration numbered 353: i.e. bin/synapse -sample 353
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>
<p>This sample is functionally equivalent to sample # 350 (#351 and #8) but instead uses a Ruby script using the JRuby interpreter. The script has two functions, 'transformRequest' and 'transformResponse', and the Synapse configuration specifies which function to be invoked when used. Execute the stock quote client to send a custom stock quote as per example #350 and check the received stock quote response. </p>

<h2>
<a name="Sample354" id="Sample354">Sample 354: Using In-lined Ruby scripts for mediation</a></h2>
<div>
<pre xml:space="preserve">      &lt;!-- Using In-lined Ruby scripts for mediation --&gt;
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;in&gt;
        &lt;script language=&quot;rb&quot;&gt;
            &lt;![CDATA[
                require 'rexml/document'
                include REXML
                newRequest= Document.new '&lt;m:getQuote xmlns:m=&quot;http://services.samples&quot;&gt;&lt;m:request&gt;&lt;m:symbol&gt;...test...&lt;/m:symbol&gt;&lt;/m:request&gt;&lt;/m:getQuote&gt;'
                newRequest.root.elements[1].elements[1].text = $mc.getPayloadXML().root.elements[1].get_text
                $mc.setPayloadXML(newRequest)
            ]]&gt;
        &lt;/script&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;/in&gt;
    &lt;out&gt;
        &lt;script language=&quot;rb&quot;&gt;
            &lt;![CDATA[
                require 'rexml/document'
                include REXML
                newResponse = Document.new '&lt;m:CheckPriceResponse xmlns:m=&quot;http://services.samples/xsd&quot;&gt;&lt;m:Code&gt;&lt;/m:Code&gt;&lt;m:Price&gt;&lt;/m:Price&gt;&lt;/m:CheckPriceResponse&gt;'
                newResponse.root.elements[1].text = $mc.getPayloadXML().root.elements[1].elements[1].get_text
                newResponse.root.elements[2].text = $mc.getPayloadXML().root.elements[1].elements[2].get_text
                $mc.setPayloadXML(newResponse)
            ]]&gt;
        &lt;/script&gt;
        &lt;send/&gt;
    &lt;/out&gt;
&lt;/definitions&gt; </pre>
<p>
<strong>Objective: Script mediators using Ruby(In-line Ruby Script)</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>This sample uses Ruby so first setup support for this in Synapse as described at
<a href="Synapse_Samples_Setup.html#script">Configuring JRuby</a>
<br/>Start the Synapse configuration numbered 354: i.e. bin/synapse -sample 354
<br/> Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>

<p>This sample is functionally equivalent to the sample 353. </p>
<p>Run the client with </p>
<pre xml:space="preserve"> ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote</pre></div>
<h2>
<a name="DBMediators" id="DBMediators">Database interactions in mediation (DBLookup / DBReport)</a></h2>
<p>Following database mediators use Derby in a client/server configuration by using the network server. Therefore, to proceed with the following samples, you need a working Derby database server and you have to follow the steps in 
<a href="Synapse_Samples_Setup.html#derby">Sample Setup Guide</a> before going through the samples. </p>

<h2>
<a name="Sample360" id="Sample360">Sample 360: Introduction to dblookup mediator</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

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

    &lt;sequence name=&quot;main&quot; onError=&quot;myFaultHandler&quot;&gt;
        &lt;in&gt;
            &lt;log level=&quot;custom&quot;&gt;
                &lt;property name=&quot;text&quot;
                          value=&quot;** Looking up from the Database **&quot;/&gt;
            &lt;/log&gt;
            &lt;dblookup xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
                &lt;connection&gt;
                    &lt;pool&gt;
                        &lt;driver&gt;org.apache.derby.jdbc.ClientDriver&lt;/driver&gt;
                        &lt;url&gt;jdbc:derby://localhost:1527/synapsedb;create=false&lt;/url&gt;
                        &lt;user&gt;synapse&lt;/user&gt;
                        &lt;password&gt;synapse&lt;/password&gt;
                    &lt;/pool&gt;
                &lt;/connection&gt;
                &lt;statement&gt;
                    &lt;sql&gt;select * from company where name =?&lt;/sql&gt;
                    &lt;parameter expression=&quot;//m0:getQuote/m0:request/m0:symbol&quot;
                               xmlns:m0=&quot;http://services.samples&quot; type=&quot;VARCHAR&quot;/&gt;
                    &lt;result name=&quot;company_id&quot; column=&quot;id&quot;/&gt;
                &lt;/statement&gt;
            &lt;/dblookup&gt;

            &lt;switch source=&quot;get-property('company_id')&quot;&gt;
                &lt;case regex=&quot;c1&quot;&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot;
                                  expression=&quot;fn:concat('Company ID - ',get-property('company_id'))&quot;/&gt;
                    &lt;/log&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;/case&gt;
                &lt;case regex=&quot;c2&quot;&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot;
                                  expression=&quot;fn:concat('Company ID - ',get-property('company_id'))&quot;/&gt;
                    &lt;/log&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;/case&gt;
                &lt;case regex=&quot;c3&quot;&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot;
                                  expression=&quot;fn:concat('Company ID - ',get-property('company_id'))&quot;/&gt;
                    &lt;/log&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;/case&gt;
                &lt;default&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot; value=&quot;** Unrecognized Company ID **&quot;/&gt;
                    &lt;/log&gt;
                    &lt;makefault response=&quot;true&quot;&gt;
                        &lt;code value=&quot;tns:Receiver&quot;
                              xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
                        &lt;reason value=&quot;** Unrecognized Company ID **&quot;/&gt;
                    &lt;/makefault&gt;
                    &lt;send/&gt;
                    &lt;drop/&gt;
                &lt;/default&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:Introduction to the dblookup mediator</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Setting up Derby database as explained above.
<br/>Start the Synapse configuration numbered 360: i.e. synapse -sample 360
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done</p>

<p>This sample demonstrates simple database read operations through Synapse. When a message arrives at dblookup mediator, it opens a connection to the database and executes the SQL query. The SQL query use '?' character for attributes that will be filled at runtime. The parameters define how to calculate the value of those attributes at runtime. In this sample a dblookup mediator has been used to extract 'id' of the company from the company database using the symbol which is evaluated using an xpath against the SOAP envelope. Then 'id' base switching will be done by a switch mediator. </p>

<p>When the IBM stock quote is requested, </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</pre>
<p>Synapse console shows </p>
<pre xml:space="preserve">INFO LogMediator text = ** Looking up from the Database **INFO LogMediator text = Company ID &#x2013; c1
<br/></pre>

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

<p>Synapse console shows </p>
<pre xml:space="preserve">INFO LogMediator text = ** Looking up from the Database **INFO LogMediator text = Company ID &#x2013; c2
<br/></pre>
<p>and for the MSFT stock quote, </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT</pre>
<pre xml:space="preserve">INFO LogMediator text = ** Looking up from the Database **
<br/>INFO LogMediator text = Company ID &#x2013; c2</pre>
<p>For any other symbols, Synapse console shows </p>
<pre xml:space="preserve">INFO LogMediator text = ** Unrecognized Company ID **</pre>

<p>and the client gets a response which has following message. </p>
<pre xml:space="preserve">** Unrecognized Company ID **</pre>
<p/>
<h2>
<a name="Sample361" id="Sample361">Sample 361: Introduction to dbreport mediator</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;sequence name=&quot;main&quot;&gt;
        &lt;in&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;/in&gt;

        &lt;out&gt;
            &lt;log level=&quot;custom&quot;&gt;
                &lt;property name=&quot;text&quot;
                          value=&quot;** Reporting to the Database **&quot;/&gt;
            &lt;/log&gt;
            &lt;dbreport xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
                &lt;connection&gt;
                    &lt;pool&gt;
                        &lt;driver&gt;org.apache.derby.jdbc.ClientDriver&lt;/driver&gt;
                        &lt;url&gt;jdbc:derby://localhost:1527/synapsedb;create=false&lt;/url&gt;
                        &lt;user&gt;synapse&lt;/user&gt;
                        &lt;password&gt;synapse&lt;/password&gt;
                    &lt;/pool&gt;
                &lt;/connection&gt;
                &lt;statement&gt;
                    &lt;sql&gt;update company set price=? where name =?&lt;/sql&gt;
                    &lt;parameter expression=&quot;//m0:return/m0:last/child::text()&quot;
                               xmlns:m0=&quot;http://services.samples/xsd&quot; type=&quot;DOUBLE&quot;/&gt;
                    &lt;parameter expression=&quot;//m0:return/m0:symbol/child::text()&quot;
                               xmlns:m0=&quot;http://services.samples/xsd&quot; type=&quot;VARCHAR&quot;/&gt;
                &lt;/statement&gt;
            &lt;/dbreport&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</pre>
<div>
<p>
<strong>Objective:Introduction to the dbreport mediator</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Setting up Derby database as above.
<br/>Start the Synapse configuration numbered 361: i.e. synapse -sample 361
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done</p></div>
<p>This sample demonstrates simple database write operations. The dbreport mediator writes (i.e. inserts one row) to a table using the message details. It works the same as the dblookup mediator. In this sample , dbreport mediator is used for updating the stock price of the company using the last quote value which is calculated by evaluating an XPath against the response message. After running this sample, user can check the company table using the Derby client tool. It will show the inserted value by the dbreport mediator. </p>
<p>Run the client using, </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</pre>
<p>and then execute the following query using database client tool against synapsedb. </p>
<pre xml:space="preserve">select price from company where name='IBM';</pre>
<p>It will show some value as follows. </p>
<pre xml:space="preserve">96.39535981018865</pre>
<p/>
<h2>
<a name="Sample362" id="Sample362">Sample 362: Action of dbreport and dblookup mediators together</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;sequence name="main" trace="enable"&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;log level="custom"&gt;
                &lt;property name="text" value="** Reporting to the Database **"/&gt;
            &lt;/log&gt;

            &lt;dbreport&gt;
                &lt;connection&gt;
                    &lt;pool&gt;
                        &lt;driver&gt;com.mysql.jdbc.Driver&lt;/driver&gt;
                        &lt;url&gt;jdbc:mysql://localhost:3306/synapsedb&lt;/url&gt;
                        &lt;user&gt;root&lt;/user&gt;
                        &lt;password&gt;root123&lt;/password&gt;
                    &lt;/pool&gt;
                &lt;/connection&gt;
                &lt;statement&gt;
                    &lt;sql&gt;update company set price=? where name =?&lt;/sql&gt;
                    &lt;parameter xmlns:m1="http://services.samples/xsd"
                               xmlns:m0="http://services.samples"
                               expression="//m0:return/m1:last/child::text()" type="DOUBLE"/&gt;
                    &lt;parameter xmlns:m1="http://services.samples/xsd"
                               xmlns:m0="http://services.samples"
                               expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/&gt;
                &lt;/statement&gt;
            &lt;/dbreport&gt;
            &lt;log level="custom"&gt;
                &lt;property name="text" value="** Looking up from the Database **"/&gt;
            &lt;/log&gt;
            &lt;dblookup&gt;
                &lt;connection&gt;
                    &lt;pool&gt;
                        &lt;driver&gt;com.mysql.jdbc.Driver&lt;/driver&gt;
                        &lt;url&gt;jdbc:mysql://localhost:3306/synapsedb&lt;/url&gt;
                        &lt;user&gt;root&lt;/user&gt;
                        &lt;password&gt;root123&lt;/password&gt;
                    &lt;/pool&gt;
                &lt;/connection&gt;
                &lt;statement&gt;
                    &lt;sql&gt;select * from company where name =?&lt;/sql&gt;
                    &lt;parameter xmlns:m1="http://services.samples/xsd"
                               xmlns:m0="http://services.samples"
                               expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/&gt;
                    &lt;result name="stock_price" column="price"/&gt;
                &lt;/statement&gt;
            &lt;/dblookup&gt;
            &lt;log level="custom"&gt;
                &lt;property name="text"
                          expression="fn:concat('Stock price - ',get-property('stock_price'))"/&gt;
            &lt;/log&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the use of dbreport and dblookup mediators</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Setting up Derby database as above
<br/>Start the Synapse configuration numbered 362: i.e. synapse -sample 362
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done</p>

<p>In this sample ,the dbreport mediator works the same as the above sample. It updates the price for the given company using the response messages content. Then the dblookup mediator reads the last updated value from the company database and logs it. </p>
<p>When running client, </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</pre>
<p>Synapse console shows, </p>
<pre xml:space="preserve">INFO LogMediator text = ** Reporting to the Database **
...
INFO LogMediator text = ** Looking up from the Database **
...
INFO LogMediator text = Stock price - 153.47886496064808</pre>
<p/>
<h2>
<a name="Sample363" id="Sample363">Sample 363: Reusable database connection pools</a></h2>
<div>
<p>Prior to run this sample please follow the 'Setting up Synapse DataSources' section in the 
<a href="Synapse_Samples_Setup.html">sample setup guide</a>.</p>
<pre>&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;sequence name=&quot;myFaultHandler&quot;&gt;
        &lt;makefault response=&quot;true&quot;&gt;
            &lt;code value=&quot;tns:Receiver&quot; xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
            &lt;reason expression=&quot;get-property('ERROR_MESSAGE')&quot;/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
        &lt;drop/&gt;
    &lt;/sequence&gt;

    &lt;sequence name=&quot;main&quot; onError=&quot;myFaultHandler&quot;&gt;
        &lt;in&gt;
            &lt;log level=&quot;custom&quot;&gt;
                &lt;property name=&quot;text&quot; value=&quot;** Looking up from the Database **&quot;/&gt;
            &lt;/log&gt;
            &lt;dblookup&gt;
                &lt;connection&gt;
                    &lt;pool&gt;
                        &lt;dsName&gt;lookupdb&lt;/dsName&gt;
                        &lt;icClass&gt;com.sun.jndi.rmi.registry.RegistryContextFactory&lt;/icClass&gt;
                        &lt;url&gt;rmi://localhost:2199&lt;/url&gt;
                        &lt;user&gt;synapse&lt;/user&gt;
                        &lt;password&gt;synapse&lt;/password&gt;
                    &lt;/pool&gt;
                &lt;/connection&gt;
                &lt;statement&gt;
                    &lt;sql&gt;select * from company where name =?&lt;/sql&gt;
                    &lt;parameter expression=&quot;//m0:getQuote/m0:request/m0:symbol&quot; xmlns:m0=&quot;http://services.samples&quot; type=&quot;VARCHAR&quot;/&gt;
                    &lt;result name=&quot;company_id&quot; column=&quot;id&quot;/&gt;
                &lt;/statement&gt;
            &lt;/dblookup&gt;
            &lt;switch source=&quot;get-property('company_id')&quot;&gt;
                &lt;case regex=&quot;c1&quot;&gt;
                    &lt;log level=&quot;custom&quot;&gt; &lt;
                        property name=&quot;text&quot; expression=&quot;fn:concat('Company ID - ',get-property('company_id'))&quot;/&gt;
                    &lt;/log&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;/case&gt;
                &lt;case regex=&quot;c2&quot;&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot; expression=&quot;fn:concat('Company ID - ',get-property('company_id'))&quot;/&gt;
                    &lt;/log&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;/case&gt;
                &lt;case regex=&quot;c3&quot;&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot; expression=&quot;fn:concat('Company ID - ',get-property('company_id'))&quot;/&gt;
                    &lt;/log&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;/case&gt;
                &lt;default&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot; value=&quot;** Unrecognized Company ID **&quot;/&gt;
                    &lt;/log&gt;
                    &lt;makefault response=&quot;true&quot;&gt;
                        &lt;code value=&quot;tns:Receiver&quot; xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
                        &lt;reason value=&quot;** Unrecognized Company ID **&quot;/&gt;
                    &lt;/makefault&gt;
                    &lt;send/&gt;
                    &lt;drop/&gt;
                &lt;/default&gt;
            &lt;/switch&gt;
        &lt;drop/&gt;
    &lt;/in&gt;
    &lt;out&gt;
        &lt;log level=&quot;custom&quot;&gt;
            &lt;property name=&quot;text&quot; value=&quot;** Reporting to the Database **&quot;/&gt;
        &lt;/log&gt;
        &lt;dbreport&gt;
            &lt;connection&gt;
                &lt;pool&gt;
                    &lt;dsName&gt;reportdb&lt;/dsName&gt;
                    &lt;icClass&gt;com.sun.jndi.rmi.registry.RegistryContextFactory&lt;/icClass&gt;
                    &lt;url&gt;rmi://localhost:2199&lt;/url&gt;
                    &lt;user&gt;synapse&lt;/user&gt;
                    &lt;password&gt;synapse&lt;/password&gt;
                &lt;/pool&gt;
            &lt;/connection&gt;
            &lt;statement&gt;
                &lt;sql&gt;update company set price=? where name =?&lt;/sql&gt;
                &lt;parameter expression=&quot;//m0:return/m0:last/child::text()&quot; xmlns:m0=&quot;http://services.samples/xsd&quot; type=&quot;DOUBLE&quot;/&gt;
                &lt;parameter expression=&quot;//m0:return/m0:symbol/child::text()&quot; xmlns:m0=&quot;http://services.samples/xsd&quot; type=&quot;VARCHAR&quot;/&gt;
            &lt;/statement&gt;
        &lt;/dbreport&gt;
        &lt;log level=&quot;custom&quot;&gt;
            &lt;property name=&quot;text&quot; value=&quot;** Looking up from the Database **&quot;/&gt;
        &lt;/log&gt;
        &lt;dblookup&gt;
            &lt;connection&gt;
                &lt;pool&gt;
                    &lt;dsName&gt;reportdb&lt;/dsName&gt;
                    &lt;icClass&gt;com.sun.jndi.rmi.registry.RegistryContextFactory&lt;/icClass&gt;
                    &lt;url&gt;rmi://localhost:2199&lt;/url&gt;
                    &lt;user&gt;synapse&lt;/user&gt;
                    &lt;password&gt;synapse&lt;/password&gt;
                &lt;/pool&gt;
            &lt;/connection&gt;
            &lt;statement&gt;
                &lt;sql&gt;select * from company where name =?&lt;/sql&gt;
                &lt;parameter expression=&quot;//m0:return/m0:symbol/child::text()&quot; xmlns:m0=&quot;http://services.samples/xsd&quot; type=&quot;VARCHAR&quot;/&gt;
                &lt;result name=&quot;stock_price&quot; column=&quot;price&quot;/&gt;
            &lt;/statement&gt;
            &lt;/dblookup&gt;
            &lt;log level=&quot;custom&quot;&gt;
                &lt;property name=&quot;text&quot; expression=&quot;fn:concat('Stock price - ',get-property('stock_price'))&quot;/&gt;
            &lt;/log&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;</pre></div>
<div>
<p>
<strong>Objective: Demonstrate the use of reusable database connection pools</strong></p>
<p>
<strong>Prerequisites:</strong>
<br/>Set up the database and Data sources according to the
<a href="Synapse_Samples_Setup.html">sample setup guide</a>
<br/>Start the Synapse configuration numbered 363: i.e. synapse -sample 363
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>

<p>Runs the client as follows</p>
<pre>ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</pre>
<p>Then the console output </p>
<pre>INFO LogMediator text = ** Looking up from the Database ** ...
    INFO LogMediator text = Company ID - c1 ...
    INFO LogMediator text = ** Reporting to the Database ** ...
    INFO LogMediator text = ** Looking up from the Database ** ...
    INFO LogMediator text = Stock price - 183.3635460215262</pre></div>
<h2>
<a name="Sample364" id="Sample364">Sample 364: Executing database Stored Procedures</a></h2>
<div>
<p>This sample if functionally similar to sample 363 but uses a stored procedure to query
the database instead of direct SQL statements. Prior to running this sample please follow the
instructions given in the 'Setting up MySQL database server' section in the
<a href="Synapse_Samples_Setup.html#mysql">sample setup guide</a>.</p>

<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;sequence name="main"&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;endpoint&gt;
                    &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
        &lt;/in&gt;

        &lt;out&gt;
            &lt;log level="custom"&gt;
                &lt;property name="text" value="** Reporting to the Database **"/&gt;
            &lt;/log&gt;

            &lt;dbreport&gt;
                &lt;connection&gt;
                    &lt;pool&gt;
                        &lt;driver&gt;com.mysql.jdbc.Driver&lt;/driver&gt;
			&lt;url&gt;jdbc:mysql://localhost/synapsedb&lt;/url&gt;
			&lt;user&gt;root&lt;/user&gt;
			&lt;password&gt;admin&lt;/password&gt;
                    &lt;/pool&gt;
                &lt;/connection&gt;
                &lt;statement&gt;
                    &lt;sql&gt;call updateCompany(?,?)&lt;/sql&gt;
                    &lt;parameter expression="//m0:return/m1:last/child::text()" xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd" type="DOUBLE"/&gt;
                    &lt;parameter expression="//m0:return/m1:symbol/child::text()" xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd" type="VARCHAR"/&gt;
                &lt;/statement&gt;
            &lt;/dbreport&gt;
            &lt;log level="custom"&gt;
                &lt;property name="text" value="** Looking up from the Database **"/&gt;
            &lt;/log&gt;
            &lt;dblookup&gt;
                &lt;connection&gt;
                    &lt;pool&gt;
                        &lt;driver&gt;com.mysql.jdbc.Driver&lt;/driver&gt;
			&lt;url&gt;jdbc:mysql://localhost/synapsedb&lt;/url&gt;
			&lt;user&gt;root&lt;/user&gt;
			&lt;password&gt;admin&lt;/password&gt;
                    &lt;/pool&gt;
                &lt;/connection&gt;
                &lt;statement&gt;
                    &lt;sql&gt;call getCompany(?)&lt;/sql&gt;
                    &lt;parameter expression="//m0:return/m1:symbol/child::text()" xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd" type="VARCHAR"/&gt;
                    &lt;result name="stock_prize" column="price"/&gt;
                &lt;/statement&gt;
            &lt;/dblookup&gt;
            &lt;log level="custom"&gt;
                &lt;property name="text" expression="fn:concat('Stock Prize - ',get-property('stock_prize'))"/&gt;
            &lt;/log&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</pre></div>
<div>
<p>
<strong>Objective: Demonstrate the use of dblookup and dbreport mediators to execute a database Stored Procedures</strong></p>
<p>
<strong>Prerequisites:</strong>
<br/>Set up MySQL database server according to the
<a href="Synapse_Samples_Setup.html#mysql">sample setup guide</a>
<br/>Edit the synapse_sample_364.xml
configuration file and update the configuration with the appropriate database connection details
<br/>Start the Synapse configuration numbered 364: i.e. synapse -sample 364
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done </p>
<p>Run the client as follows</p>
<pre>ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</pre>
<p>Then you will get the following console output </p>
<pre>INFO LogMediator text = ** Looking up from the Database ** ... 
INFO LogMediator text = Company ID - c1 ...  
INFO LogMediator text = Stock price - 183.3635460215262</pre></div>
<h2>
<a name="Throttle" id="Throttle">Throttling messages (Throttle Mediator)</a></h2>
<h2>
<a name="Sample370" id="Sample370">Sample 370: Introduction to throttle mediator and concurrency throttling</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;sequence name=&quot;main&quot;&gt;
        &lt;in&gt;
            &lt;throttle id=&quot;A&quot;&gt;
                &lt;policy&gt;
                    &lt;!-- define throttle policy --&gt;
                    &lt;wsp:Policy xmlns:wsp=&quot;http://schemas.xmlsoap.org/ws/2004/09/policy&quot;
                                xmlns:throttle=&quot;http://www.wso2.org/products/wso2commons/throttle&quot;&gt;
                        &lt;throttle:ThrottleAssertion&gt;
                            &lt;throttle:MaximumConcurrentAccess&gt;10&lt;/throttle:MaximumConcurrentAccess&gt;
                        &lt;/throttle:ThrottleAssertion&gt;
                    &lt;/wsp:Policy&gt;
                &lt;/policy&gt;
                &lt;onAccept&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot; value=&quot;**Access Accept**&quot;/&gt;
                    &lt;/log&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;/onAccept&gt;
                &lt;onReject&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot; value=&quot;**Access Denied**&quot;/&gt;
                    &lt;/log&gt;
                    &lt;makefault response=&quot;true&quot;&gt;
                        &lt;code value=&quot;tns:Receiver&quot;
                              xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
                        &lt;reason value=&quot;**Access Denied**&quot;/&gt;
                    &lt;/makefault&gt;
                    &lt;send/&gt;
                    &lt;drop/&gt;
                &lt;/onReject&gt;
            &lt;/throttle&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;throttle id=&quot;A&quot;/&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: </strong>Demonstrate the use of throttle mediator for concurrency throttling </p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 370 (i.e. synapse -sample 370)</p>

<p>Above configuration specifies a throttle mediator inside the in mediator. Therefore, all request messages directed to the main sequence will be subjected to throttling. Throttle mediator has 'policy', 'onAccept' and 'onReject' tags at top level. The 'policy' tag specifies the throttling policy for throttling messages. This sample policy only contains a component called &quot;MaximumConcurrentAccess&quot;. This indicates the maximum number of concurrent requests that can pass through Synapse on a single unit of time. To test concurrency throttling, it is required to send concurrent requests to Synapse. If Synapse with above configuration, receives 20 requests concurrently from clients, then approximately half of those will succeed while the others being throttled. The client command to try this is as follows. </p>
<pre xml:space="preserve">ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280/</pre>
<p/>
<h2>
<a name="Sample371" id="Sample371">Sample 371: Restricting requests based on policies </a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;sequence name=&quot;main&quot;&gt;
        &lt;in&gt;
            &lt;throttle id=&quot;A&quot;&gt;
                &lt;policy&gt;
                    &lt;!-- define throttle policy --&gt;
                    &lt;wsp:Policy xmlns:wsp=&quot;http://schemas.xmlsoap.org/ws/2004/09/policy&quot;
                                xmlns:throttle=&quot;http://www.wso2.org/products/wso2commons/throttle&quot;&gt;
                        &lt;throttle:ThrottleAssertion&gt;   
<br/>                                   &lt;wsp:All&gt;
                                &lt;throttle:ID throttle:type=&quot;IP&quot;&gt;Other&lt;/throttle:ID&gt;
                                &lt;wsp:ExactlyOne&gt;
                                    &lt;wsp:All&gt;
                                        &lt;throttle:MaximumCount&gt;4&lt;/throttle:MaximumCount&gt;
                                        &lt;throttle:UnitTime&gt;800000&lt;/throttle:UnitTime&gt;
                                        &lt;throttle:ProhibitTimePeriod wsp:Optional=&quot;true&quot;&gt;10000&lt;/throttle:ProhibitTimePeriod&gt;
                                    &lt;/wsp:All&gt;
                                    &lt;throttle:IsAllow&gt;true&lt;/throttle:IsAllow&gt;
                                &lt;/wsp:ExactlyOne&gt;
                            &lt;/wsp:All&gt;
                            &lt;wsp:All&gt;
                                &lt;throttle:ID throttle:type=&quot;IP&quot;&gt;192.168.8.200-192.168.8.222&lt;/throttle:ID&gt;
                                &lt;wsp:ExactlyOne&gt;
                                    &lt;wsp:All&gt;
                                        &lt;throttle:MaximumCount&gt;8&lt;/throttle:MaximumCount&gt;
                                        &lt;throttle:UnitTime&gt;800000&lt;/throttle:UnitTime&gt;
                                        &lt;throttle:ProhibitTimePeriod wsp:Optional=&quot;true&quot;&gt;10&lt;/throttle:ProhibitTimePeriod&gt;
                                    &lt;/wsp:All&gt;
                                    &lt;throttle:IsAllow&gt;true&lt;/throttle:IsAllow&gt;
                                &lt;/wsp:ExactlyOne&gt;
                            &lt;/wsp:All&gt;
                            &lt;wsp:All&gt;
                                &lt;throttle:ID throttle:type=&quot;IP&quot;&gt;192.168.8.201&lt;/throttle:ID&gt;
                                &lt;wsp:ExactlyOne&gt;
                                    &lt;wsp:All&gt;
                                        &lt;throttle:MaximumCount&gt;200&lt;/throttle:MaximumCount&gt;
                                        &lt;throttle:UnitTime&gt;600000&lt;/throttle:UnitTime&gt;
                                        &lt;throttle:ProhibitTimePeriod wsp:Optional=&quot;true&quot;&gt;&lt;/throttle:ProhibitTimePeriod&gt;
                                    &lt;/wsp:All&gt;
                                    &lt;throttle:IsAllow&gt;true&lt;/throttle:IsAllow&gt;
                                &lt;/wsp:ExactlyOne&gt;
                            &lt;/wsp:All&gt;
                            &lt;wsp:All&gt;
                                &lt;throttle:ID throttle:type=&quot;IP&quot;&gt;192.168.8.198&lt;/throttle:ID&gt;
                                &lt;wsp:ExactlyOne&gt;
                                    &lt;wsp:All&gt;
                                        &lt;throttle:MaximumCount&gt;50&lt;/throttle:MaximumCount&gt;
                                        &lt;throttle:UnitTime&gt;500000&lt;/throttle:UnitTime&gt;
                                        &lt;throttle:ProhibitTimePeriod wsp:Optional=&quot;true&quot;&gt;&lt;/throttle:ProhibitTimePeriod&gt;
                                    &lt;/wsp:All&gt;
                                    &lt;throttle:IsAllow&gt;true&lt;/throttle:IsAllow&gt;
                                &lt;/wsp:ExactlyOne&gt;
                            &lt;/wsp:All&gt;
                        &lt;/throttle:ThrottleAssertion&gt;
                    &lt;/wsp:Policy&gt;
                &lt;/policy&gt;
                &lt;onAccept&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot; value=&quot;**Access Accept**&quot;/&gt;
                    &lt;/log&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;/onAccept&gt;
                &lt;onReject&gt;
                    &lt;log level=&quot;custom&quot;&gt;
                        &lt;property name=&quot;text&quot; value=&quot;**Access Denied**&quot;/&gt;
                    &lt;/log&gt;
                    &lt;makefault response=&quot;true&quot;&gt;
                        &lt;code value=&quot;tns:Receiver&quot;
                              xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
                        &lt;reason value=&quot;**Access Denied**&quot;/&gt;
                    &lt;/makefault&gt;
                    &lt;send/&gt;
                    &lt;drop/&gt;
                &lt;/onReject&gt;
            &lt;/throttle&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;throttle id=&quot;A&quot;/&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the use of throttle mediator for restricting request counts</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 371 (i.e. synapse -sample 371)</p>

<p>Above configuration specifies a throttle mediator inside the in mediator. Therefore, all request messages directed to the main sequence will be subjected to throttling. Throttle mediator has policy, onAccept and onReject tags at the top level. Policy tag specifies the throttling policy to be applied for messages. It contains some IP address ranges and the maximum number of messages to be allowed for those ranges within a time period given in &quot;UnitTime&quot; tag. &quot;ProhibitTimePeriod&quot; tag specifies the time period to prohibit further requests after the received request count exceeds the specified time. Now run the client 5 times repetitively using the following command to see how throttling works. </p>
<pre xml:space="preserve">ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280/</pre>
<p>For the first four requests you will get the quote prices for IBM as follows. </p>
<pre xml:space="preserve">[java] Standard :: Stock price = $177.20143371883802</pre>
<p>You will receive the following response for the fifth request. </p>
<pre xml:space="preserve">[java] org.apache.axis2.AxisFault: **Access Denied**</pre>
<p>Maximum number of requests within 800000 milliseconds is specified as 4 for any server (including localhost) other than the explicitly specified ones. Therefore, our fifth request is denied by the throttle mediator. You can verify this by looking at the Synapse console. </p>
<pre xml:space="preserve">[HttpServerWorker-1] INFO  LogMediator - text = **Access Accept**
[HttpServerWorker-2] INFO  LogMediator - text = **Access Accept**
[HttpServerWorker-3] INFO  LogMediator - text = **Access Accept**
[HttpServerWorker-4] INFO  LogMediator - text = **Access Accept**
[HttpServerWorker-5] INFO  LogMediator - text = **Access Denied** </pre>
<h2>
<a name="Sample372" id="Sample372">Sample 372: Use of both concurrency throttling and request rate based throttling </a></h2>
<pre xml:space="preserve">&lt;!-- Use of both concurrency throttling and request rate based throttling --&gt;
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;registry provider=&quot;org.apache.synapse.registry.url.SimpleURLRegistry&quot;&gt;
        &lt;!-- the root property of the simple URL registry helps resolve a resource URL as root + key --&gt;
        &lt;parameter name=&quot;root&quot;&gt;file:repository/&lt;/parameter&gt;
        &lt;!-- all resources loaded from the URL registry would be cached for this number of milli seconds --&gt;
        &lt;parameter name=&quot;cachableDuration&quot;&gt;150000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;sequence name=&quot;onAcceptSequence&quot;&gt;
        &lt;log level=&quot;custom&quot;&gt;
            &lt;property name=&quot;text&quot; value=&quot;**Access Accept**&quot;/&gt;
        &lt;/log&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;/sequence&gt;
    &lt;sequence name=&quot;onRejectSequence&quot; trace=&quot;enable&quot;&gt;
        &lt;log level=&quot;custom&quot;&gt;
            &lt;property name=&quot;text&quot; value=&quot;**Access Denied**&quot;/&gt;
        &lt;/log&gt;
        &lt;makefault response=&quot;true&quot;&gt;
            &lt;code value=&quot;tns:Receiver&quot;
                  xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
            &lt;reason value=&quot;**Access Denied**&quot;/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
        &lt;drop/&gt;
    &lt;/sequence&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot;&gt;
        &lt;target&gt;
             &lt;inSequence&gt;
                &lt;throttle onReject=&quot;onRejectSequence&quot; onAccept=&quot;onAcceptSequence&quot; id=&quot;A&quot;&gt;
                    &lt;policy key=&quot;conf/sample/resources/policy/throttle_policy.xml&quot;/&gt;
                &lt;/throttle&gt;
            &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;throttle id=&quot;A&quot;/&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Use of both concurrency throttling and request rate based throttling </strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 372 (i.e. synapse -sample 372)</p>
<p>Throttle policy is loaded from the &#x201c;throttle_policy. xml&#x201d; . That policy contains merging policy from sample 370 and 371. To check the functionality, it requires to run a load test. The all enabled request from the concurrency throttling will be controlled by the access rate base throttling according to the policy. </p>
<p>Run the client as follows </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy</pre>
<div>
<p>You will get same results as in sample 371. If you run the load test, results will be different due to the effect of concurrency throttling. </p></div>
<h2>
<a name="Class" id="Class">Extending the mediation in java (Class Mediator)</a></h2>
<p>Class mediator can be used to write your own custom mediation in Java and you have access to the SynapseMessageContext and to the full Synapse API in there. This is a useful extension mechanism within Synapse to extend its functionality. This class can contain fields for which you can assign values at runtime through the configuration. </p>
<h2>
<a name="Sample380" id="Sample380">Sample 380: Writing your own custom mediation in Java</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;sequence name=&quot;fault&quot;&gt;
        &lt;makefault&gt;
            &lt;code value=&quot;tns:Receiver&quot; xmlns:tns=&quot;http://www.w3.org/2003/05/soap-envelope&quot;/&gt;
            &lt;reason value=&quot;Mediation failed.&quot;/&gt;
        &lt;/makefault&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

    &lt;sequence name=&quot;main&quot; onError=&quot;fault&quot;&gt;
        &lt;in&gt;
            &lt;send&gt;
                &lt;endpoint name=&quot;stockquote&quot;&gt;
                    &lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;
                &lt;/endpoint&gt;
            &lt;/send&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;class name=&quot;samples.mediators.DiscountQuoteMediator&quot;&gt;
                &lt;property name=&quot;discountFactor&quot; value=&quot;10&quot;/&gt;
                &lt;property name=&quot;bonusFor&quot; value=&quot;5&quot;/&gt;
            &lt;/class&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;

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

<p>
<strong>Objective: Demonstrate the use of Class mediator to extend the mediation functionality</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Make sure the synapse-samples-1.0.jar is in your class path (by default this jar is placed in the lib directory when installing Synapse)
<br/>Start Synapse with the sample configuration 380 (i.e. synapse -sample 380)
<br/>Start the sample Axis2 server and deploy the SimpleStockQuoteService. </p>

<p>In this configuration, Synapse hands over the request message to the specified endpoint, which sends it to the Axis2 server running on port 9000. </p>
<p>But the response message is passed through the class mediator before sending it back to the client. Two parameters named &quot;discountFactor&quot; </p>
<p>and &quot;bonusFor&quot; are passed to the instance mediator implementation class (i.e. samples.mediators.DiscountQuoteMediator) before each </p>
<p>invocation. Code of the mediator implementation class is shown below. </p>
<pre xml:space="preserve">package samples.mediators;

import org.apache.synapse.MessageContext;
import org.apache.synapse.Mediator;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.xml.namespace.QName;

public class DiscountQuoteMediator implements Mediator {

    private static final Log log = LogFactory.getLog(DiscountQuoteMediator.class);

    private String discountFactor=&quot;10&quot;;

    private String bonusFor=&quot;10&quot;;

    private int bonusCount=0;

    public DiscountQuoteMediator(){}

    public boolean mediate(MessageContext mc) {

        String price= mc.getEnvelope().getBody().getFirstElement().getFirstElement().
                getFirstChildWithName(new QName(&quot;http://services.samples/xsd&quot;,&quot;last&quot;)).getText();

        //converting String properties into integers
        int discount=Integer.parseInt(discountFactor);
        int bonusNo=Integer.parseInt(bonusFor);
        double currentPrice=Double.parseDouble(price);

        //discounting factor is deducted from current price form every response
        Double lastPrice = new Double(currentPrice - currentPrice * discount / 100);

        //Special discount of 5% offers for the first responses as set in the bonusFor property
        if (bonusCount &lt;= bonusNo) {
            lastPrice = new Double(lastPrice.doubleValue() - lastPrice.doubleValue() * 0.05);
            bonusCount++;
        }

        String discountedPrice = lastPrice.toString();

        mc.getEnvelope().getBody().getFirstElement().getFirstElement().getFirstChildWithName
                (new QName(&quot;http://services.samples/xsd&quot;,&quot;last&quot;)).setText(discountedPrice);

        System.out.println(&quot;Quote value discounted.&quot;);
        System.out.println(&quot;Original price: &quot; + price);
        System.out.println(&quot;Discounted price: &quot; + discountedPrice);

        return true;
    }

    public String getType() {
        return null;
    }

    public void setTraceState(int traceState) {
        traceState = 0;
    }

    public int getTraceState() {
        return 0;
    }

    public void setDiscountFactor(String discount) {
        discountFactor=discount;
    }

    public String getDiscountFactor() {
        return discountFactor;
    }

    public void setBonusFor(String bonus){
        bonusFor=bonus;
    }

    public String getBonusFor(){
        return bonusFor;
    }
}</pre>
<p>All classes developed for class mediation should implement the Mediator interface, which contains the mediate(...) method. mediate(...) method of the above class is invoked for each response message mediated through the main sequence, with the message context of the current message as the parameter. All details of the message including the SOAP headers, SOAP body and properties of the context hierarchy can be accessed from the message context. In this sample, the body of the message is retrieved and the discount percentage is subtracted from the quote price. If the quote request number is less than the number specified in the &quot;bonusFor&quot; property in the configuration, a special discount is given. </p>

<p>Now run the client using the following command. </p>
<pre xml:space="preserve">ant stockquote -Dsymbol=IBM -Dmode=quote -Daddurl=http://localhost:8280</pre>
<p>You will see the below output in the client console with the discounted quote value. </p>
<pre xml:space="preserve">[java] Standard :: Stock price = $138.77458254967408</pre>
<p>Now check the console running Synapse. You will see the original value and the discounted value for the requested quote as follows. </p>
<pre xml:space="preserve">Quote value discounted.
Original price: 162.30945327447262
Discounted price: 138.77458254967408</pre>
<p/>
<h2>        
<a name="Sample381" id="Sample381">Sample 381:Class mediator to CBR binary messages</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
	&lt;proxy name=&quot;JMSBinaryProxy&quot; transports=&quot;jms&quot;&gt;
		&lt;target inSequence=&quot;BINARY_CBR_SEQ&quot; /&gt;
	&lt;/proxy&gt;
	&lt;sequence name=&quot;BINARY_CBR_SEQ&quot;&gt;
		&lt;in&gt;
			&lt;log level=&quot;full&quot; /&gt;
			&lt;property action=&quot;set&quot; name=&quot;OUT_ONLY&quot; value=&quot;true&quot; /&gt;
			&lt;class name=&quot;samples.mediators.BinaryExtractMediator&quot;&gt;
				&lt;property name=&quot;offset&quot; value=&quot;11&quot; /&gt;
				&lt;property name=&quot;length&quot; value=&quot;4&quot; /&gt;
				&lt;property name=&quot;variableName&quot; value=&quot;symbol&quot; /&gt;
				&lt;property name=&quot;binaryEncoding&quot; value=&quot;utf-8&quot; /&gt;
			&lt;/class&gt;
			&lt;log level=&quot;custom&quot;&gt;
				&lt;property name=&quot;symbol&quot;
					expression=&quot;get-property('symbol')&quot; /&gt;
			&lt;/log&gt;
			&lt;switch source=&quot;get-property('symbol')&quot;&gt;
				&lt;case regex=&quot;GOOG&quot;&gt;
					&lt;send&gt;
						&lt;endpoint&gt;
							&lt;address
								uri=&quot;jms:/dynamicTopics/mdd.GOOG?transport.jms.ConnectionFactoryJNDIName=TopicConnectionFactory&amp;amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;amp;java.naming.provider.url=tcp://localhost:61616&amp;amp;transport.jms.DestinationType=topic&quot; /&gt;
						&lt;/endpoint&gt;
					&lt;/send&gt;
				&lt;/case&gt;
				&lt;case regex=&quot;MSFT&quot;&gt;
					&lt;send&gt;
						&lt;endpoint&gt;
							&lt;address
								uri=&quot;jms:/dynamicTopics/mdd.MSFT?transport.jms.ConnectionFactoryJNDIName=TopicConnectionFactory&amp;amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;amp;java.naming.provider.url=tcp://localhost:61616&amp;amp;transport.jms.DestinationType=topic&quot; /&gt;
						&lt;/endpoint&gt;
					&lt;/send&gt;
				&lt;/case&gt;
				&lt;default&gt;&lt;/default&gt;
			&lt;/switch&gt;
		&lt;/in&gt;
	&lt;/sequence&gt;
&lt;/definitions&gt;</pre>

<p>
<strong>Objective: Demonstrate on CBR a message with binary payload</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Make sure the synapse-samples-1.0.jar is in your class path (by default this jar is placed in the lib directory when installing Synapse)
<br/>Configure JMS transport using ActiveMQ (refer <a href="Synapse_Samples_Setup.html">Sample Configuration Guide </a>)
<br/>Start Synapse with the sample configuration 381 (i.e. synapse -sample 381) </p>

<p>In this configuration, a proxy has configured to accept incoming JMS messages. JMS messages contains a binary payload. User configure the offset, length, binary encoding of the text literal that it need to use for CBR. And a variable name to set the  decoded value as a property. Configuration simply route the messages based on the text to different endpoints. </p>
<p>A JMS producer and two instances of a consumer used to demonstrate the CBR functionality.</p>
<p>Now run the first consumer using the following command. </p>
<pre xml:space="preserve">ant mddconsumer -Djms_topic=mdd.MSFT</pre>
<p>Now run the second consumer using the following command. </p>
<pre xml:space="preserve">ant mddconsumer -Djms_topic=mdd.GOOG</pre>
<p>Now run the market data producer to genenrate market data for symbol 'MSFT' using the following command. </p>
<pre xml:space="preserve">ant mddproducer -Dsymbol=MSFT</pre>
<p>Now run the market data producer to genenrate market data for symbol 'GOOG' using the following command. </p>
<pre xml:space="preserve">ant mddproducer -Dsymbol=GOOG</pre>
<p>You will see the below output in the client console(s) based on the symbol. </p>
<pre xml:space="preserve">mddconsumer:
     [java]  Market data recived for symbol : topic://mdd.MSFT
     [java]  Market data recived for symbol : topic://mdd.MSFT</pre>
<p/>
<h2>
<a name="XQuery" id="XQuery">Evaluating XQuery for mediation (XQuery Mediator)</a></h2>
<h2>
<a name="Sample390" id="Sample390">Sample 390: Introduction to the XQuery mediator</a></h2>
<pre xml:space="preserve">    &lt;!-- Introduction to the XQuery mediator --&gt;
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or http://) --&gt;
    &lt;registry provider=&quot;org.apache.synapse.registry.url.SimpleURLRegistry&quot;&gt;
        &lt;!-- the root property of the simple URL registry helps resolve a resource URL as root + key --&gt;
        &lt;parameter name=&quot;root&quot;&gt;file:repository/conf/sample/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=&quot;cachableDuration&quot;&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;localEntry key=&quot;xquery-key-req&quot;
                src=&quot;file:repository/conf/sample/resources/xquery/xquery_req.xq&quot;/&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;xquery key=&quot;xquery-key-req&quot;&gt;
                    &lt;variable name=&quot;payload&quot; type=&quot;ELEMENT&quot;/&gt;
                &lt;/xquery&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;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;out&gt;
                    &lt;xquery key=&quot;xquery/xquery_res.xq&quot;&gt;
                        &lt;variable name=&quot;payload&quot; type=&quot;ELEMENT&quot;/&gt;
                        &lt;variable name=&quot;code&quot; type=&quot;STRING&quot;
                                  expression=&quot;self::node()//m0:return/m0:symbol/child::text()&quot;
                                  xmlns:m0=&quot;http://services.samples/xsd&quot;/&gt;
                        &lt;variable name=&quot;price&quot; type=&quot;DOUBLE&quot;
                                  expression=&quot;self::node()//m0:return/m0:last/child::text()&quot;
                                  xmlns:m0=&quot;http://services.samples/xsd&quot;/&gt;
                    &lt;/xquery&gt;
                    &lt;send/&gt;
                &lt;/out&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;

&lt;/definitions&gt; </pre>
<p>
<strong>Objective: </strong>Introduction transformation using XQuery mediator </p>
<p>
<strong>Prerequisites</strong>:
<br/>Start the Synapse configuration numbered 390: i.e. synapse -sample 390
<br/>Start the Axis2 server and deploy the SimpleStockQuoteService if not already done. </p>

<p>This example uses the XQuery mediator to perform transformations. This sample behaves the same as sample number 8 and the only difference is that this sample uses XQuery instead of XSLT for transformation. </p>

<p>Execute the custom quote client as 'ant stockquote -Dmode=customquote ...' </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dmode=customquote </pre>
<p/>
<h2>
<a name="Sample391" id="Sample391">Sample 391: How to use data from an external XML document with in XQuery </a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;!-- the SimpleURLRegistry allows access to  URL based registry (e.g. file:/// or http://) --&gt;
    &lt;registry provider=&quot;org.apache.synapse.registry.url.SimpleURLRegistry&quot;&gt;
        &lt;!-- the root property of the simple URL registry helps resolve a resource URL as root + key --&gt;
        &lt;parameter name=&quot;root&quot;&gt;file:repository/conf/sample/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=&quot;cachableDuration&quot;&gt;15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;proxy name=&quot;StockQuoteProxy&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&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;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;out&gt;
                    &lt;xquery key=&quot;xquery/xquery_commisson.xq&quot;&gt;
                        &lt;variable name=&quot;payload&quot; type=&quot;ELEMENT&quot;&gt;&lt;/variable&gt;
                            &lt;variable name=&quot;commission&quot; type=&quot;ELEMENT&quot; key=&quot;misc/commission.xml&quot;&gt;&lt;/variable&gt;
                    &lt;/xquery&gt;
                    &lt;send/&gt;
                &lt;/out&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the use of XQuery mediator to import external XML documents to the XQuery engine</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 391 (i.e. synapse -sample 391). </p>
<p>In this sample, data from commission.xml document is used inside XQuery . The stock quote price from the response and commission from the commission.xml document will be added and given as a new price . </p>
<p>Invoke the client as follows. </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy</pre>
<h2>
<a name="Splitter" id="Splitter">Splitting messages in to parts and process in parallel (Iterate / Clone)</a></h2>
<h2>
<a name="Sample400" id="Sample400">Sample 400: Message splitting and aggregating the responses</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;

    &lt;proxy name=&quot;SplitAggregateProxy&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;iterate expression=&quot;//m0:getQuote/m0:request&quot; preservePayload=&quot;true&quot;
                         attachPath=&quot;//m0:getQuote&quot;
                         xmlns:m0=&quot;http://services.samples&quot;&gt;
                    &lt;target&gt;
                        &lt;sequence&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;/sequence&gt;
                    &lt;/target&gt;
                &lt;/iterate&gt;
            &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;aggregate&gt;
                    &lt;onComplete expression=&quot;//m0:getQuoteResponse&quot;
                                xmlns:m0=&quot;http://services.samples&quot;&gt;
                        &lt;send/&gt;
                    &lt;/onComplete&gt;
                &lt;/aggregate&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the use of Iterate mediator to split the messages in to parts and process them asynchronously and then aggregate the responses coming in to Synapse</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 400 (i.e. synapse -sample 400). </p>
<p>In this sample, the message sent to Synapse is comprised of a number of elements of the same type. When Synapse receives this message it will iterate through those elements and then will send to the specified endpoint. When all the responses appear to Synapse then those messages will be aggregated to form the resultant response and will send back to the client. </p>
<p>Invoke the client as follows. </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:8280/services/SplitAggregateProxy -Ditr=4</pre>
<h2>
<a name="Cache" id="Cache">Caching the responses over the requests (Cache Mediator)</a></h2>
<p>Cache mediator can be used to utilize the network bandwidth, to protect the backend service from being loaded with the same type of requests like browser refresh actions and also to speed up the execution of the web service. This mediator should be used with sense, because it is not applicable for each and every service (for example services with dynamic responses for a particular release) </p>
<h2>
<a name="Sample420" id="Sample420">Sample 420: Simple cache implemented on Synapse for the actual service</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;in&gt;
        &lt;cache timeout=&quot;20&quot; scope=&quot;per-host&quot; collector=&quot;false&quot;
               hashGenerator=&quot;org.wso2.caching.digest.DOMHASHGenerator&quot;&gt;
            &lt;implementation type=&quot;memory&quot; maxSize=&quot;100&quot;/&gt;
        &lt;/cache&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;/in&gt;
    &lt;out&gt;
        &lt;cache collector=&quot;true&quot;/&gt;
        &lt;send/&gt;
    &lt;/out&gt;
&lt;/definitions&gt;</pre>
<p>
<strong>Objective: Demonstrate the use of Cache mediator in order to cache the response and use that cached response as the response for an identical xml request</strong> </p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 420 (i.e. synapse -sample 420)</p>
<p>In this sample, the message sent to Synapse is checked for an existing cached response by calculating the hash value of the request. If there is a cache hit in Synapse then this request will not be forwarded to the actual service, rather Synapse responds to the client with the cached response. In case of a cache miss that particular message will be forwarded to the actual service and caches that response in the out path for the use of consecutive requests of the same type. </p>
<p>To observe this behaviour, invoke the client as follows. </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280/</pre>
<p>You could notice that if you send more than one requests within 20 seconds only the first request is forwarded to the actual service, and the rest of the requests will be served by the cache inside Synapse. You could observe this by looking at the printed line of the axis2 server, as well as by observing a constant rate as the response to the client instead of the random rate, which changes by each and every 20 seconds.
<br/> </p>
<h2>
<a name="Callout" id="Callout">Synchronous Web Services Invocations with the Callout Mediator</a></h2>
<p>The Callout mediator calls the given service URL with the request message which is given by the source attribute, waits for the response and attaches the received response to the destination which is given by the target attribute. Both the source and the target can be a key or an XPath. In the case of the source, this key refers to either a message context property or to a local entry. For the target, this key refers to a message context property only. </p>
<h2>
<a name="Sample430" id="Sample430">Sample 430: Simple Callout Mediator for synchronizing web service invocation</a></h2>
<pre xml:space="preserve">    &lt;!-- Simple callout  mediator --&gt;
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;callout serviceURL=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;
             action=&quot;urn:getQuote&quot;&gt;
        &lt;source xmlns:s11=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
                xmlns:s12=&quot;http://www.w3.org/2003/05/soap-envelope&quot;
                xpath=&quot;s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]&quot;/&gt;
        &lt;target xmlns:s11=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;
                xmlns:s12=&quot;http://www.w3.org/2003/05/soap-envelope&quot;
                xpath=&quot;s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]&quot;/&gt;
    &lt;/callout&gt;
    &lt;property name=&quot;RESPONSE&quot; value=&quot;true&quot;/&gt;
    &lt;header name=&quot;To&quot; action=&quot;remove&quot;/&gt;
    &lt;send/&gt;
    &lt;drop/&gt;
&lt;/definitions&gt; </pre>
<div>
<p>
<strong>Objective:</strong> Demonstrate the use of the callout mediator for the synchronized web service invocation </p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 430 (i.e. synapse -sample 430)</p>
<p>In this sample, the callout mediator does the direct service invocation to the StockQuoteService using the client request, gets the response and sets it as the first child of the SOAP message body. Then using the send mediator, the message is sent back to the client. </p>
<p>Invoke the client as follows. </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</pre></div>
<h2>
    <a name="Sample440" id="Sample440">Sample 440: Exposing a SOAP Service Over JSON</a>
</h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;proxy name="JSONProxy" transports="http https"&gt;
        &lt;target&gt;
            &lt;endpoint&gt;
                &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
            &lt;/endpoint&gt;
            &lt;inSequence&gt;
                &lt;log level="full"/&gt;
                &lt;xslt key="in_transform"/&gt;
                &lt;property name="messageType" scope="axis2" value="text/xml"/&gt;
            &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;log level="full"/&gt;
                &lt;xslt key="out_transform"/&gt;
                &lt;property name="messageType" scope="axis2" value="application/json"/&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
    &lt;/proxy&gt;

    &lt;localEntry key="in_transform"&gt;
        &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                        xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
                        xmlns:m0="http://services.samples" version="2.0" exclude-result-prefixes="m0 fn"&gt;
            &lt;xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/&gt;
            &lt;xsl:template match="*"&gt;
                &lt;xsl:element name="{local-name()}" namespace="http://services.samples"&gt;
                    &lt;xsl:copy-of select="attribute::*"/&gt;
                    &lt;xsl:apply-templates/&gt;
                &lt;/xsl:element&gt;
            &lt;/xsl:template&gt;
        &lt;/xsl:stylesheet&gt;
    &lt;/localEntry&gt;

    &lt;localEntry key="out_transform"&gt;
        &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
            &lt;xsl:output method="xml" version="1.0" encoding="UTF-8"/&gt;
            &lt;xsl:template match="*"&gt;
                &lt;xsl:element name="{local-name()}"&gt;
                    &lt;xsl:apply-templates/&gt;
                &lt;/xsl:element&gt;
            &lt;/xsl:template&gt;
        &lt;/xsl:stylesheet&gt;
    &lt;/localEntry&gt;

&lt;/definitions&gt;</pre>
<div>
<p>
<strong>Objective:</strong> Demonstrate the ability to switch between JSON and XML/SOAP content interchange formats</p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Setup Synapse and the sample Axis2 client for JSON (Refer <a href="Synapse_Samples_Setup.html#json">Synapse Samples Setup Guide</a>
for details)
<br/>Start Synapse with the sample configuration 440 (i.e. synapse -sample 440)</p>
<p>Invoke the JSON client as follows. </p>
<pre xml:space="preserve">ant jsonclient -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/services/JSONProxy</pre>
<p>JSON client will send a stockquote request to Synapse using the JSON content interchange format. Synapse
will trnasform it into a SOAP request and forward to the Axis2 server. The SOAP response from the Axis2 server
will be converted into a JSON message and sent back to the JSON client.</p>
<p>You may use a tool like TCPMon to monitor the JSON requests sent over the wire. A sample JSON request and response
 is shown below:</p>
<pre>{"getQuote":{"request":{"symbol":"IBM"}}}</pre>
<pre>{"getQuoteResponse":{"return":{"change":3.853593376681722,"earnings":12.802850763714854,"high":67.92488310190126,"last":66.14619264746406,"lastTradeTimestamp":"Mon Aug 23 16:48:40 IST 2010","low":-66.04000424423522,"marketCap":-9334516.42324327,"name":"IBM Company","open":-64.61950137150009,"peRatio":-19.78600441437058,"percentageChange":5.411779328273005,"prevClose":71.2075112994578,"symbol":"IBM","volume":16842}}}</pre>
</div>

<h2>
    <a name="Sample450" id="Sample450">Sample 450: Introduction to the URL Rewrite Mediator</a>
</h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;sequence xmlns="http://ws.apache.org/ns/synapse" name="main"&gt;
        &lt;in&gt;
            &lt;rewrite&gt;
               &lt;rewriterule&gt;
                  &lt;action type="replace" regex="soap" value="services" fragment="path"/&gt;
               &lt;/rewriterule&gt;
            &lt;/rewrite&gt;
            &lt;send/&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;</pre>
<div>
<p>
<strong>Objective:</strong> Demonstrate the basic functions of the URL rewrite mediator</p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 450 (i.e. synapse -sample 450)</p>
<p>Invoke the Axis2 client as follows. </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280 -Daddurl=http://localhost:9000/soap/SimpleStockQuoteService</pre>
<p>Note that the address URL of the client request contains the context 'soap'. But in the Axis2 server all the
services are deployed under a context named 'services' by default. Synapse will rewrite the To header of the request
by replacing the 'soap' context with 'services. Hence the request will be delivered to the Axis2 server and the
Axis2 client will receive a valid response.</p>
</div>
<h2>
    <a name="Sample451" id="Sample451">Sample 451: Conditional URL Rewriting</a>
</h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;sequence xmlns="http://ws.apache.org/ns/synapse" name="main"&gt;
        &lt;in&gt;
            &lt;rewrite&gt;
               &lt;rewriterule&gt;
                  &lt;condition&gt;
                     &lt;and&gt;
                        &lt;equal type="url" source="host" value="localhost"/&gt;
                        &lt;not&gt;
                           &lt;equal type="url" source="protocol" value="https"/&gt;
                        &lt;/not&gt;
                     &lt;/and&gt;
                  &lt;/condition&gt;
                  &lt;action fragment="protocol" value="https"/&gt;
                  &lt;action fragment="port" value="9002"/&gt;
               &lt;/rewriterule&gt;
            &lt;/rewrite&gt;
            &lt;log level="full"/&gt;
            &lt;send/&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;</pre>
<div>
<p>
<strong>Objective:</strong> Demonstrate the ability of the URL rewrite mediator to evaluate conditions on messages and
perform rewrites based on the results.</p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 451 (i.e. synapse -sample 451)</p>
<p>Invoke the Axis2 client and send some requests to Synapse with different address URL values. If the address
URL value contains localhost as the hostname and https as the protocol prefix, Synapse will route the message as
it is. But if the hostname is localhost and the protocol is not https, Synapse will rewrite the URL by setting
https as the protocol. The port number will also be set to the HTTPS port of the Axis2 server.</p>
<p>The condition evaluation feature is provided by the Synapse evaluator framework. Currently one can evaluate
expressions on URL values, query parameters, transport headers, properties and SOAP envelope content using this
framework. Hence URL rewriting can be done based on any of these aspects.</p>    
</div>

<h2>
    <a name="Sample452" id="Sample452">Sample 452: Conditional URL Rewriting with Multiple Rules</a>
</h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
    &lt;sequence name="main"&gt;
        &lt;in&gt;
            &lt;property name="http.port" value="9000"/&gt;
            &lt;property name="https.port" value="9002"/&gt;
            &lt;rewrite&gt;
                &lt;rewriterule&gt;
                    &lt;action fragment="host" value="localhost"/&gt;
                    &lt;action fragment="path" type="prepend" value="/services"/&gt;
                &lt;/rewriterule&gt;
                &lt;rewriterule&gt;
                    &lt;condition&gt;
                        &lt;equal type="url" source="protocol" value="http"/&gt;
                    &lt;/condition&gt;
                    &lt;action fragment="port" xpath="get-property('http.port')"/&gt;
                &lt;/rewriterule&gt;
                &lt;rewriterule&gt;
                    &lt;condition&gt;
                        &lt;equal type="url" source="protocol" value="https"/&gt;
                    &lt;/condition&gt;
                    &lt;action fragment="port" xpath="get-property('https.port')"/&gt;
                &lt;/rewriterule&gt;
            &lt;/rewrite&gt;
            &lt;log level="full"/&gt;
            &lt;send/&gt;
        &lt;/in&gt;
        &lt;out&gt;
            &lt;send/&gt;
        &lt;/out&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;</pre>
<div>
<p>
<strong>Objective:</strong> Demonstrate the ability of the URL rewrite mediator to perform rewrites based
on multiple rules.</p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 452 (i.e. synapse -sample 452)</p>
<p>Invoke the Axis2 client as follows. </p>
<pre xml:space="preserve">ant stockquote -Dtrpurl=http://localhost:8280 -Daddurl=http://test.com/SimpleStockQuoteService</pre>
<p>The provided address URL does not contain a port number and the context. The URL rewrite mediator will replace
the hostname to be 'localhost' and add the context '/services' to the path. Then it will add the appropriate
port number to the URL by looking at the protocol prefix. Ultimately the service request will be routed the sample Axis2
server and the client will receive a valid response.</p>
<p>Another important aspect shown by this sample is the ability of the URL rewirte mediator to obtain the necessary
values by executing XPath expressions. The port numbers are calculated by executing an XPath on the messages.</p>
</div>

<h2>
<a name="Sample460" id="Sample460">Sample 460: How to initialize and use a Spring Bean as a Mediator</a></h2>
<pre xml:space="preserve">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;registry provider="org.apache.synapse.registry.url.SimpleURLRegistry"&gt;
        &lt;parameter name="root">file:repository/conf/sample/resources/&lt;/parameter&gt;
        &lt;parameter name="cachableDuration">15000&lt;/parameter&gt;
    &lt;/registry&gt;

    &lt;sequence name="main"&gt;
        &lt;!--Setting the Spring Mediator and its Spring Beans xml file location --&gt;
        &lt;!--Note that springtest is the bean id used in springCustomLogger.xml --&gt;
        &lt;spring bean="springtest" key="spring/springCustomLogger.xml"/&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;

</pre>
<p>springCustomLogger.xml file</p>
<pre xml:space="preserve">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE beans PUBLIC  "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd"&gt;

&lt;beans&gt;

   &lt;bean id="springtest" class="samples.mediators.extentions.SpringCustomLogger" singleton="false"&gt;
	   &lt;property name="userName"&gt;&lt;value&gt;"Synapse User"&lt;/value&gt;&lt;/property&gt;
	   &lt;property name="email"&gt;&lt;value&gt;"usr@synapse.org"&lt;/value&gt;&lt;/property&gt;
   &lt;/bean&gt;

&lt;/beans&gt;

</pre>
<div>
<p>
<strong>Objective:</strong> Demonstrate How to initialize and use a SpringBean as a mediator  </p>
<p>
<strong>Prerequisites:</strong>
<br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
<br/>Start Synapse with the sample configuration 460 (i.e. synapse -sample 460)</p>
<p>In this sample, the Spring Bean, SpringCustomLogger get initialized using springCustomLogger.xml file and then it log the message Id.</p>
<p>Invoke the client as follows. </p>
<pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</pre>
<p>If you have enabled logging for the samples.mediators package you will see an output similar to the
following on the console:</p>
<pre xml:space="preserve">2010-09-26 20:46:57,946 [-] [HttpServerWorker-1]  INFO SpringCustomLogger Starting Spring Meditor
2010-09-26 20:46:57,946 [-] [HttpServerWorker-1]  INFO SpringCustomLogger Bean in Initialized with User:["Synapse User"]
2010-09-26 20:46:57,946 [-] [HttpServerWorker-1]  INFO SpringCustomLogger E-MAIL:["usr@synapse.org"]
2010-09-26 20:46:57,946 [-] [HttpServerWorker-1]  INFO SpringCustomLogger Massage Id:  urn:uuid:383FA8B27D7CC549D91285514217720
2010-09-26 20:46:57,946 [-] [HttpServerWorker-1]  INFO SpringCustomLogger Logged....</pre>
</div>
    
   <h2>
      <a name="Sample500" id="Sample500">Sample 500: Simple Eventing Sample</a>
    </h2>
<pre xml:space="preserve">&lt;!-- Simple Eventing configuration --&gt;
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
     &lt;eventSource name=&quot;SampleEventSource&quot;&gt;
           &lt;subscriptionManager class=&quot;org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager&quot;&gt;
               &lt;property name=&quot;topicHeaderName&quot; value=&quot;Topic&quot;/&gt;
               &lt;property name=&quot;topicHeaderNS&quot; value=&quot;http://apache.org/aip&quot;/&gt;
           &lt;/subscriptionManager&gt;
     &lt;/eventSource&gt;

    &lt;sequence name=&quot;PublicEventSource&quot; &gt;
           &lt;log level=&quot;full&quot;/&gt;
           &lt;eventPublisher eventSourceName=&quot;SampleEventSource&quot;/&gt;
    &lt;/sequence&gt;

    &lt;proxy name=&quot;EventingProxy&quot;&gt;
        &lt;target inSequence=&quot;PublicEventSource&quot; /&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
    <div>
      <p>
        <strong>Objective:</strong> Demonstrate the use of the Eventing functionality built with Synapse
      </p>
      <p>
        <strong>Prerequisites:</strong>
        <br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
        <br/>Start Synapse with the sample configuration 500 (i.e. synapse -sample 500)
      </p>
      <p>
        In this sample, the event source creted based on the configuration. Event subscriber subscribes for the events, Event sender publish events and the SimpleStockQuoteService act as the Event Sink.
      </p>
      <p>
        Invoke the client (Subscriber) as follows:
      </p>
<pre xml:space="preserve">ant eventsubscriber</pre>
      <p>
        This will create a new subscription with the SimpleStockQuoteService deployed on the sample
        Axis2 server acting as the sink: whenever a new event is published, SimpleStockQuoteService
        will receive a message with that event.
        You should see a message like this:
      </p>
<pre>[java] Subscription identifier: urn:uuid:6989F66706E73C69F5259116575749162017010321</pre>
      <p>
        You will need this identifier to modify the subscription in the next steps below.
        Now, invoke the client (Sender) as follows:
      </p>
<pre xml:space="preserve">ant eventsender</pre>
      <p>
        This will send a placeOrder message to the EventingProxy. You should see this message in the
        Synapse logs. Note the presence of the following SOAP header in the request:
      </p>
<pre>&lt;aip:Topic xmlns:aip="http://apache.org/aip">synapse/event/test&lt;/aip:Topic></pre>
      <p>
        Since there is a single subscription with SimpleStockQuoteService as the sink, Synapse will
        send the message to the sample Axis2 server and you should see the following message in
        its logs:
      </p>
<pre>Accepted order for : 1000 stocks of GOOG at $ 10.1</pre>
      <p>
        To get the current status of the subscription, invoke the client as follows:
      </p>
<pre xml:space="preserve">ant eventsubscriber -Dmode=getstatus -Didentifier=<i>&lt;identifier></i></pre>
      <p>
        To renew the subscription, invoke the client as follows:
      </p>
<pre xml:space="preserve">ant eventsubscriber -Dmode=renew -Didentifier=<i>&lt;identifier></i> -Dexpires=2009-12-31T21:07:00.000-08:00</pre>
      <p>
        Finally, in order to unsubscribe, use the following command:
      </p>
<pre xml:space="preserve">ant eventsubscriber -Dmode=unsubscribe -Didentifier=<i>&lt;identifier></i></pre>
    </div>
   <h2>
      <a name="Sample501" id="Sample501">Sample 501: EventSource with static subscriptions</a>
    </h2>
<pre xml:space="preserve">&lt;!-- Eventing configuration with static subscriptions--&gt;
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
     &lt;eventSource name=&quot;SampleEventSource&quot;&gt;
           &lt;subscriptionManager class=&quot;org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager&quot;&gt;
               &lt;property name=&quot;topicHeaderName&quot; value=&quot;Topic&quot;/&gt;
               &lt;property name=&quot;topicHeaderNS&quot; value=&quot;http://apache.org/aip&quot;/&gt;
           &lt;/subscriptionManager&gt;
           &lt;subscription id=&quot;mysub1&quot;&gt;
                &lt;filter source =&quot;synapse/event/test&quot; dialect=&quot;http://synapse.apache.org/eventing/dialect/topicFilter&quot;/&gt;
                &lt;endpoint&gt;&lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;&lt;/endpoint&gt;
           &lt;/subscription&gt;
           &lt;subscription id=&quot;mysub2&quot;&gt;
                &lt;filter source =&quot;synapse/event/test&quot; dialect=&quot;http://synapse.apache.org/eventing/dialect/topicFilter&quot;/&gt;
                &lt;endpoint&gt;&lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;&lt;/endpoint&gt;
                &lt;expires&gt;2020-06-27T21:07:00.000-08:00&lt;/expires&gt;
           &lt;/subscription&gt;
     &lt;/eventSource&gt;

    &lt;sequence name=&quot;PublicEventSource&quot; &gt;
           &lt;log level=&quot;full&quot;/&gt;
           &lt;eventPublisher eventSourceName=&quot;SampleEventSource&quot;/&gt;
    &lt;/sequence&gt;

    &lt;proxy name=&quot;EventingProxy&quot;&gt;
        &lt;target inSequence=&quot;PublicEventSource&quot; /&gt;
    &lt;/proxy&gt;
&lt;/definitions&gt;</pre>
    <div>
      <p>
        <strong>Objective:</strong> Demonstrate static subscription capability of Synapse
      </p>
      <p>
        <strong>Prerequisites:</strong>
        <br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
        <br/>Start Synapse with the sample configuration 501 (i.e. synapse -sample 501)
      </p>
      <p>
        In this sample, two static subscriptions created by providing the SimpleStockQuoteService as the event sink.
      </p>
        <p>
          Invoke the client (Sender) as follows.
        </p>
<pre xml:space="preserve">ant eventsender</pre>
      <p>
        Event sender will send the events to the static subscriptions
      </p>
    </div>
      <h2>
         <a name="Sample502" id="Sample502">Sample 502: Transform events before publish</a>
       </h2>
       <p>
         &#xa0;
       </p>
   <pre xml:space="preserve">&lt;!-- Eventing configuration with transformation before publish--&gt;
&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
     &lt;eventSource name=&quot;SampleEventSource&quot;&gt;
           &lt;subscriptionManager class=&quot;org.apache.synapse.eventing.managers.DefaultInMemorySubscriptionManager&quot;&gt;
               &lt;property name=&quot;topicHeaderName&quot; value=&quot;Topic&quot;/&gt;
               &lt;property name=&quot;topicHeaderNS&quot; value=&quot;http://apache.org/aip&quot;/&gt;
           &lt;/subscriptionManager&gt;
           &lt;subscription id=&quot;mysub1&quot;&gt;
                &lt;filter source =&quot;synapse/event/test&quot; dialect=&quot;http://synapse.apache.org/eventing/dialect/topicFilter&quot;/&gt;
                &lt;endpoint&gt;&lt;address uri=&quot;http://localhost:9000/services/SimpleStockQuoteService&quot;/&gt;&lt;/endpoint&gt;
           &lt;/subscription&gt;
     &lt;/eventSource&gt;


    &lt;sequence name=&quot;PublicEventSource&quot;&gt;
           &lt;log level=&quot;full&quot;/&gt;
           &lt;xslt key=&quot;xslt-key-req&quot;/&gt;
           &lt;log level=&quot;full&quot;/&gt;
           &lt;eventPublisher eventSourceName=&quot;SampleEventSource&quot;/&gt;
    &lt;/sequence&gt;

    &lt;proxy name=&quot;EventingProxy&quot;&gt;
        &lt;target inSequence=&quot;PublicEventSource&quot; /&gt;
    &lt;/proxy&gt;

    &lt;localEntry key=&quot;xslt-key-req&quot; src=&quot;file:repository/conf/sample/resources/transform/transform_eventing.xslt&quot;/&gt;
&lt;/definitions&gt;</pre>
       <div>
         <p>
           <strong>Objective:</strong> Demonstrate the mediation capability of events before publishsing to event sink.
         </p>
         <p>
           <strong>Prerequisites:</strong>
           <br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
           <br/>Start Synapse with the sample configuration 502 (i.e. synapse -sample 502)
         </p>
         <p>
           In this sample, the event (order request) transform to a new order with different namesapce using XSLT mediator.
         </p>
           <p>
             Invoke the client (Sender) as follows.
           </p>
   <pre xml:space="preserve">ant eventsender</pre>
         <p>
           Event publish after transformation.
         </p>
       </div>
    
       <h2>
         <a name="Sample600" id="Sample600">Sample 600: File hierarchy based configuration builder</a>
       </h2>
       <p>
         &#xa0;
       </p>
       <pre xml:space="preserve">
         synapse_sample_600.xml
            |-- endpoints
            |   `-- foo.xml
            |-- events
            |   `-- event1.xml
            |-- local-entries
            |   `-- bar.xml
            |-- proxy-services
            |   |-- proxy1.xml
            |   |-- proxy2.xml
            |   `-- proxy3.xml
            |-- registry.xml
            |-- sequences
            |   |-- custom-logger.xml
            |   |-- fault.xml
            |   `-- main.xml
            |-- synapse.xml
            `-- tasks
                `-- task1.xml

       </pre>
       <div>
         <p>
           <strong>Objective:</strong> Demonstrate the ability to construct the Synapse configuration from a file hierarchy
         </p>
         <p>
           <strong>Prerequisites:</strong>
           <br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000
           <br/>Start Synapse with the sample configuration 600 (i.e. synapse -sample 600)
         </p>
         <p>
            Go to the SYNAPSE_HOME/repository/conf/sample directory and locate the subdirectory named synapse_sample_600.xml
            within it. When Synapse is started with the sample configuration 600, Synapse will load the configuration from
            this directory. You will find a number of subdirectories and a set of XML files in each of those directories.
            Synapse will parse all the XML files in this file hierarchy and construct the full Synapse configuration at startup. 
            As a result when this sample is executed Synapse will start with four proxy services, several sequences, a task, an event
            source and some endpoint and local entry definitions.
         </p>
         <p>
            The names of the subdirectories (eg: proxy-services, sequences, endpoints) are fixed and hence cannot be changed.
            Also the registry definition should go into a file named registry.xml which resides at the top level of the file
            hierarchy. It can also be specified in the synapse.xml file at top level. This synapse.xml file can include
            any item that can be normally defined in a synapse.xml file. The files which define proxy services, sequences,
            endpoints etc can have any name. These configuration files must have the .xml extension at the end of the name. Synapse
            will ignore any files which do not have the .xml extension.
         </p>
         <p>
            None of the directories and files in the sample file hierachy are mandatory. You can leave entire directories out if
            you do not need them. For example if your configuration does not contain any proxy services you can leave the
            subdirectory named proxy-services out.
         </p>
         <p>
            To use this feature you should simply pass a path to an existing directory when starting the Synapse server. The
            SynapseServer class which is responsible for starting the server accepts a file path as an argument from where to
            load the configuration. Generally we pass the path to the synapse.xml file as the value of this argument. If you
            pass a directory path instead, Synapse configuration will be loaded from the specified directory. Note the following
            line on the console when Synapse is loading the configuration from a file hierarchy.
         </p>
         <pre>2009-08-04 14:14:42,489 [-] [main]  INFO SynapseConfigurationBuilder Loaded Synapse configuration from the directory hierarchy at : /home/synapse/repository/conf/sample/synapse_sample_600.xml</pre>
         <p>
            This feature comes in handy when managing large Synapse configurations. It is easier to maintain a well structured
            file hierarchy than managing one large flat XML file.
         </p>
       </div>
       <h2>
         <a name="Sample601" id="Sample601">Sample 601: Using Synapse observers</a>
       </h2>
       <div>
         <p>
           <strong>Objective:</strong> Demonstrate the ability to monitor the Synapse configuration at runtime using the
             SynapseObserver interface
         </p>
         <p>
           Open the synapse.properties file in the SYNAPSE_HOME/repository/conf directory using a text editor and uncomment the line which
           defines the simple logging Synapse observer.
         </p>
         <pre xml:space="preserve">synapse.observers=samples.userguide.SimpleLoggingObserver</pre>
         <p>
           Open the log4j.properties file in the SYNAPSE_HOME/lib directory and uncomment the line which sets the INFO log
           level to the samples.userguide package.
         </p>
         <pre xml:space="preserve">log4j.category.samples.userguide=INFO</pre>
         <p>
           Start Synapse using any of the sample configurations. The SimpleLoggingObserver will capture events that occur
           while constructing the Synapse configuration and log them on the console as follows.
         </p>
         <pre xml:space="preserve">
 2009-08-06 14:30:24,578 [-] [main]  INFO SimpleLoggingObserver Simple logging observer initialized...Capturing Synapse events...
 2009-08-06 14:30:24,604 [-] [main]  INFO SimpleLoggingObserver Endpoint : a3 was added to the Synapse configuration successfully
 2009-08-06 14:30:24,605 [-] [main]  INFO SimpleLoggingObserver Endpoint : a2 was added to the Synapse configuration successfully
 2009-08-06 14:30:24,606 [-] [main]  INFO SimpleLoggingObserver Endpoint : null was added to the Synapse configuration successfully
 2009-08-06 14:30:24,611 [-] [main]  INFO SimpleLoggingObserver Local entry : a1 was added to the Synapse configuration successfully
 2009-08-06 14:30:24,649 [-] [main]  INFO SimpleLoggingObserver Proxy service : StockQuoteProxy2 was added to the Synapse configuration successfully
 2009-08-06 14:30:24,661 [-] [main]  INFO SimpleLoggingObserver Proxy service : StockQuoteProxy1 was added to the Synapse configuration successfully
 2009-08-06 14:30:24,664 [-] [main]  INFO SimpleLoggingObserver Sequence : main was added to the Synapse configuration successfully
 2009-08-06 14:30:24,701 [-] [main]  INFO SimpleLoggingObserver Sequence : fault was added to the Synapse configuration successfully</pre>

         <p>
           The SimpleLoggingObserver is implemented as follows. It does not override any of the event handler implementations
           in the AbstractSynapseObserver class. The AbstractSynapseObserver logs all the received events by default.
         </p>
         <pre xml:space="preserve">
    package samples.userguide;

    import org.apache.synapse.config.AbstractSynapseObserver;

    public class SimpleLoggingObserver extends AbstractSynapseObserver {

        public SimpleLoggingObserver() {
            super();
            log.info("Simple logging observer initialized...Capturing Synapse events...");
        }
    }</pre>
         <p>
           Refer Synapse <a href="Synapse_Extending.html#synObservers">Synapse Extending Guide</a> for more details on developing Synapse observers.
         </p>
       </div>

   <h2>
         <a name="Sample650" id="Sample650">Sample 650: Priority Based Message Mediation</a>
   </h2>
   <pre xml:space="preserve">&lt;definitions xmlns=&quot;http://ws.apache.org/ns/synapse&quot;&gt;
    &lt;priorityExecutor name=&quot;exec&quot;&gt;
        &lt;queues&gt;
            &lt;queue size=&quot;100&quot; priority=&quot;1&quot;/&gt;
            &lt;queue size=&quot;100&quot; priority=&quot;10&quot;/&gt;
        &lt;/queues&gt;
    &lt;/priorityExecutor&gt;
    &lt;proxy name=&quot;StockQuoteProxy&quot;&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
                &lt;filter source=&quot;$trp:priority&quot; regex=&quot;1&quot;&gt;
                    &lt;then&gt;
                        &lt;enqueue priority=&quot;1&quot; sequence=&quot;priority_sequence&quot; executor=&quot;exec&quot;/&gt;
                    &lt;/then&gt;
                    &lt;else&gt;
                        &lt;enqueue priority=&quot;10&quot; sequence=&quot;priority_sequence&quot; executor=&quot;exec&quot;/&gt;
                    &lt;/else&gt;
                &lt;/filter&gt;
            &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
        &lt;publishWSDL uri=&quot;file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl&quot;/&gt;
    &lt;/proxy&gt;
    &lt;sequence name=&quot;priority_sequence&quot;&gt;
        &lt;log level=&quot;full&quot;/&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;/sequence&gt;
&lt;/definitions&gt;</pre>
       <div>
         <p>
           <strong>Objective:</strong> Demonstrate the priority based mediation capability of synapse.
         </p>
         <p>
           <strong>Prerequisites:</strong>
           <br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port
           9000. Priority is applied only when synapse is loaded with enough messages to consume its core number of threads.
             So to observe the priority based mediation, it is required to use a load testing tool like JMeter, SOAP UI or Apache bench.
           <br/>Start Synapse with the sample configuration 650 (i.e. synapse -sample 650)
         </p>
         <p>
           In this sample, client should send a HTTP header that specifies the priority of the message.This header name is priority.
             This header is retrieved in the synapse configuration using the $trp:priority XPath expression. Then it is matched against
             the value 1. If it has the value 1, message is executed with priority 1. Otherwise the message is executed with priority 10.
         </p>
           <p>
               Here are two sample XML files that can be used to invoke the service using a tool like JMeter, or Ab. For SOAP UI,
               user can use the WSDL repository/conf/sample/resources/proxy/sample_proxy_1.wsdl to create the request. The only
               difference between the two demonstrated requests here is the symbol. One has the symbol as IBM and other has MSFT. For one type of
               request set the priority header to 1 and for the next set the priority header to 10. Then load synapse with high
               volume of traffic from both types of requests using the load testing tool. In the back end server it prints the
               symbol of the incoming requests. User should be able to see more of high priority symbol.
           </p>
           <pre xml:space="preserve">
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
     &lt;soapenv:Header xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;&gt;
        &lt;wsa:To&gt;http://localhost:8281/services/SimpleStockQuoteService&lt;/wsa:To&gt;
        &lt;wsa:MessageID&gt;urn:uuid:1B57D0B0BF770678DE1261165228620&lt;/wsa:MessageID&gt;
        &lt;wsa:Action&gt;urn:getQuote&lt;/wsa:Action&gt;
     &lt;/soapenv:Header&gt;
     &lt;soapenv:Body&gt;
        &lt;m0:getQuote xmlns:m0=&quot;http://services.samples&quot;&gt;
           &lt;m0:request&gt;
              &lt;m0:symbol&gt;IBM&lt;/m0:symbol&gt;
           &lt;/m0:request&gt;
        &lt;/m0:getQuote&gt;
     &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;
           </pre>
           <pre xml:space="preserve">
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
     &lt;soapenv:Header xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;&gt;
        &lt;wsa:To&gt;http://localhost:8281/services/SimpleStockQuoteService&lt;/wsa:To&gt;
        &lt;wsa:MessageID&gt;urn:uuid:1B57D0B0BF770678DE1261165228620&lt;/wsa:MessageID&gt;
        &lt;wsa:Action&gt;urn:getQuote&lt;/wsa:Action&gt;
     &lt;/soapenv:Header&gt;
     &lt;soapenv:Body&gt;
        &lt;m0:getQuote xmlns:m0=&quot;http://services.samples&quot;&gt;
           &lt;m0:request&gt;
              &lt;m0:symbol&gt;MSFT&lt;/m0:symbol&gt;
           &lt;/m0:request&gt;
        &lt;/m0:getQuote&gt;
     &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;
           </pre>
       </div>

    <h2>
         <a name="Sample651" id="Sample651">Sample 651: NHTTP Transport Priority Based Dispatching</a>
    </h2>
    <p>
        Here is the priority configuration file used by the NHTTP transport to determine the priority based on HTTP level properties.
    </p>
   <pre xml:space="preserve">&lt;priorityConfiguration&gt;
    &lt;priorityExecutor&gt;
        &lt;!-- two priorities specified with priority 10 and 1. Both priority messages has a queue depth of 100 --&gt;
        &lt;queues isFixedCapacity=&quot;true&quot; nextQueue=&quot;org.apache.synapse.commons.executors.PRRNextQueueAlgorithm&quot;&gt;
            &lt;queue size=&quot;100&quot; priority=&quot;10&quot;/&gt;
            &lt;queue size=&quot;100&quot; priority=&quot;1&quot;/&gt;
        &lt;/queues&gt;
        &lt;!-- these are the default values, values are put here to show their availability --&gt;
        &lt;threads core=&quot;20&quot; max=&quot;100&quot; keep-alive=&quot;5&quot;/&gt;
    &lt;/priorityExecutor&gt;

    &lt;!-- if a message comes that we cannot determine priority, we set a default priority of 1 --&gt;
    &lt;conditions defaultPriority=&quot;1&quot;&gt;
        &lt;condition priority=&quot;10&quot;&gt;
            &lt;!-- check for the header named priority --&gt;
            &lt;equal type=&quot;header&quot; source=&quot;priority&quot; value=&quot;5&quot;/&gt;
        &lt;/condition&gt;
        &lt;condition priority=&quot;1&quot;&gt;
            &lt;equal type=&quot;header&quot; source=&quot;priority&quot; value=&quot;1&quot;/&gt;
        &lt;/condition&gt;
    &lt;/conditions&gt;
&lt;/priorityConfiguration&gt;</pre>
       <div>
         <p>
           <strong>Objective:</strong> Demonstrate the priority based dispatching of NHTTP transport.
         </p>
         <p>
           <strong>Prerequisites:</strong>
           <br/>Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port
           9000. Priority is applied only when synapse is loaded with enough messages to consume its core number of threads.
           So to observe the priority based dispatching, it is required to use a load testing tool like JMeter, SOAP UI or Apache bench.
           <br/>Open axis2.xml in repository/conf directory and uncomment the following parameter to the configuration.
             <strong>priorityConfigFile</strong>. Set the value to repository/conf/sample/resources/priority/priority-configuration.xml
           <br/>Start Synapse with the sample configuration 150 (i.e. synapse -sample 150).
         </p>
         <p>
           In this sample, client should send a HTTP header that specifies the priority of the message.This header name is priority.
             This header is retrieved in the prioirty configuration. Then it is matched against
             the value 1 and 10. Depending on this value message is executed with priority 1 or 10.
         </p>
           <p>
               Here are two sample XML files that can be used to invoke the service using a tool like JMeter, or Apache Ab. For SOAP UI,
               user can use the WSDL repository/conf/sample/resources/proxy/sample_proxy_1.wsdl to create the request. The only
               difference between the two demonstrated requests here is the symbol. One has the symbol as IBM and other has MSFT. For one type of
               request set the priority header to 1 and for the next set the priority header to 10. Then load synapse with high
               volume of traffic from both types of requests using the load testing tool. In the back end server it prints the
               symbol of the incoming requests. User should be able to see more of high priority symbol.
           </p>
           <pre xml:space="preserve">
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
     &lt;soapenv:Header xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;&gt;
        &lt;wsa:To&gt;http://localhost:8281/services/SimpleStockQuoteService&lt;/wsa:To&gt;
        &lt;wsa:MessageID&gt;urn:uuid:1B57D0B0BF770678DE1261165228620&lt;/wsa:MessageID&gt;
        &lt;wsa:Action&gt;urn:getQuote&lt;/wsa:Action&gt;
     &lt;/soapenv:Header&gt;
     &lt;soapenv:Body&gt;
        &lt;m0:getQuote xmlns:m0=&quot;http://services.samples&quot;&gt;
           &lt;m0:request&gt;
              &lt;m0:symbol&gt;IBM&lt;/m0:symbol&gt;
           &lt;/m0:request&gt;
        &lt;/m0:getQuote&gt;
     &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;
           </pre>
           <pre xml:space="preserve">
&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
     &lt;soapenv:Header xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;&gt;
        &lt;wsa:To&gt;http://localhost:8281/services/SimpleStockQuoteService&lt;/wsa:To&gt;
        &lt;wsa:MessageID&gt;urn:uuid:1B57D0B0BF770678DE1261165228620&lt;/wsa:MessageID&gt;
        &lt;wsa:Action&gt;urn:getQuote&lt;/wsa:Action&gt;
     &lt;/soapenv:Header&gt;
     &lt;soapenv:Body&gt;
        &lt;m0:getQuote xmlns:m0=&quot;http://services.samples&quot;&gt;
           &lt;m0:request&gt;
              &lt;m0:symbol&gt;MSFT&lt;/m0:symbol&gt;
           &lt;/m0:request&gt;
        &lt;/m0:getQuote&gt;
     &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;
           </pre>
       </div>
    <h2>
        <a name="Sample652" id="Sample652">Distributed transaction with Transaction
            mediator
        </a>
    </h2>
    <p>This sample describes how to use transaction mediator to participate in a distributed
        transaction
    </p>
    <h2>
        <a name="Sample652" id="Sample652">Sample 652: Distributed transaction management</a>
    </h2>
    <pre xml:space="preserve"> &lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

        &lt;sequence name="myFaultHandler"&gt;
            &lt;log level="custom"&gt;
                &lt;property name="text" value="** Rollback Transaction**"/&gt;
            &lt;/log&gt;
            &lt;transaction action="rollback"/&gt;
            &lt;send/&gt;
        &lt;/sequence&gt;

        &lt;sequence name="main" onError="myFaultHandler"&gt;
            &lt;in&gt;
                &lt;send&gt;
                    &lt;endpoint&gt;
                        &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
                    &lt;/endpoint&gt;
                &lt;/send&gt;
            &lt;/in&gt;

            &lt;out&gt;
                &lt;transaction action="new"/&gt;

                &lt;log level="custom"&gt;
                    &lt;property name="text" value="** Reporting to the Database esbdb**"/&gt;
                &lt;/log&gt;
                &lt;dbreport useTransaction="true" xmlns="http://ws.apache.org/ns/synapse"&gt;
                    &lt;connection&gt;
                        &lt;pool&gt;
                            &lt;dsName&gt;java:jdbc/XADerbyDS&lt;/dsName&gt;
                            &lt;icClass&gt;org.jnp.interfaces.NamingContextFactory&lt;/icClass&gt;
                            &lt;url&gt;localhost:1099&lt;/url&gt;
                            &lt;user&gt;synapse&lt;/user&gt;
                            &lt;password&gt;synapse&lt;/password&gt;
                        &lt;/pool&gt;
                    &lt;/connection&gt;
                    &lt;statement&gt;
                        &lt;sql&gt;delete from company where name =?&lt;/sql&gt;
                        &lt;parameter expression="//m0:return/m1:symbol/child::text()"
                                   xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd"
                                   type="VARCHAR"/&gt;
                    &lt;/statement&gt;
                &lt;/dbreport&gt;

                &lt;log level="custom"&gt;
                    &lt;property name="text" value="** Reporting to the Database esbdb1**"/&gt;
                &lt;/log&gt;
                &lt;dbreport useTransaction="true" xmlns="http://ws.apache.org/ns/synapse"&gt;
                    &lt;connection&gt;
                        &lt;pool&gt;
                            &lt;dsName&gt;java:jdbc/XADerbyDS1&lt;/dsName&gt;
                            &lt;icClass&gt;org.jnp.interfaces.NamingContextFactory&lt;/icClass&gt;
                            &lt;url&gt;localhost:1099&lt;/url&gt;
                            &lt;user&gt;synapse&lt;/user&gt;
                            &lt;password&gt;synapse&lt;/password&gt;
                        &lt;/pool&gt;
                    &lt;/connection&gt;
                    &lt;statement&gt;
                        &lt;sql&gt; INSERT into company values ('IBM','c4',12.0)&lt;/sql&gt;
                    &lt;/statement&gt;
                &lt;/dbreport&gt;
                &lt;transaction action="commit"/&gt;
                &lt;send/&gt;
            &lt;/out&gt;
        &lt;/sequence&gt;
        &lt;/definitions&gt; </pre>


    <div>
        <p>
            <strong>Objective:</strong>
            Demonstrate the use of the transaction mediator in a distributed transaction
        </p>
        <p>
            <strong>Prerequisites:</strong>
            Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000.
        </p>
        <p>Start Synapse with the sample configuration 652 (i.e. synapse -sample 652).</p>
        <p>To run this sample it is required to deploy synpase on JBoss application server(This is
            only tested with JBoss application sever), you can use the
            war distribution to deploy synapse on JBoss application server. Use the
            synpase_sample_652.xml as the synapse confiuration file and start JBoss with
            that synpase configuration file. Also you need to define two XA datasources for above
            two datasources. You'll need to refer JBoss documentation to see how
            to do this.
        </p>
        <p>It also required to have two database instances, this will be used by the two XA
            datasources. Refer the
            <a href="Synapse_Samples_Setup.html#derby">Sample Setup Guide</a>
            to see how you can set up the derby database server.
        </p>
        <p>In this sample a record is delete from one database and it is added into the second
            database. If either of the operations(deleting from the 1st database and adding into the
            second database) fails everything will be roll backed. The records will be untoched.
        </p>
        <p>Invoke the client as follows.</p>
        <pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN/
        </pre>

        <h2>
            <a name="StoreNFwd" id="StoreNFwd">Store and Forward Messaging patterns with Message
                Stores and Message Processors
            </a>
        </h2>
        <p>
            Synapse Message Stores and Message Processors can be used to implement different store
            and forward messaging patterns.
            This can be use to cater different SLA s and other QoS aspects.
        </p>
        <h2>
            <a name="Sample700" id="Sample700">Sample 700: Introduction to Synapse Message Store</a></h2>
        <pre xml:space="preserve">
            &lt;!-- Introduction to the Synapse Message Store --&gt;
            &lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
            &lt;sequence name="fault"&gt;
            &lt;log level="full"&gt;
            &lt;property name="MESSAGE" value="Executing default 'fault' sequence"/&gt;
            &lt;property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/&gt;
            &lt;property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/&gt;
            &lt;/log&gt;
            &lt;drop/&gt;
            &lt;/sequence&gt;
            &lt;sequence name="onStoreSequence"&gt;
            &lt;log&gt;
            &lt;property name="On-Store" value="Storing message"/&gt;
            &lt;/log&gt;
            &lt;/sequence&gt;
            &lt;sequence name="main"&gt;
            &lt;in&gt;
            &lt;log level="full"/&gt;
            &lt;property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/&gt;
            &lt;store messageStore="MyStore" sequence="onStoreSequence"/&gt;
            &lt;/in&gt;
            &lt;description&gt;The main sequence for the message mediation&lt;/description&gt;
            &lt;/sequence&gt;
            &lt;messageStore name="MyStore"/&gt;
            &lt;/definitions&gt;
        </pre>
    <p>
    <strong>Objective: </strong>Introduction to Synapse Message Stores</p>
    <strong>Prerequisites</strong>:
    <br/>Start the Synapse configuration numbered 700: i.e. synapse -sample 700
    <p>To Execute the Client : </p>
    <pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=placeorder
    </pre>
    <p>When you execute the client the message will be dispatched to the main sequence.
        In the Main sequence store mediator will store the placeOrder request message in the "MyStore" Message Store</p>

        <p>Before Storing the message store mediator will invoke the sequence :onStoreSequence. See the log</p>
        <p>INFO - LogMediator To: http://localhost:9000/services/SimpleStockQuoteService, WSAction: urn:placeOrder, SOAPAction: urn:placeOrder, ReplyTo: http://www.w3.org/2005/08/addressing/none, MessageID: urn:uuid:54f0e7c6-7b43-437c-837e-a825d819688c, Direction: request, On-Store = Storing message
        </p>


    <p>You can then use the JMX view of Synapse Message Store by using the jconsole and view the stored
        Messages and delete them.
    </p>
            <h2>
    <a name="Sample701" id="Sample701">Sample 701: Introduction to Synapse Message Sampling Processor</a></h2>
        <pre xml:space="preserve">
            &lt;!-- Introduction to Synapse Message Sampling Processor --&gt;

            &lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

            &lt;sequence name="send_seq"&gt;
            &lt;send&gt;
            &lt;endpoint&gt;
            &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"&gt;
            &lt;suspendOnFailure&gt;
            &lt;errorCodes&gt;-1&lt;/errorCodes&gt;
            &lt;progressionFactor&gt;1.0&lt;/progressionFactor&gt;
            &lt;/suspendOnFailure&gt;
            &lt;/address&gt;
            &lt;/endpoint&gt;
            &lt;/send&gt;
            &lt;/sequence&gt;
            &lt;sequence name="main"&gt;
            &lt;in&gt;
            &lt;log level="full"/&gt;
            &lt;property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/&gt;
            &lt;property name="OUT_ONLY" value="true"/&gt;
            &lt;store messageStore="MyStore"/&gt;
            &lt;/in&gt;
            &lt;description&gt;The main sequence for the message mediation&lt;/description&gt;
            &lt;/sequence&gt;
            &lt;messageStore name="MyStore"/&gt;
            &lt;messageProcessor
            class="org.apache.synapse.message.processors.sampler.SamplingProcessor"
            name="SamplingProcessor" messageStore="MyStore"&gt;
            &lt;parameter name="interval"&gt;20000&lt;/parameter&gt;
            &lt;parameter name="sequence"&gt;send_seq&lt;/parameter&gt;
            &lt;/messageProcessor&gt;
            &lt;/definitions&gt;
        </pre>
        <p>
            <strong>Objective:</strong>Introduction to Synapse Message Sampling Processor
        </p>
        <strong>Prerequisites</strong>:
        <br/>Start the Synapse configuration numbered 701: i.e. synapse -sample 701
        <p>Start the SimpleStockQuoteService if its not already started</p>
        <p>To Execute the Client few times:</p>
        <pre xml:space="preserve">ant stockquote
            -Daddurl=http://localhost:9000/services/SimpleStockQuoteService
            -Dtrpurl=http://localhost:8280/ -Dmode=placeorder
        </pre>
        <p>When you execute the client the message will be dispatched to the main sequence.
            In the Main sequence store mediator will store the placeOrder request message in the
            "MyStore" Message Store
        </p>

        <p>Message Processor will consume the messages and forward to the send_seq sequence in
            configured rate.
        </p>
        <p>You will observe that service invocation rate is not changing when increasing the rate we
            execute the client.
        </p>
    <h2>
    <a name="Sample702" id="Sample702">Sample 702: Introduction to Synapse Message Forwarding Processor</a></h2>
        <pre xml:space="preserve">

            &lt;!-- Introduction to Synapse Scheduled Message Forwarding Processor --&gt;

            &lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

            &lt;endpoint name="StockQuoteServiceEp"&gt;
            &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"&gt;
            &lt;suspendOnFailure&gt;
            &lt;errorCodes&gt;-1&lt;/errorCodes&gt;
            &lt;progressionFactor&gt;1.0&lt;/progressionFactor&gt;
            &lt;/suspendOnFailure&gt;
            &lt;/address&gt;
            &lt;/endpoint&gt;
            &lt;sequence name="fault"&gt;
            &lt;log level="full"&gt;
            &lt;property name="MESSAGE" value="Executing default 'fault' sequence"/&gt;
            &lt;property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/&gt;
            &lt;property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/&gt;
            &lt;/log&gt;
            &lt;drop/&gt;
            &lt;/sequence&gt;
            &lt;sequence name="main"&gt;
            &lt;in&gt;
            &lt;log level="full"/&gt;
            &lt;property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/&gt;
            &lt;property name="OUT_ONLY" value="true"/&gt;
            &lt;property name="target.endpoint" value="StockQuoteServiceEp"/&gt;
            &lt;store messageStore="MyStore"/&gt;
            &lt;/in&gt;
            &lt;description&gt;The main sequence for the message mediation&lt;/description&gt;
            &lt;/sequence&gt;
            &lt;messageStore name="MyStore"/&gt;
            &lt;messageProcessor
            class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor"
            name="ScheduledProcessor" messageStore="MyStore"&gt;
            &lt;parameter name="interval"&gt;10000&lt;/parameter&gt;
            &lt;/messageProcessor&gt;
            &lt;/definitions&gt;
        </pre>
    <p>
    <strong>Objective: </strong>Introduction to Synapse Message Forwarding Processor</p>
    <strong>Prerequisites</strong>:
    <br/>Start the Synapse configuration numbered 702: i.e. synapse -sample 702

    <p>To Execute the Client: </p>
    <pre xml:space="preserve">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=placeorder
</pre>

        <p>Now Start the SimpleStockQuoteService</p>
        <p>When you Start the service you will see message getting delivered to the service. Even
            though service is down when we invoke it from the client
        </p>
        <p>Here in the Main sequence store mediator will store the placeOrder request message in the
            "MyStore" Message Store
        </p>
        <p>Message Processor will send the message to the endpoint configured as a message context
            property.
        </p>
        <p>Message processor will remove the message from the store only if message delivered
            successfully
        </p>

    </div>
</body>
</document>
