Author: antelder
Date: Sun Nov 26 04:46:48 2006
New Revision: 479353

URL: http://svn.apache.org/viewvc?view=rev&rev=479353
Log:
Add a script mediator section to the samples guide (just a start, still quite 
rough and needs more work

Modified:
    incubator/synapse/trunk/java/src/site/resources/Synapse_Samples.html

Modified: incubator/synapse/trunk/java/src/site/resources/Synapse_Samples.html
URL: 
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/src/site/resources/Synapse_Samples.html?view=diff&rev=479353&r1=479352&r2=479353
==============================================================================
--- incubator/synapse/trunk/java/src/site/resources/Synapse_Samples.html 
(original)
+++ incubator/synapse/trunk/java/src/site/resources/Synapse_Samples.html Sun 
Nov 26 04:46:48 2006
@@ -69,6 +69,12 @@
         <li><a href="#Sample112">Sample 112: Demonstrate one way messaging / 
fireAndForget</a></li>
       </ul>
     </li>
+    <li><a href="#ScriptMediators">Script Mediators</a>
+      <ul>
+        <li><a href="#Sample500">Sample 500: Introduction to script 
mediators</a></li>
+        <li><a href="#Sample501">Sample 501: In-line script mediators</a></li>
+      </ul>
+    </li>
   </ul>
 </div>
 
@@ -914,5 +920,85 @@
 <p>If you send your client request through TCPmon, you will notice that the
 SimpleStockQuoteService replies to Synapse with a HTTP 202 reply, and that
 Synapse in-turn replies to the client with a HTTP 202 acknowledgement.</p>
+
+<h1><a name="ScriptMediators">Script mediators</a></h1>
+
+<p>Synapse supports Mediators implemented in a variety of scripting languages 
such as JavaScript, Python or Ruby.</p>
+
+<p>Implementing a Mediator with a script language can have advantages over 
using the built in Synapse Mediator types or implementing a custom Java class 
Mediator. Script Mediators have all the flexibility of a class Mediator with 
access to the Synapse MessageContext and SynapseEnvironment APIs, and the ease 
of use and dynamic nature of scripting languages allows rapid development and 
prototyping of custom mediators. An additional benefit of some scripting 
languages is that they have very simple and elegant XML manipulation 
capabilities, for example JavaScript E4X or Ruby REXML, so this makes them well 
suited for use in the Synapse mediation environment.</p>
+
+<h2><a name="Sample500">Sample 500:</a></h2>
+
+<p><strong>Objective: Introduction to script mediators</strong></p>
+
+<p>This sample is similar to sample 8 but instead of using XSLT the 
transformation is done with JavaScript and E4X</p>
+
+<p><strong>Pre-Requisites:</strong></p>
+
+<p>
+This sample uses JavaScript/E4X which requires the Mozilla Rhino JavaScript 
interpreter and Apache XmlBeans xbean be installed into your Synapse 
distribution.
+If you've built Synapse from the src distribution these two jars will be in 
your local Maven repository, otherwise you can download them manualy by right 
clicking on the following links and choosing 'save link as...':
+<a href="http://repo1.maven.org/maven2/rhino/js/1.6R3/js-1.6R3.jar";>rhino</a> 
and <a 
href="http://repo1.maven.org/maven2/xmlbeans/xbean/2.2.0/xbean-2.2.0.jar";>xbean</a>.
 
+Once you've got the two jars copy them to the lib directory of your Synapse 
installation.
+</p>
+
+<p>
+Start the Synapse configuration numbered 500: i.e. synapse -sample 500<br>
+Start the Axis2 server and deploy the SimpleStockQuoteService (Refer steps
+above)
+</p>
+
+<p>The JavaScript script is in a separate file which the Synapse xml 
references by using a static property named 'stockquoteScript'. The script has 
two functions, 'transformRequest' and 'transformResponse', and the Synapse xml 
script element uses the function attribute to specify which function to use for 
the in and out rules.</p>
+
+<p>Execute the custom quote client as 'ant customquote' and check analyze the
+the Synapse debug log output as shown below</p>
+<pre>DEBUG XSLTMediator - Transformation source :&lt;m0:CheckPriceRequest 
xmlns:m0=http://www.apache-synapse.org/test&gt;
+&lt;m0:Code&gt;IBM&lt;/m0:Code&gt;&lt;/m0:CheckPriceRequest&gt;
+DEBUG XSLTMediator - Transformation result :
+&lt;m:getQuote xmlns:m=http://services.samples/xsd&gt;
+&lt;m:request&gt;&lt;m:symbol&gt;IBM&lt;/m:symbol&gt;&lt;/m:request&gt;&lt;/m:getQuote&gt;</pre>
+
+<p>The incoming message is now transformed into a standard stock quote
+request as expected by the SimpleStockQuoteService deployed on the local
+Axis2 instance by the JavaScript mediator. The JavaScript mediator uses E4X to
+perform the transformations. The response from the
+SimpleStockQuoteService is converted into the custom format as expected by
+the client during the out message processing.</p>
+
+<h2><a name="Sample501">Sample 501:</a></h2>
+
+<p><strong>Objective: Introduction to in-line script mediators</strong></p>
+
+<p>This sample is the same as sample 500 but instead of having the JavaScript 
source defined in a separate file it is defined in-line within the Synapse 
XML.</p>
+
+<p><strong>Pre-Requisites:</strong></p>
+
+<p>
+This sample uses JavaScript/E4X which requires the Mozilla Rhino JavaScript 
interpreter and Apache XmlBeans xbean be installed into your Synapse 
distribution.
+If you've built Synapse from the src distribution these two jars will be in 
your local Maven repository, otherwise you can download them manualy by right 
clicking on the following links and choosing 'save link as...':
+<a href="http://repo1.maven.org/maven2/rhino/js/1.6R3/js-1.6R3.jar";>rhino</a> 
and <a 
href="http://repo1.maven.org/maven2/xmlbeans/xbean/2.2.0/xbean-2.2.0.jar";>xbean</a>.
 
+Once you've got the two jars copy them to the lib directory of your Synapse 
installation.
+</p>
+<p>
+Start the Synapse configuration numbered 501: i.e. synapse -sample 501<br>
+Start the Axis2 server and deploy the SimpleStockQuoteService (Refer steps
+above)
+</p>
+
+<p>Execute the custom quote client as 'ant customquote' and check analyze the
+the Synapse debug log output as shown below</p>
+<pre>DEBUG XSLTMediator - Transformation source :&lt;m0:CheckPriceRequest 
xmlns:m0=http://www.apache-synapse.org/test&gt;
+&lt;m0:Code&gt;IBM&lt;/m0:Code&gt;&lt;/m0:CheckPriceRequest&gt;
+DEBUG XSLTMediator - Transformation result :
+&lt;m:getQuote xmlns:m=http://services.samples/xsd&gt;
+&lt;m:request&gt;&lt;m:symbol&gt;IBM&lt;/m:symbol&gt;&lt;/m:request&gt;&lt;/m:getQuote&gt;</pre>
+
+<p>The incoming message is now transformed into a standard stock quote
+request as expected by the SimpleStockQuoteService deployed on the local
+Axis2 instance by the JavaScript mediator. The JavaScript mediator uses E4X to
+perform the transformations. The response from the
+SimpleStockQuoteService is converted into the custom format as expected by
+the client during the out message processing.</p>
+
 </body>
 </html>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to