Sample 3: Local Registry Entries, Reusable Endpoints and Sequences

<definitions xmlns=""> <!-- 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>


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.


  • Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
  • Start Synapse using the configuration numbered 3 (repository/conf/sample/synapse_sample_3.xml)
    Unix/Linux: sh -sample 3
    Windows: synapse.bat -sample 3

Executing the Client

Execute the sample client as follows.

ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/

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'.

DEBUG SequenceMediator - Sequence mediator <main> :: mediate() DEBUG InMediator - In mediator mediate() DEBUG SequenceMediator - Sequence mediator <stockquote> :: mediate()

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.

[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

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.

Back to Catalog