Sample 352: Accessing the Synapse MessageContext API Through Scripts

<definitions xmlns=""> <sequence name="main"> <in> <!-- change the MessageContext into a response and set a response payload --> <script language="js"> mc.setTo(mc.getReplyTo()); mc.setProperty("RESPONSE", "true"); mc.setPayloadXML( <ns:getQuoteResponse xmlns:ns="http://services.samples/xsd"> <ns:return> <ns:last>99.9</ns:last> </ns:return> </ns:getQuoteResponse>); </script> </in> <send/> </sequence> </definitions>


Demonstrate how to access various methods on the Synapse MessageContext API using the script mediator


  • Start Synapse using the configuration numbered 352 (repository/conf/sample/synapse_sample_352.xml)
    Unix/Linux: sh -sample 352
    Windows: synapse.bat -sample 352

Executing the Client

This example shows how an inline JavaScript can access the Synapse message context API to set its 'To' EPR and to set a custom property to mark it as a response. Execute the stock quote client, and you will receive the response '99.9' as the last sale price as per the above script.

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

Note that the symbol 'mc' is bound to the Synapse MessageContext object by the script mediator. Then the user can invoke various methods on the message context using common JavaScript syntax such as mc.getProperty('name') and mc.setTo('epr').

Back to Catalog