blob: bf8d9c941284323337a799dff01a8e938a6da463 [file] [log] [blame]
<?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 2</title>
</properties>
<body>
<section name="Sample 2: CBR with Switch Case Mediator">
<div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
&lt;sequence name="main"&gt;
&lt;switch source="//m0:getQuote/m0:request/m0:symbol" xmlns:m0="http://services.samples"&gt;
&lt;case regex="IBM"&gt;
&lt;!-- the property mediator sets a local property on the *current* message --&gt;
&lt;property name="symbol" value="Great stock - IBM"/&gt;
&lt;/case&gt;
&lt;case regex="MSFT"&gt;
&lt;property name="symbol" value="Are you sure? - MSFT"/&gt;
&lt;/case&gt;
&lt;default&gt;
&lt;!-- it is possible to assign the result of an XPath expression as well --&gt;
&lt;property name="symbol" expression="fn:concat('Normal Stock - ', //m0:getQuote/m0:request/m0:symbol)"/&gt;
&lt;/default&gt;
&lt;/switch&gt;
&lt;log level="custom"&gt;
&lt;!-- the get-property() XPath extension function allows the lookup of local message properties
as well as properties from the Axis2 or Transport contexts (i.e. transport headers) --&gt;
&lt;property name="symbol" expression="get-property('symbol')"/&gt;
&lt;!-- the get-property() function supports the implicit message headers To/From/Action/FaultTo/ReplyTo --&gt;
&lt;property name="epr" expression="get-property('To')"/&gt;
&lt;/log&gt;
&lt;!-- Send the messages where they are destined to (i.e. the 'To' EPR of the message) --&gt;
&lt;send/&gt;
&lt;/sequence&gt;
&lt;/definitions&gt;</div>
<subsection name="Objective">
<p>
Introduction to the switch-case mediator and manipulating properties set on the
messages.
</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 2 (repository/conf/sample/synapse_sample_2.xml)
<div class="command">
Unix/Linux: sh synapse.sh -sample 2<br/>
Windows: synapse.bat -sample 2
</div>
</li>
</ul>
</p>
</subsection>
<subsection name="Executing the Client">
<p>
Execute the sample Axis2 client in the smart client using different symbols
such as IBM, MSFT and SUN.
</p>
<div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM</div>
<div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT</div>
<div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN</div>
<p>
When the symbol IBM is requested, viewing the mediation logs you will see that
the switch mediator's first case for 'IBM' is executed and a local property named
'symbol' is 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>
<div class="consoleOutput">INFO LogMediator - symbol = Great stock - IBM, epr = http://localhost:9000/axis2/services/SimpleStockQuoteService</div>
<p>
Similarly for the symbol 'MSFT' the second case statement in the switch mediator
will be executed which will result in the following log.
</p>
<div class="consoleOutput">INFO LogMediator - symbol = Are you sure? - MSFT, epr = http://localhost:9000/axis2/services/SimpleStockQuoteService</div>
</subsection>
</section>
<p><a href="../samples.html">Back to Catalog</a></p>
</body>
</document>