blob: 4b7d803a5e86d59f5038affa406041013079f2c4 [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 3</title>
</properties>
<body>
<section name="Sample 3: Local Registry Entries, Reusable Endpoints and Sequences">
<div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
&lt;!-- define a string resource entry to the local registry --&gt;
&lt;localEntry key="version"&gt;0.1&lt;/localEntry&gt;
&lt;!-- define a reuseable endpoint definition --&gt;
&lt;endpoint name="simple"&gt;
&lt;address uri="http://localhost:9000/services/SimpleStockQuoteService"/&gt;
&lt;/endpoint&gt;
&lt;!-- define a reusable sequence --&gt;
&lt;sequence name="stockquote"&gt;
&lt;!-- log the message using the custom log level. illustrates custom properties for log --&gt;
&lt;log level="custom"&gt;
&lt;property name="Text" value="Sending quote request"/&gt;
&lt;property name="version" expression="get-property('version')"/&gt;
&lt;property name="direction" expression="get-property('direction')"/&gt;
&lt;/log&gt;
&lt;!-- send message to real endpoint referenced by key "simple" endpoint definition --&gt;
&lt;send&gt;
&lt;endpoint key="simple"/&gt;
&lt;/send&gt;
&lt;/sequence&gt;
&lt;sequence name="main"&gt;
&lt;in&gt;
&lt;property name="direction" value="incoming"/&gt;
&lt;sequence key="stockquote"/&gt;
&lt;/in&gt;
&lt;out&gt;
&lt;send/&gt;
&lt;/out&gt;
&lt;/sequence&gt;
&lt;/definitions&gt;</div>
<subsection name="Objective">
<p>
Demonstrates how to define local registry entries, sequences and endpoints in a
reusable manner so that they can be used for mediation by referencing them by
names.
</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 3 (repository/conf/sample/synapse_sample_3.xml)
<div class="command">
Unix/Linux: sh synapse.sh -sample 3<br/>
Windows: synapse.bat -sample 3
</div>
</li>
</ul>
</p>
</subsection>
<subsection name="Executing the Client">
<p>
Execute the sample client as follows.
</p>
<div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</div>
<p>
This example uses a sequence named 'main' that specifies the main mediation
rules to be executed. Following through the mediation logs you will notice
that the sequence named 'main' is executed on receiving the requests (The main
sequence acts as the default entry point for messages received by Synapse). Then
for the incoming message flow the 'in' mediator executes, and it calls the sequence
named 'stockquote'.
</p>
<div class="consoleOutput">DEBUG SequenceMediator - Sequence mediator &lt;main&gt; :: mediate()
DEBUG InMediator - In mediator mediate()
DEBUG SequenceMediator - Sequence mediator &lt;stockquote&gt; :: mediate()</div>
<p>
As the 'stockquote' sequence executes, the log mediator dumps a simple text/string
property, result of an XPath evaluation, that picks up the key named 'version',
and a second result of an XPath evaluation that picks up a local message property
set previously by the property 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 'version' defines a simple text/string
registry entry which is visible to all messages that pass through Synapse.
</p>
<div class="consoleOutput">[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 </div>
<p>
Responses from the Axis2 server will also get dispatched to the main sequence.
But because they are responses the in mediator will not be executed on them.
Only the out mediator will execute on these messages which simply sends them
back to the client using a send mediator.
</p>
</subsection>
</section>
<p><a href="../samples.html">Back to Catalog</a></p>
</body>
</document>