<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
  ~  Licensed to the Apache Software Foundation (ASF) under one
  ~  or more contributor license agreements.  See the NOTICE file
  ~  distributed with this work for additional information
  ~  regarding copyright ownership.  The ASF licenses this file
  ~  to you under the Apache License, Version 2.0 (the
  ~  "License"); you may not use this file except in compliance
  ~  with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing,
  ~  software distributed under the License is distributed on an
  ~   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~  KIND, either express or implied.  See the License for the
  ~  specific language governing permissions and limitations
  ~  under the License.
  -->

<document>
    <properties>
        <title>Apache Synapse - Sample 1</title>
    </properties>
    <body>
        <section name="Sample 1: Simple Content Based Routing (CBR) of Messages">
            <div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;

    &lt;sequence name="main"&gt;
        &lt;!-- filtering of messages with XPath and regex matches --&gt;
        &lt;filter source="get-property('To')" regex=".*/StockQuote.*"&gt;
            &lt;then&gt;
                &lt;send&gt;
                    &lt;endpoint&gt;
                        &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
                    &lt;/endpoint&gt;
                &lt;/send&gt;
                &lt;drop/&gt;
            &lt;/then&gt;
        &lt;/filter&gt;
        &lt;send/&gt;
    &lt;/sequence&gt;

&lt;/definitions&gt;</div>
            <subsection name="Objective">
                <p>
                    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.
                </p>
            </subsection>
            <subsection name="Pre-requisites">
                <p>
                    <ul>
                        <li>
                            Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
                        </li>
                        <li>
                            Start Synapse using the configuration numbered 1 (repository/conf/sample/synapse_sample_1.xml)
                            <div class="command">
                                Unix/Linux: sh synapse.sh -sample 1<br/>
                                Windows: synapse.bat -sample 1
                            </div>
                        </li>
                    </ul>
                </p>
            </subsection>
            <subsection name="Executing the Client">
                <p>Execute the sample client in the dumb client mode using the following command.</p>
                <div class="command">ant stockquote -Dtrpurl=http://localhost:8280/services/StockQuote</div>

                <p>
                    This time you will see Synapse receiving a message for which Synapse was set
                    as the ultimate receiver. The filter mediator in the main sequence performs
                    a regular expression match on the 'To' header (http://localhost:8280/services/StockQuote)
                    to check whether it matches the expression ".*/StockQuote.*". Since the 'To' header
                    matches this expression the child mediators of the filter mediator get executed.
                    As a result, the message is sent to the Axis2 server. The drop mediator after
                    the send mediator terminates the flow of the sequence. Axis2 server will print
                    the following log when it receives the stock quote request from Synapse.
                </p>
                <div class="consoleOutput">Sat Nov 18 21:01:23 IST 2006 SimpleStockQuoteService :: Generating quote for : IBM</div>
                <p>
                    During response processing, the filter condition fails, and thus the child mediators
                    of the filter are skipped. The 'send' mediator at the end of the sequence
                    forwards the response back to the client using the implicit 'To' address.
                    The client will print a message similar to the following when it receives the
                    response.
                </p>
                <div class="consoleOutput">Standard :: Stock price = $95.26454380258552</div>
            </subsection>
        </section>
        <p><a href="../samples.html">Back to Catalog</a></p>        
    </body>
</document>