blob: cc0efcf757f36035f1433748aa4dd0ec49a9df4b [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 156</title>
</properties>
<body>
<section name="Sample 156: Service Integration with Specifying the Receiving Sequence">
<div class="xmlConf">&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;enrich&gt;
&lt;source type=&quot;body&quot;/&gt;
&lt;target type=&quot;property&quot; property=&quot;REQUEST&quot;/&gt;
&lt;/enrich&gt;
&lt;send receive=&quot;SimpleServiceSeq&quot;&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;/inSequence&gt;
&lt;outSequence&gt;
&lt;drop/&gt;
&lt;/outSequence&gt;
&lt;/target&gt;
&lt;/proxy&gt;
&lt;sequence name=&quot;SimpleServiceSeq&quot;&gt;
&lt;property name=&quot;SECURE_SER_AMT&quot; expression=&quot;//ns:getQuoteResponse/ns:return/ax21:last&quot;
xmlns:ns=&quot;http://services.samples&quot; xmlns:ax21=&quot;http://services.samples/xsd&quot;/&gt;
&lt;log level=&quot;custom&quot;&gt;
&lt;property name=&quot;SecureStockQuoteService-Amount&quot; expression=&quot;get-property(&#39;SECURE_SER_AMT&#39;)&quot;/&gt;
&lt;/log&gt;
&lt;enrich&gt;
&lt;source type=&quot;body&quot;/&gt;
&lt;target type=&quot;property&quot; property=&quot;SecureService_Res&quot;/&gt;
&lt;/enrich&gt;
&lt;enrich&gt;
&lt;source type=&quot;property&quot; property=&quot;REQUEST&quot;/&gt;
&lt;target type=&quot;body&quot;/&gt;
&lt;/enrich&gt;
&lt;send receive=&quot;ClientOutSeq&quot;&gt;
&lt;endpoint name=&quot;SimpleStockQuoteService&quot;&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;ClientOutSeq&quot;&gt;
&lt;property name=&quot;SIMPLE_SER_AMT&quot; expression=&quot;//ns:getQuoteResponse/ns:return/ax21:last&quot;
xmlns:ns=&quot;http://services.samples&quot; xmlns:ax21=&quot;http://services.samples/xsd&quot;/&gt;
&lt;log level=&quot;custom&quot;&gt;
&lt;property name=&quot;SimpleStockQuoteService-Amount&quot; expression=&quot;get-property(&#39;SIMPLE_SER_AMT&#39;)&quot;/&gt;
&lt;/log&gt;
&lt;enrich&gt;
&lt;source type=&quot;body&quot;/&gt;
&lt;target type=&quot;property&quot; property=&quot;SimpleService_Res&quot;/&gt;
&lt;/enrich&gt;
&lt;filter xpath=&quot;fn:number(get-property(&#39;SIMPLE_SER_AMT&#39;)) &gt; fn:number(get-property(&#39;SECURE_SER_AMT&#39;))&quot;&gt;
&lt;then&gt;
&lt;log&gt;
&lt;property name=&quot;StockQuote&quot; value=&quot;SecureStockQuoteService&quot;/&gt;
&lt;/log&gt;
&lt;enrich&gt;
&lt;source type=&quot;property&quot; property=&quot;SecureService_Res&quot;/&gt;
&lt;target type=&quot;body&quot;/&gt;
&lt;/enrich&gt;
&lt;/then&gt;
&lt;else&gt;
&lt;log&gt;
&lt;property name=&quot;StockQuote&quot; value=&quot;SimpleStockQuoteService&quot;/&gt;
&lt;/log&gt;
&lt;/else&gt;
&lt;/filter&gt;
&lt;send/&gt;
&lt;/sequence&gt;
&lt;/definitions&gt;</div>
<subsection name="Objective">
<p>
Synapse is capable of mediating requests among multiple services and managing
complex message flows thereby acting as a lightweight orchestration engine. This
sample demonstrates how to easily integrate multiple services with Synapse using
the 'receiving sequence' feature of Synapse.
</p>
</subsection>
<subsection name="Pre-requisites">
<p>
<ul>
<li>
Deploy the SimpleStockQuoteService in the sample Axis2 server
</li>
<li>
Deploy the SecureStockQuoteService in the sample Axis2 server and start Axis2
</li>
<li>
Start Synapse using the configuration numbered 156 (repository/conf/sample/synapse_sample_156.xml)
<div class="command">
Unix/Linux: sh synapse.sh -sample 156<br/>
Windows: synapse.bat -sample 156
</div>
</li>
</ul>
</p>
</subsection>
<subsection name="Executing the Client">
<p>
This sample includes a proxy service which first forwards the client request to
the SecureStockQuoteService. Once a response has been received from this service,
Synapse will turn around and invoke the SimpleStockQuoteService. To do this proxy
service must hold on to the original request in memory. This is done using an
enrich mediator. Once Synapse has received a response from the SimpleStockQuoteService
it will compare the two responses received from the two services and select the
one with the lower stock quote value. This response will be then sent to the
client.
</p>
<p>
The important feature to note here is the 'receive' attribute set on the 'send'
mediators. This tells Synapse that responses of those send operations should be
directed to the sequences referred by the 'receive' attribute. Therefore the
response from the SecureStockQuoteService is directed to the sequence named
'SimpleServiceSeq'. Similarly the response from the SimpleStockQuoteService will
be handled by the sequence named 'ClientOutSeq'.
</p>
<p>
To try this out, execute the stock quote client as follows:
</p>
<div class="command">ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy</div>
<p>
You can confirm that Synapse invokes both services by going through the console
output of the Axis2 server. However Axis2 client will receive only one response
back. As far as the client is concerned, only one HTTP transaction is taking place.
But Synapse does multiple service invocations with the back-end to make the whole
integration scenario tick.
</p>
</subsection>
</section>
<p><a href="../samples.html">Back to Catalog</a></p>
</body>
</document>