| <?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"><definitions xmlns="http://ws.apache.org/ns/synapse"> |
| <!-- define a string resource entry to the local registry --> |
| <localEntry key="version">0.1</localEntry> |
| <!-- define a reuseable endpoint definition --> |
| <endpoint name="simple"> |
| <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> |
| </endpoint> |
| |
| <!-- define a reusable sequence --> |
| <sequence name="stockquote"> |
| <!-- log the message using the custom log level. illustrates custom properties for log --> |
| <log level="custom"> |
| <property name="Text" value="Sending quote request"/> |
| <property name="version" expression="get-property('version')"/> |
| <property name="direction" expression="get-property('direction')"/> |
| </log> |
| <!-- send message to real endpoint referenced by key "simple" endpoint definition --> |
| <send> |
| <endpoint key="simple"/> |
| </send> |
| </sequence> |
| |
| <sequence name="main"> |
| <in> |
| <property name="direction" value="incoming"/> |
| <sequence key="stockquote"/> |
| </in> |
| <out> |
| <send/> |
| </out> |
| </sequence> |
| </definitions></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 <main> :: mediate() |
| DEBUG InMediator - In mediator mediate() |
| DEBUG SequenceMediator - Sequence mediator <stockquote> :: 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> |