You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by hi...@apache.org on 2010/12/26 05:04:59 UTC

svn commit: r1052828 - in /synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide: samples.xml samples/sample350.xml samples/sample351.xml samples/sample352.xml

Author: hiranya
Date: Sun Dec 26 04:04:59 2010
New Revision: 1052828

URL: http://svn.apache.org/viewvc?rev=1052828&view=rev
Log:
JS samples


Modified:
    synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples.xml
    synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample350.xml
    synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample351.xml
    synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample352.xml

Modified: synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples.xml?rev=1052828&r1=1052827&r2=1052828&view=diff
==============================================================================
--- synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples.xml (original)
+++ synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples.xml Sun Dec 26 04:04:59 2010
@@ -131,11 +131,11 @@
                 <h4>Script Mediator (Writing Mediation Logic in Scripting Languages)</h4>
                 <p>
                     <ul>
-                        <li><a href="#Sample350">Sample 350: Introduction to the script mediator using js scripts</a></li>
-                        <li><a href="#Sample351">Sample 351: In-line script mediation with JavaScript</a></li>
-                        <li><a href="#Sample352">Sample 352: Accessing Synapse message context API methods using scripting language</a></li>
-                        <li><a href="#Sample353">Sample 353: Using Ruby scripts for mediation</a></li>
-                        <li><a href="#Sample354">Sample 354: Using In-lined Ruby scripts for mediation</a></li>
+                        <li><a href="samples/sample350.html">Sample 350: Introduction to the script mediator using js scripts</a></li>
+                        <li><a href="samples/sample351.html">Sample 351: Inline scripts with the script mediator</a></li>
+                        <li><a href="samples/sample352.html">Sample 352: Accessing Synapse MessageContext API through scripts</a></li>
+                        <li><a href="samples/sample353.html">Sample 353: Using Ruby scripts for mediation</a></li>
+                        <li><a href="samples/sample354.html">Sample 354: Using In-lined Ruby scripts for mediation</a></li>
                     </ul>
                 </p>
                 <h4>Database Mediators (Interacting with Databases)</h4>

Modified: synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample350.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample350.xml?rev=1052828&r1=1052827&r2=1052828&view=diff
==============================================================================
--- synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample350.xml (original)
+++ synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample350.xml Sun Dec 26 04:04:59 2010
@@ -23,7 +23,7 @@
         <title>Apache Synapse - Sample 350</title>
     </properties>
     <body>
-        <section name="Sample 350: ">
+        <section name="Sample 350: Introduction to the Script Mediator using JavaScript">
             <div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
 
     &lt;registry provider="org.apache.synapse.registry.url.SimpleURLRegistry"&gt;
@@ -55,9 +55,34 @@
     &lt;/sequence&gt;
 
 &lt;/definitions&gt;</div>
+            <p>
+                The JavaScript resource file referenced by the configuration looks like this.
+            </p>
+            <div class="xmlConf">&lt;x&gt;&lt;![CDATA[
+  function transformRequest(mc) {
+     var symbol = mc.getPayloadXML()..*::Code.toString();
+     mc.setPayloadXML(
+        &lt;m:getQuote xmlns:m=&quot;http://services.samples&quot;&gt;
+           &lt;m:request&gt;
+              &lt;m:symbol&gt;{symbol}&lt;/m:symbol&gt;
+           &lt;/m:request&gt;
+        &lt;/m:getQuote&gt;);
+  }
+
+  function transformResponse(mc) {
+     var symbol = mc.getPayloadXML()..*::symbol.toString();
+     var price = mc.getPayloadXML()..*::last.toString();
+     mc.setPayloadXML(
+        &lt;m:CheckPriceResponse xmlns:m=&quot;http://www.apache-synapse.org/test&quot;&gt;
+           &lt;m:Code&gt;{symbol}&lt;/m:Code&gt;
+           &lt;m:Price&gt;{price}&lt;/m:Price&gt;
+        &lt;/m:CheckPriceResponse&gt;);
+  }
+]]&gt;&lt;/x&gt;</div>
             <subsection name="Objective">
                 <p>
-
+                    Showcase the ability to configure the Synapse runtime using common scripting
+                    languages such as JavaScript
                 </p>
             </subsection>
             <subsection name="Pre-requisites">
@@ -77,11 +102,21 @@
                 </p>
             </subsection>
             <subsection name="Executing the Client">
-                <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</div>
-
-                <div class="consoleOutput">Sat Nov 18 21:01:23 IST 2006 SimpleStockQuoteService :: Generating quote for : IBM</div>
-
-                <div class="consoleOutput">Standard :: Stock price = $95.26454380258552</div>
+                <p>
+                    This sample is similar to <a href="sample8.html">sample 8</a> but instead of using
+                    XSLT, the transformation is done using JavaScript and E4X. Note that the script
+                    source is loaded from a resource in the file system which must be wrapped in
+                    CDATA tags within an XML element. The script used in this example has two functions, 
+                    'transformRequest' and 'transformResponse'. The Synapse configuration uses the
+                    'function' attribute to specify which function should be invoked. Use the stock
+                    quote client to send a custom quote request as follows.
+                </p>
+                <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote</div>
+                <p>
+                    Synapse uses the script mediator and the specified JavaScript function to convert
+                    the custom request to a standard quote request. Subsequently the response received
+                    is transformed and sent back to the client.
+                </p>
             </subsection>
         </section>
         <p><a href="../samples.html">Back to Catalog</a></p>        

Modified: synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample351.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample351.xml?rev=1052828&r1=1052827&r2=1052828&view=diff
==============================================================================
--- synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample351.xml (original)
+++ synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample351.xml Sun Dec 26 04:04:59 2010
@@ -23,7 +23,7 @@
         <title>Apache Synapse - Sample 351</title>
     </properties>
     <body>
-        <section name="Sample 351: ">
+        <section name="Sample 351: Inline Scripts with the Script Mediator">
             <div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
 
     &lt;sequence name="main"&gt;
@@ -33,9 +33,9 @@
                 var symbol = mc.getPayloadXML()..*::Code.toString();
                 mc.setPayloadXML(
                 &lt;m:getQuote xmlns:m="http://services.samples"&gt;
-                &lt;m:request&gt;
-                &lt;m:symbol&gt;{symbol}&lt;/m:symbol&gt;
-                &lt;/m:request&gt;
+                    &lt;m:request&gt;
+                        &lt;m:symbol&gt;{symbol}&lt;/m:symbol&gt;
+                    &lt;/m:request&gt;
                 &lt;/m:getQuote&gt;);
             &lt;/script&gt;
             &lt;send&gt;
@@ -51,8 +51,8 @@
                 var price = mc.getPayloadXML()..*::last.toString();
                 mc.setPayloadXML(
                 &lt;m:CheckPriceResponse xmlns:m="http://services.samples/xsd"&gt;
-                &lt;m:Code&gt;{symbol}&lt;/m:Code&gt;
-                &lt;m:Price&gt;{price}&lt;/m:Price&gt;
+                    &lt;m:Code&gt;{symbol}&lt;/m:Code&gt;
+                    &lt;m:Price&gt;{price}&lt;/m:Price&gt;
                 &lt;/m:CheckPriceResponse&gt;);
             &lt;/script&gt;
             &lt;send/&gt;
@@ -62,7 +62,10 @@
 &lt;/definitions&gt;</div>
             <subsection name="Objective">
                 <p>
-
+                    <a href="sample350.html">Sample 350</a> shows how to use scripts stored as
+                    external resources for mediation. This sample demonstrates how small scriplets
+                    can be specified inline with the Synapse configuration thus avoiding the requirement
+                    to have an external registry.
                 </p>
             </subsection>
             <subsection name="Pre-requisites">
@@ -82,11 +85,13 @@
                 </p>
             </subsection>
             <subsection name="Executing the Client">
-                <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</div>
-
-                <div class="consoleOutput">Sat Nov 18 21:01:23 IST 2006 SimpleStockQuoteService :: Generating quote for : IBM</div>
-
-                <div class="consoleOutput">Standard :: Stock price = $95.26454380258552</div>
+                <p>
+                    The functionality and the behavior of this sample is identical to
+                    <a href="sample350.html">sample 350</a>. Only difference is that, the 2 JS functions
+                    are embedded in the Synapse configuration. To try this out run the following
+                    command on the sample client.
+                </p>
+                <div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dmode=customquote</div>
             </subsection>
         </section>
         <p><a href="../samples.html">Back to Catalog</a></p>        

Modified: synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample352.xml
URL: http://svn.apache.org/viewvc/synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample352.xml?rev=1052828&r1=1052827&r2=1052828&view=diff
==============================================================================
--- synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample352.xml (original)
+++ synapse/trunk/scratch/hiranya/website/src/site/xdoc/userguide/samples/sample352.xml Sun Dec 26 04:04:59 2010
@@ -23,7 +23,7 @@
         <title>Apache Synapse - Sample 352</title>
     </properties>
     <body>
-        <section name="Sample 352: ">
+        <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;
@@ -34,9 +34,9 @@
                 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: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;
@@ -46,16 +46,14 @@
 &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>
-                            Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
-                        </li>
-                        <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/>
@@ -66,11 +64,18 @@
                 </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>
-
-                <div class="consoleOutput">Sat Nov 18 21:01:23 IST 2006 SimpleStockQuoteService :: Generating quote for : IBM</div>
-
-                <div class="consoleOutput">Standard :: Stock price = $95.26454380258552</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>