blob: f02fb7e227c1096d973f2a47b16308d2b769f38e [file] [log] [blame]
<?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 352</title>
</properties>
<body>
<section name="Sample 352: Accessing the Synapse MessageContext API Through Scripts">
<div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
&lt;sequence name="main"&gt;
&lt;in&gt;
&lt;!-- change the MessageContext into a response and set a response payload --&gt;
&lt;script language="js"&gt;
mc.setTo(mc.getReplyTo());
mc.setProperty("RESPONSE", "true");
mc.setPayloadXML(
&lt;ns:getQuoteResponse xmlns:ns="http://services.samples/xsd"&gt;
&lt;ns:return&gt;
&lt;ns:last&gt;99.9&lt;/ns:last&gt;
&lt;/ns:return&gt;
&lt;/ns:getQuoteResponse&gt;);
&lt;/script&gt;
&lt;/in&gt;
&lt;send/&gt;
&lt;/sequence&gt;
&lt;/definitions&gt;</div>
<subsection name="Objective">
<p>
Demonstrate how to access various methods on the Synapse MessageContext API
using the script mediator
</p>
</subsection>
<subsection name="Pre-requisites">
<p>
<ul>
<li>
Start Synapse using the configuration numbered 352 (repository/conf/sample/synapse_sample_352.xml)
<div class="command">
Unix/Linux: sh synapse.sh -sample 352<br/>
Windows: synapse.bat -sample 352
</div>
</li>
</ul>
</p>
</subsection>
<subsection name="Executing the Client">
<p>
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.
</p>
<div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</div>
<p>
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').
</p>
</subsection>
</section>
<p><a href="../samples.html">Back to Catalog</a></p>
</body>
</document>