This documentation is work in progress and will be released with the next WSO2 EI version.
Sample 352: Accessing Synapse message context API using a scripting language - WSO2 Enterprise Integrator 6.x.x - WSO2 Documentation

All docs This doc
||
Skip to end of metadata
Go to start of metadata

Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:

  • <PRODUCT_HOME>/repository/samples/ directory that includes all Integration profile samples is changed to <EI_HOME>/samples/service-bus/.
  • <PRODUCT_HOME>/repository/samples/resources/ directory that includes all artifacts related to the Integration profile samples is changed to <EI_HOME>/samples/service-bus/resources/.

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