Author: indika Date: Wed Jul 1 01:09:15 2009 New Revision: 40484 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=40484
Log: script mediator doc update Modified: branches/esb/java/2.1/product/docs/xdoc/mediators/script.xml Modified: branches/esb/java/2.1/product/docs/xdoc/mediators/script.xml URL: http://wso2.org/svn/browse/wso2/branches/esb/java/2.1/product/docs/xdoc/mediators/script.xml?rev=40484&r1=40483&r2=40484&view=diff ============================================================================== --- branches/esb/java/2.1/product/docs/xdoc/mediators/script.xml (original) +++ branches/esb/java/2.1/product/docs/xdoc/mediators/script.xml Wed Jul 1 01:09:15 2009 @@ -1,101 +1,126 @@ -<?xml version="1.0" encoding="utf-8"?> +<?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 - Script 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 +<head> + <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> + <title>WSO2 ESB - Script 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. 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. With the script +mediator, you can invoke a function in the corresponding script. With in these +functions, it is possible to access the Synapse predefined in a script variable +named '<strong>mc</strong>’. This ‘<strong>mc</strong>’ represents an +implementation of the MessageContext, named +<strong>ScriptMessageContext.java</strong>. That contains following additional +methods that can be accessed within the script by +<strong>mc.methodNam</strong><strong>e</strong>. </p> +<ul> + <li><em>public Object getPayloadXML() - getting the XML representation of + SOAP Body payload</em></li> + <li><em>public void setPayloadXML(Object payload) - Set the SOAP body payload + from XML</em></li> + <li><em>public void addHeader(boolean mustUnderstand, Object content) - Add a + new SOAP header to the message.</em></li> + <li><em>public Object getEnvelopeXML() - Get the XML representation of the + complete SOAP envelope</em></li> + <li><em>public void setTo(String reference)</em></li> + <li><em>public void setFaultTo(String reference)</em></li> + <li><em>public void setFrom(String reference)</em></li> + <li><em>public void setReplyTo(String reference) </em></li> +</ul> + +<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> + +<p></p> + +<h3>Syntax </h3> +<ul> + <li>Script mediator using a script off the registry + <p></p> + <pre><script key="string" language="string" [function="script-function-name"]/> + </pre> + <p>The attribute <strong>key</strong> is the registry key to load the + script. The <strong>language</strong> attribute specifies the scripting + language of the script code (e.g. "js" for Javascript, "rb" for ruby, + "groovy" for Groovy, "py" for Python..). The <strong>function</strong> is + an optional attribute defining the name of the script function to invoke, + if not specified it defaults to a function named + '<strong>mediate</strong>'. The function is passed a single parameter - + which is the <strong>Synapse MessageContext</strong>. The function may + return a boolean, if it does not, then true is assumed, and the script + mediator returns this value. </p> + </li> + <li>Script mediator using a In-lined script + <p></p> + <pre><script language="string">...script source code...<script/></pre> + </li> +</ul> + +<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> + +<h3>Example </h3> +</body> +</html> _______________________________________________ Esb-java-dev mailing list [email protected] https://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev
