<?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 856</title>
    </properties>
    <body>
        <section name="Sample 856: Introduction to Synapse Dynamic Router eip function template">
            <div class="xmlConf">&lt;!-- Introduction to Synapse Dynamic Router eip function template --&gt;
&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
&lt;import xmlns="http://ws.apache.org/ns/synapse" name="EipLibrary" package="synapse.lang.eip" /&gt;
 &lt;proxy name="StockQuoteProxy" transports="https http" startOnLoad="true" trace="disable"&gt;
        &lt;target&gt;
            &lt;inSequence&gt;
               &lt;call-template target="synapse.lang.eip.dynamic_router"&gt;
&lt;with-param name="conditions" value="header=foo:bar.*{AND}url=/services/StockQuoteProxy.*;seq=cnd1_seq,header=custom_header1:bar.*{OR}header=custom_header1:foo.*;seq=cnd2_seq,header=custom_header2:foo.*;seq=cnd3_seq"/&gt;
    &lt;/call-template&gt;
     &lt;/inSequence&gt;
            &lt;outSequence&gt;
                &lt;send/&gt;
            &lt;/outSequence&gt;
        &lt;/target&gt;
    &lt;/proxy&gt;
&lt;sequence name="send_seq"&gt;
        &lt;log level="custom"&gt;
            &lt;property name="DEBUG" value="Condition Satisfied"/&gt;
        &lt;/log&gt;
        &lt;send&gt;
            &lt;endpoint name="simple"&gt;
                &lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
            &lt;/endpoint&gt;
        &lt;/send&gt;
    &lt;/sequence&gt;

    &lt;sequence name="cnd1_seq"&gt;
        &lt;log level="custom"&gt;
            &lt;property name="MSG_FLOW" value="Condition (I) Satisfied"/&gt;
        &lt;/log&gt;
        &lt;sequence key="send_seq"/&gt;
    &lt;/sequence&gt;
    &lt;sequence name="cnd2_seq"&gt;
        &lt;log level="custom"&gt;
            &lt;property name="MSG_FLOW" value="Condition (II) Satisfied"/&gt;
        &lt;/log&gt;
        &lt;sequence key="send_seq"/&gt;
    &lt;/sequence&gt;
    &lt;sequence name="cnd3_seq"&gt;
        &lt;log level="custom"&gt;
            &lt;property name="MSG_FLOW" value="Condition (III) Satisfied"/&gt;
        &lt;/log&gt;
        &lt;sequence key="send_seq"/&gt;
    &lt;/sequence&gt;
&lt;/definitions&gt;</div>
            <subsection name="Objective">
                <p>
This sample is an introduction to Synapse Dynamic Router eip function template.
                </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 856 (repository/conf/sample/synapse_sample_856.xml)
                            <div class="command">
                                Unix/Linux: sh synapse.sh -sample 856<br/>
                                Windows: synapse.bat -sample 856
                            </div>
                        </li>
                    </ul>
                </p>
            </subsection>
            <subsection name="Executing the Client">
<p>
In this sample, it checks whether the route condition based on HTTP url,HTTP headers evaluates to true and mediates using the given sequence. We will be using 'curl' as the client in this scenario. 
</p>
<p>Invoke curl commands as follows to see dynamic routing in action.</p>
                <div class="command">curl -d @stockQuoteReq.xml -H "Content-Type: application/soap+xml;charset=UTF-8" -H "foo:bar" "http://localhost:8280/services/StockQuoteProxy</div>
<p>You will see logs according to cnd1_seq in console.</p>
 <div class="command">curl -d @stockQuoteReq.xml -H "Content-Type: application/soap+xml;charset=UTF-8" -H "custom_header1:foo" "http://localhost:8280/services/StockQuoteProxy"</div>
<p>or</p>
<div class="command">curl -d @stockQuoteReq.xml -H "Content-Type: application/soap+xml;charset=UTF-8" -H "custom_header1:bar" "http://localhost:8280/services/StockQuoteProxy"</div>
<p>You will see logs according to cnd2_seq in console.</p>
<div class="command">curl -d @stockQuoteReq.xml -H "Content-Type: application/soap+xml;charset=UTF-8" -H "custom_header2:foo" "http://localhost:8280/services/StockQuoteProxy"</div>
<p>You will see logs according to cnd3_seq in console.</p>

            </subsection>
        </section>
        <p><a href="../samples.html">Back to Catalog</a></p>        
    </body>
</document>
