Author: supun Date: Fri Jun 26 23:13:00 2009 New Revision: 40111 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=40111
Log: Adding scripting mediator guide Added: trunk/esb/java/docs/xdoc/mediators/script.xml Added: trunk/esb/java/docs/xdoc/mediators/script.xml URL: http://wso2.org/svn/browse/wso2/trunk/esb/java/docs/xdoc/mediators/script.xml?pathrev=40111 ============================================================================== --- (empty file) +++ trunk/esb/java/docs/xdoc/mediators/script.xml Fri Jun 26 23:13:00 2009 @@ -0,0 +1,101 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> + <title>WSO2 ESB - RMSequence Mediator </title> + <link href="css/esb-docs.css" rel="stylesheet" /> + <link href="styles/dist-docs.css" rel="stylesheet" type="text/css" + media="all" /> + </head> + <body> + <h2> + <a id="script">Script Mediator</a> + </h2> + + <p> + Synapse supports Mediators implemented in a variety of scripting languages + such as JavaScript, Python or Ruby. There are two ways of defining script + mediators, either with the script program statements stored in a separate file + which is referenced via the local or remote registry entry, or with the script + program statements embedded in-line within the Synapse configuration. A script + mediator using a script off the registry (local or remote) is defined as + follows: + </p> + + <pre xml:space="preserve"> <script key="string" language="string" [function="script-function-name"]/></pre> + + <p> + The property key is the registry key to load the script. The language + attribute specifies the scripting language of the script code (e.g. "js" for + Javascript, "rb" for ruby, "groovy" for Groovy, "py" for Python..). The + function is an optional attribute defining the name of the script function to + invoke, if not specified it defaults to a function named 'mediate'. The + function is passed a single parameter - which is the Synapse MessageContext. + The function may return a boolean, if it does not, then true is assumed, and + the script mediator returns this value. An inline script mediator has the + script source embedded in the configuration as follows: + </p> + + <pre xml:space="preserve"> <script language="string">...script source code...<script/></pre> + + <p> + The execution context environment of the script has access to the Synapse + MessageContext predefined in a script variable named 'mc' . An example of an + inline mediator using JavaScript/E4X which returns false if the SOAP message + body contains an element named 'symbol' which has a value of 'IBM' would be: + </p> + + <pre xml:space="preserve"> <script language="js">mc.getPayloadXML()..symbol != "IBM";<script/></pre> + + <p> + Synapse uses the Apache <a href="http://jakarta.apache.org/bsf/"> + Bean + Scripting Framework + </a> for the scripting language support, any script language + supported by BSF may be used to implement a Synapse Mediator. + </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. For both types of script + mediator definition the MessageContext passed into the script has additional + methods over the standard Synapse MessageContext to enable working with the XML + in a way natural to the scripting language. For example when using JavaScript + getPayloadXML and setPayloadXML, E4X XML objects, and when using Ruby, REXML + documents. + </p> + <h3>UI Configuration</h3> + <h4>Script Type</h4> + <ul> + <li>Inline: Specify the script inline</li> + <li>Registry: Store the script in registry and refer it using the key</li> + </ul> + <h4>If Inline Selected</h4> + <p> + <img alt="Script Mediator with Inlinded Source" src="../script-mediator/docs/images/script.png"/> + </p> + <h4>Language</h4> + <p>Choose from variety of scripting languages supported</p> + <h4>Source</h4> + <p>If inline selected as the Script type, specify the source</p> + <h4>If Registry Selected</h4> + <p> + <img alt="Script Mediator with Registry Source" src="../script-mediator/docs/images/script_registry.png"/> + </p> + <h4>Function</h4> + <p>Function of the script language to execute</p> + <h4>Key</h4> + <p>Registry location of the source</p> + <h4>Include Keys</h4> + <p>Scripts sources to be included</p> + </body> +</html> \ No newline at end of file _______________________________________________ Esb-java-dev mailing list [email protected] https://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev
