This documentation is for WSO2 Enterprise Service Bus version 4.8.1 . View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

Objective: Accessing the Synapse APIs from scripting languages

Prerequisites:

  • Start the Synapse configuration numbered 352: i.e. wso2esb-samples.sh -sn 352
  • Start the Axis2 server and deploy the SimpleStockQuoteService if not already done.
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <in>
       <!-- change the MessageContext into a response and set a response payload -->
       <script language="js"><![CDATA[
          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/>
</definitions>
This example shows how an inline JavaScript mediator script could 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/

 

 

  • No labels