Author: indika Date: Fri Jul 31 11:50:15 2009 New Revision: 42340 URL: http://wso2.org/svn/browse/wso2?view=rev&revision=42340
Log: updates the documents for rule samples in the ESB Modified: trunk/esb/java/docs/xdoc/configuration_language.xml trunk/esb/java/docs/xdoc/mediators/rule.xml trunk/esb/java/docs/xdoc/samples/rule_samples.xml Modified: trunk/esb/java/docs/xdoc/configuration_language.xml URL: http://wso2.org/svn/browse/wso2/trunk/esb/java/docs/xdoc/configuration_language.xml?rev=42340&r1=42339&r2=42340&view=diff ============================================================================== --- trunk/esb/java/docs/xdoc/configuration_language.xml (original) +++ trunk/esb/java/docs/xdoc/configuration_language.xml Fri Jul 31 11:50:15 2009 @@ -958,7 +958,6 @@ <h2><a id="mediator">Mediators</a> </h2> <p>A mediator token refers to any of the following tokens: </p> - <pre xml:space="preserve"><a href="#send">send</a> | <a href="#drop">drop</a> | <a href="#log">log</a> | <a href="#property">property</a> | <a href="#sequence_ref">sequence</a> | <a href="#validate">validate</a> | <a href="#fault">fault</a> | <a href="#callout">callout</a> | <a href="#xslt">xslt</a> | <a href="#header">header</a> | <a href="#filter">filter</a> | <a href="#switch">switch</a> | <a href="#in">in</a> | <a href="#out">out</a> | <a href="#router">router</a> | <a href="#dblookup">dblookup</a> | <a href="#dbreport">dbreport</a> | <a href="#RMSequence">RMSequence</a> | <a href="#throttle">throttle</a> | <a href="#xquery">xquery</a> | <a href="#cache">cache</a> | <a href="#clone">clone</a> | <a href="#iterate">iterate</a> | <a href="#aggregate">aggregate</a> | <a href="#class">class</a> | <a href="#pojoCommand">pojoCommand</a> | <a href="#script">script</a> | <a href="#spring">spring</a> | <a href="#event">event</a> | <a href="#transaction">transaction</a></pre> @@ -995,18 +994,15 @@ message must be sent and then further processed (e.g. transformed). In such a scenario, it maybe required to first clone the message into two copies and then perform processing to avoid conflicts. </p> - <pre xml:space="preserve"> <send/></pre> <p>If the message is to be sent to one or more endpoints, then the following is used: </p> - <pre xml:space="preserve"> <send> (endpointref | endpoint)+ </send></pre> <p>where the endpointref token refers to the following: </p> - <pre xml:space="preserve"> <endpoint key="name"/></pre> <p>and the endpoint token refers to an anonymous endpoint definition. </p> @@ -1015,7 +1011,6 @@ <p>The drop token refers to a <drop> element which is used to stop further processing of a message: </p> - <pre xml:space="preserve"> <drop/></pre> <p>Once the <drop> mediator executes, further processing of the current @@ -1025,7 +1020,6 @@ <p>The log token refers to a <log> element which may be used to log messages being mediated: </p> - <pre xml:space="preserve"> <log [level="string"] [separator="string"]> <property name="string" (value="literal" | expression="xpath")/>* </log></pre> @@ -1034,7 +1028,6 @@ be logged. </p> <p>e.g. </p> - <ul> <li>simple = To, From, WSAction, SOAPAction, ReplyTo, MessageID and any properties </li> @@ -1048,7 +1041,6 @@ The default separator is the ',' comma. </p> <h4><a id="property">Property</a> </h4> - <pre xml:space="preserve"> <property name="string" [action=set|remove] (value="literal" | expression="xpath") [scope=transport|axis2|axis2-client]/></pre> <p>The property token refers to a <property> element which is a mediator @@ -1063,7 +1055,6 @@ <p>There are some well-defined properties that you can get/set on the Synapse message context scope: </p> - <ul> <li>RESPONSE - 'true' means the message is to be marked as a response message </li> @@ -1082,7 +1073,6 @@ <p>There are some Axis2 and module properties that are useful which are set at scope="axis2" </p> - <ul> <li>MercurySequenceKey - can be an identifier specifying an Mercury internal sequence key, and </li> @@ -1092,7 +1082,6 @@ <p>There are some Axis2 client side properties/options that are useful which are set at scope="axis2-client" </p> - <ul> <li>FORCE_HTTP_1.0 - forces outgoing http/s messages to use HTTP 1.0 (instead of the default 1.1) </li> @@ -1111,7 +1100,6 @@ <property_name> [,<dateformat>] ) </p> <p>Some useful properties from the Synapse message context follows: </p> - <ul> <li>SYSTEM_DATE - Returns the current date as a String. Optionally a date format as per standard date format may be supplied. e.g. @@ -1158,14 +1146,12 @@ current message </li></ul> <h4><a id="sequence_ref">Sequence</a> </h4> - <pre xml:space="preserve"> <sequence key="name"/></pre> <p>A sequence ref token refers to a <sequence> element which is used to invoke a named sequence of mediators. </p> <h4><a id="validate">Validate</a> </h4> - <pre xml:space="preserve"> <validate [source="xpath"]> <property name="validation-feature-id" value="true|false"/>* <schema key="string"/>+ @@ -1186,7 +1172,6 @@ <h3>Transformation Mediators </h3> <h4><a id="fault">Fault</a> </h4> - <pre xml:space="preserve"> <makefault [version="soap11|soap12|pox"]> <code (value="literal" | expression="xpath")/> <reason (value="literal" | expression="xpath")> @@ -1225,7 +1210,6 @@ specified separately </p> <h4><a id="xslt">XSLT</a> </h4> - <pre xml:space="preserve"> <xslt key="string" [source="xpath"]> <property name="string" (value="literal" | expression="xpath")/>* <feature name="string" value="true| false" />* @@ -1284,7 +1268,6 @@ </ul> <h4><a id="header">Header</a> </h4> - <pre xml:space="preserve"> <header name="qname" (value="literal" | expression="xpath") [action="set"]/> <header name="qname" action="remove"/></pre> @@ -1298,7 +1281,6 @@ <h3>Selection Mediators </h3> <h4><a id="filter">Filter</a> </h4> - <pre xml:space="preserve"> <filter (source="xpath" regex="string") | xpath="xpath"> mediator+ </filter></pre> @@ -1325,7 +1307,6 @@ mediators enclosed in the else element in sequence </p> <h4><a id="switch">Switch</a> </h4> - <pre xml:space="preserve"> <switch source="xpath"> <case regex="string"> mediator+ @@ -1343,10 +1324,8 @@ <p><a id="in"/> </p> <h4><a id="out">In / Out</a> </h4> - <pre xml:space="preserve"><in><br /> mediator+ </in><br /></pre> - <pre xml:space="preserve"><out> mediator+ </out></pre> @@ -1396,7 +1375,6 @@ <h3>Database Mediators </h3> <h4><a id="dblookup">DB-lookup</a> </h4> - <pre xml:space="preserve"><dblookup> <connection> <pool> @@ -1428,7 +1406,6 @@ DataSource or specified in-line, in which case an Apache DBCP connection pool is established and used. Apache DBCP connection pools support the following properties: </p> - <ul> <li>autocommit = true | false </li> <li>isolation = Connection.TRANSACTION_NONE | @@ -1458,7 +1435,6 @@ context, and the column attribute specifies a column number or name . </p> <h4><a id="dbreport">DB-report</a> </h4> - <pre xml:space="preserve"><dbreport> <connection> <pool> @@ -1489,7 +1465,6 @@ <h3>Advanced Mediators </h3> <h4><a id="RMSequence">RMSequence</a> </h4> - <pre xml:space="preserve"> <RMSequence (correlation="xpath" [last-message="xpath"]) | single="true" [version="1.0|1.1"]/></pre> <p>The <RMSequence> mediator can be used to create a sequence of messages @@ -1506,7 +1481,6 @@ 1.1. </p> <h4><a id="throttle">Throttle</a> </h4> - <pre xml:space="preserve"><throttle [onReject="string"] [onAccept="string"] id="string"> (<policy key="string"/> | <policy>..</policy>) <onReject>..</onReject>? @@ -1526,7 +1500,6 @@ rejected messages are to be handled. </p> <h4><a id="cache">Cache</a> </h4> - <pre xml:space="preserve"> <cache [id="string"] [hashGenerator="class"] [timeout="seconds"] [scope=(per-host | per-mediator)] collector=(true | false) [maxMessageSize="in-bytes"]> <onCacheHit [sequence="key"]> @@ -1555,7 +1528,6 @@ attribute defines the maximum number of elements to be cached. </p> <h4><a id="clone">Clone</a> </h4> - <pre xml:space="preserve"> <clone [continueParent=(true | false)]> <target [to="uri"] [soapAction="qname"] [sequence="sequence_ref"] [endpoint="endpoint_ref"]> <sequence> @@ -1574,7 +1546,6 @@ custom 'To' address and/or a 'Action' may be specified for cloned messages </p> <h4><a id="iterate">Iterate</a> </h4> - <pre xml:space="preserve"> <iterate [continueParent=(true | false)] [preservePayload=(true | false)] (attachPath="xpath")? expression="xpath"> <target [to="uri"] [soapAction="qname"] [sequence="sequence_ref"] [endpoint="endpoint_ref"]> <sequence> @@ -1597,7 +1568,6 @@ splitted messages would contain the split elements as the SOAP body. </p> <h4><a id="aggregate">Aggregate</a> </h4> - <pre xml:space="preserve"> <aggregate> <correlateOn expression="xpath"/>? <completeCondition [timeout="time-in-seconds"]> @@ -1622,7 +1592,6 @@ </p> <h4><a id="event">Event</a> </h4> - <pre xml:space="preserve"> <syn:eventPublisher eventSourceName="event-source-name"/></pre> <p>Event mediator publishes events to the given event source. Thus, the @@ -1630,7 +1599,6 @@ mediator. </p> <h4><a id="transaction">Transaction</a> </h4> - <pre xml:space="preserve"> <syn:transaction action="transaction-action" /></pre> <p>Transaction mediator can provide transaction facility for a set of mediators @@ -1644,7 +1612,6 @@ <h3>Extension mediators </h3> <h4><a id="class">Class</a> </h4> - <pre xml:space="preserve"> <class name="class-name"> <property name="string" value="literal"> (either literal or XML child) @@ -1657,7 +1624,6 @@ are invoked on the class, once, during initialization. </p> <h4><a id="pojoCommand">POJOCommand</a> </h4> - <pre xml:space="preserve"> <pojoCommand name="class-name"> ( <property name="string" value="string"/> | @@ -1689,7 +1655,6 @@ 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 @@ -1701,7 +1666,6 @@ 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 @@ -1709,7 +1673,6 @@ 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 @@ -1743,7 +1706,6 @@ entry providing a URL or a key reference to a Registry. The configuration is then created on first use or as necessary (as per registry lookup semantics) by the mediators which reference this configuration. </p> - <pre xml:space="preserve"> <localEntry key="string"/> <localEntry key="string" src="url"/></pre> @@ -1751,7 +1713,6 @@ src, key or inlined XML references to the Spring configuration </p> <h4><a id="spring">Spring mediator</a> </h4> - <pre xml:space="preserve"> <spring:spring bean="exampleBean1" key="string"/></pre> <p>The <spring> element creates an instance of a mediator, which is @@ -1776,38 +1737,9 @@ <configuration xmlns="http://www.wso2.org/products/wso2commons/rule"> <ruleSource [key="String"] [sourceFormat="String(xml|native)"]> In-lined - </ruleSource> + </ruleSource> <provider uri="rule service provider uri" class="rule service provider implementation"> <property name="String" value="String"/>* </provider> - <provider uri="rule service provider uri" class="rule service provider implementation"> - <property name="String" value="String"/>* - </provider> - - <ruleSet> - <creation> - <property name="String" value="String"/>* - </creation> - <registration> - <property name="String" value="String"/>* - </registration> - <deregistration> - <property name="String" value="String"/>* - </deregistration> - </ruleSet> - - <ruleSession [type="stateful|stateless"]> - <property name="String" value="String"/>* - </ruleSession> - - <input name="String" type="String" [expression="XPath"] [value="String"] [key="String"] [class="String"]> - <property name="String" type="String" [expression="XPath"] [value="String"] [key="String"] />* - </input>* - - <output name="String" type="String" [expression="XPath"] [value="String"] [key="String"] [class="String"]> - <property name="String" type="String" [expression="XPath"] [value="String"] [key="String"] />* - </output>* - </configuration> - - <childMediators> + <ruleSet> <creation> <property name="String" value="String"/>* </creation> <registration> <property name="String" value="String"/>* </registration> <deregistration> <property name="String" value="String"/>* </deregistration> </ruleSet> <ruleSession [type="stateful|stateless"]> <property name="String" value="String"/>* </ruleSession> <input name="String" type="String" [expression="XPath"] [value="String"] [key="String"] [class="String"]> <property name="String" type="String" [expression="XPath"] [value="String"] [key="String"] />* </input>* <output name="String" type="String" [expression="XPath"] [value="String"] [key="String"] [class="String"]> <property name="String" type="String" [expression="XPath"] [value="String"] [key="String"] />* </output>* </configuration> <childMediators> any mediators </childMediators> @@ -1906,7 +1838,6 @@ "custom") can be configured using 'property' inside 'input / output' definitions. There is a sample to illustrate this capability. Please refers the sample guide.</p> - <p>For input , the values are calculated based on value or combination of key and expression. The expression of the 'input' defines source node to get data. These values are bind into the rule engine from its 'name' so that those can be Modified: trunk/esb/java/docs/xdoc/mediators/rule.xml URL: http://wso2.org/svn/browse/wso2/trunk/esb/java/docs/xdoc/mediators/rule.xml?rev=42340&r1=42339&r2=42340&view=diff ============================================================================== --- trunk/esb/java/docs/xdoc/mediators/rule.xml (original) +++ trunk/esb/java/docs/xdoc/mediators/rule.xml Fri Jul 31 11:50:15 2009 @@ -20,39 +20,31 @@ <h3>Syntax</h3> <pre xml:space="preserve"> <rule xmlns="http://ws.apache.org/ns/synapse"> - <configuration xmlns="http://www.wso2.org/products/wso2commons/rule"> - <ruleSource [key="String"] [sourceFormat="String(xml|native)"]> - In-lined - </ruleSource> - - <provider uri="rule service provider uri" class="rule service provider implementation"> - <property name="String" value="String"/>* - </provider> - - <ruleSet> - <creation> - <property name="String" value="String"/>* - </creation> - <registration> - <property name="String" value="String"/>* - </registration> - <deregistration> - <property name="String" value="String"/>* - </deregistration> - </ruleSet> - - <ruleSession [type="stateful|stateless"]> - <property name="String" value="String"/>* - </ruleSession> - - <input name="String" type="String" [expression="XPath"] [value="String"] [key="String"] [class="String"]> - <property name="String" type="String" [expression="XPath"] [value="String"] [key="String"] />* - </input>* - - <output name="String" type="String" [expression="XPath"] [value="String"] [key="String"] [class="String"]> - <property name="String" type="String" [expression="XPath"] [value="String"] [key="String"] />* - </output>* - </configuration> + +<configuration xmlns="String"> + <provider class="String" uri="String"> + <property name="String" [value="String" | expression="String"]/>* + </provider> + <executionSet uri="some uri"> + <source key="keyof script"/> + <creation> + <property name="String" [value="String" | expression="String"]/>* + </creation> + <registration> + <property name="String" [value="String" | expression="String"]/>* + </registration> + <deregistration> + <property name="String" [value="String" | expression="String"]/>* + </deregistration> + </executionSet> + <session type=[stateful|stateless]"> + <property name="String" [value="String" | expression="String"]/>* + </session> + <input name="String" class="String" type="String" [value="String"] [expression="String"] [key="String"]/> + <output name="String" class="String" type="String" [value="String"] [expression="String"] [key="String"]/> + <inputFilter class="String"/> + <outputFilter class=""String"/> +</configuration> <childMediators> any mediators Modified: trunk/esb/java/docs/xdoc/samples/rule_samples.xml URL: http://wso2.org/svn/browse/wso2/trunk/esb/java/docs/xdoc/samples/rule_samples.xml?rev=42340&r1=42339&r2=42340&view=diff ============================================================================== --- trunk/esb/java/docs/xdoc/samples/rule_samples.xml (original) +++ trunk/esb/java/docs/xdoc/samples/rule_samples.xml Fri Jul 31 11:50:15 2009 @@ -30,75 +30,44 @@ <h2>Introduction</h2> <p>Rule mediator just pass the values extracted from the SOAP envelope, the -Message Context, the registry to the rule engine and let to rule engine to take -decision. Rule mediator defines the <strong>inputs</strong> (with in input tag) -and these are used when computing values for binding to rule engine. A input -tells how to, what and from where get the values .With in rule engine , using -name attributes in the input definition , the corresponding value can be -accessed . Any inputs values can only be accessed through the provided -abstraction <strong>org.wso2.rule.Inputs</strong> and it only expose -<strong>get(name)</strong> method . If you want to set any output value -(consider as return values from rule engine) , there is a provided abstraction -<strong>org.wso2.rule.Outputs</strong> and it only expose -<strong>put(key,value)</strong> method. If you want to set return values from -the rule engine back to the message context or to the SOAP envelope , then ,you -have to use output in the rule mediator definition . A output tells how to -,what and to where set the return values.There is a special output value called -'<strong>execute_children'</strong> , this is used to indicate, after retuning -back from the rule engine , whether child mediators inside the rule mediator -should be executed or not. if the value is <strong>'true'</strong> ,then if -there are any child mediators , then those would be executed . For any other -value in the <strong>'execute_children'</strong>, avoids the execution of child -mediators. Then,what happens is , just pass the control to the next sibling -mediator. </p> +Message Context, the registry as facts to the rule engine and let to rule +engine to take decision. </p> <h2 id="Sample600">Sample 600 : Rule mediator as a Filter - Simple rule based routing (Using an in-lined rule script)</h2> <pre><!-- Simple rule based routing of messages - same as filter mediator --> <definitions xmlns="http://ws.apache.org/ns/synapse"> - <in> - <rule> - <configuration xmlns="http://www.wso2.org/products/wso2commons/rule"> - <ruleSource> - - <package name="SimpleRoutingRules" - xmlns="http://drools.org/drools-5.0" - xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" - xs:schemaLocation="http://drools.org/drools-5.0 drools-4.0.xsd"> - - <import name="org.apache.synapse.MessageContext"/> - <import name="org.wso2.rule.Inputs"/> - <import name="org.wso2.rule.Outputs"/> - - <rule name="Invoke IBM "> - - <lhs> - - <pattern object-type="MessageContext" identifier="mc"> - </pattern> - <pattern object-type="Inputs" identifier="inputs"> - </pattern> - <pattern object-type="Outputs" identifier="outputs"> - </pattern> - - <eval>((String)inputs.get("symbol")).equals("IBM")</eval> - </lhs> - - <rhs> - outputs.put("execute_children","true"); - </rhs> - - </rule> - </package> - - </ruleSource> - - <input name="symbol" expression="//m0:getQuote/m0:request/m0:symbol" - xmlns:m0="http://services.samples" type="string"/> + <configuration xmlns="http://www.wso2.org/products/rule/jsr94"> + <executionSet uri="SimpleRoutingRules"> + <source> + <package name="SimpleRoutingRules" + xmlns="http://drools.org/drools-5.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" + xs:schemaLocation="http://drools.org/drools-5.0 drools-4.0.xsd"> + <import name="org.apache.synapse.MessageContext"/> + <rule name="Invoke IBM "> + <lhs> + <pattern object-type="MessageContext" identifier="mc"> + </pattern> + <pattern object-type="String" identifier="symbol"> + </pattern> + <eval>symbol.equals("IBM")</eval> + </lhs> + <rhs> + mc.setProperty("execute_children","true"); + </rhs> + </rule> + </package> + </source> + </executionSet> + <session type="stateless"/> + <input name="mc" type="context"/> + <input name="symbol" type="pojo" class="java.lang.String" + expression="//m0:getQuote/m0:request/m0:symbol/child::text()" + xmlns:m0="http://services.samples"/> </configuration> - <childMediators> <send> <endpoint> @@ -107,11 +76,8 @@ </send> <drop/> </childMediators> - </rule> - </in> - <out> <send/> </out> @@ -168,7 +134,7 @@ <h2 id="Sample601">Sample 601: Rule mediator as a Filter - Simple rule based routing (Using rule script from registry)</h2> <pre><!-- Simple rule based routing of messages - same as filter mediator --> -<<definitions xmlns="http://ws.apache.org/ns/synapse"> +<definitions xmlns="http://ws.apache.org/ns/synapse"> <!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or http://) --> <registry provider="org.wso2.carbon.mediation.registry.ESBRegistry"> @@ -185,11 +151,15 @@ <in> <rule> - <configuration xmlns="http://www.wso2.org/products/wso2commons/rule"> - <ruleSource key="rule-script-key"/> - - <input name="symbol" expression="//m0:getQuote/m0:request/m0:symbol" - xmlns:m0="http://services.samples" type="string"/> + <configuration xmlns="http://www.wso2.org/products/rule/jsr94"> + <executionSet uri="SimpleRoutingRules"> + <source key="rule-script-key"/> + </executionSet> + <session type="stateless"/> + <input name="mc" type="context"/> + <input name="symbol" type="pojo" class="java.lang.String" + expression="//m0:getQuote/m0:request/m0:symbol/child::text()" + xmlns:m0="http://services.samples"/> </configuration> <childMediators> <send> @@ -216,31 +186,19 @@ xmlns="http://drools.org/drools-5.0" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://drools.org/drools-5.0 drools-4.0.xsd"> - <import name="org.apache.synapse.MessageContext"/> - <import name="org.wso2.rule.Inputs"/> - <import name="org.wso2.rule.Outputs"/> - <rule name="Invoke IBM "> - <lhs> - <pattern object-type="MessageContext" identifier="mc"> </pattern> - <pattern object-type="Inputs" identifier="inputs"> + <pattern object-type="String" identifier="symbol"> </pattern> - <pattern object-type="Outputs" identifier="outputs"> - </pattern> - - <eval>((String)inputs.get("symbol")).equals("IBM")</eval> + <eval>symbol.equals("IBM")</eval> </lhs> - <rhs> - outputs.put("execute_children","true"); + mc.setProperty("execute_children","true"); </rhs> - </rule> - </package></pre> <p><strong>Objective</strong>: Introduction to simple rule based routing </p> @@ -258,7 +216,6 @@ routing (Using an Drools native language </h2> <pre><!-- Simple rule based routing of messages - same as filter mediator --> <!-- The use of Drools native language --> - <definitions xmlns="http://ws.apache.org/ns/synapse"> <!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or http://) --> @@ -276,17 +233,18 @@ <in> <rule> - <configuration xmlns="http://www.wso2.org/products/wso2commons/rule"> - <ruleSource key="rule-script-key" sourceFormat="drl"/> - - <ruleSet> + <configuration xmlns="http://www.wso2.org/products/rule/jsr94"> + <executionSet uri="SimpleRoutingRules"> + <source key="rule-script-key"/> <creation> <property name="source" value="drl"/> </creation> - </ruleSet> - - <input name="symbol" expression="//m0:getQuote/m0:request/m0:symbol" - xmlns:m0="http://services.samples" type="string"/> + </executionSet> + <session type="stateless"/> + <input name="mc" type="context"/> + <input name="symbol" type="pojo" class="java.lang.String" + expression="//m0:getQuote/m0:request/m0:symbol/child::text()" + xmlns:m0="http://services.samples"/> </configuration> <childMediators> <send> @@ -314,20 +272,18 @@ package SimpleRoutingRules; import org.apache.synapse.MessageContext; -import org.wso2.rule.Inputs; -import org.wso2.rule.Outputs; rule InvokeIBM when -inputs : Inputs() -outputs : Outputs() -eval( ((String)inputs.get("symbol")).equals("IBM") ) +mc : MessageContext() +symbol: String() +eval( symbol.equals("IBM") ) then -outputs.put("execute_children","true"); +mc.setProperty("execute_children","true"); end @@ -405,14 +361,18 @@ <in> <rule> - <configuration xmlns="http://www.wso2.org/products/wso2commons/rule"> - <ruleSource key="rule-script-key"/> - <input name="ibmSeq" key="ibmSequence" type="sequence"/> - <input name="sunSeq" key="sunSequence" type="sequence"/> - <input name="msftSeq" key="msftSequence" type="sequence"/> - - <input name="symbol" expression="//m0:getQuote/m0:request/m0:symbol" - xmlns:m0="http://services.samples" type="string"/> + <configuration xmlns="http://www.wso2.org/products/rule/jsr94"> + <executionSet uri="AdvancedRoutingRules"> + <source key="rule-script-key"/> + </executionSet> + <session type="stateless"/> + <input name="mc" type="context"/> + <input name="ibmSeq" key="ibmSequence" type="mediator"/> + <input name="sunSeq" key="sunSequence" type="mediator"/> + <input name="msftSeq" key="msftSequence" type="mediator"/> + <input name="symbol" type="pojo" class="java.lang.String" + expression="//m0:getQuote/m0:request/m0:symbol/child::text()" + xmlns:m0="http://services.samples"/> </configuration> </rule> @@ -432,23 +392,26 @@ xs:schemaLocation="http://drools.org/drools-5.0 drools-4.0.xsd"> <import name="org.apache.synapse.MessageContext"/> - <import name="org.wso2.rule.Inputs"/> - <import name="org.wso2.rule.Outputs"/> <import name="org.apache.synapse.Mediator"/> + <import name="org.apache.synapse.mediators.base.SequenceMediator"/> <rule name="Invoke IBM "> <lhs> <pattern object-type="MessageContext" identifier="mc"> </pattern> - <pattern object-type="Inputs" identifier="inputs"> + <pattern object-type="String" identifier="symbol"> </pattern> - <pattern object-type="Outputs" identifier="outputs"> + <pattern identifier="seq" object-type="SequenceMediator"> + <field-binding field-name="name" identifier="a4"/> + <field-constraint field-name="name"> + <literal-restriction evaluator="==" value="ibmSequence"/> + </field-constraint> </pattern> - <eval>((String)inputs.get("symbol")).equals("IBM")</eval> + <eval>symbol.equals("IBM")</eval> </lhs> <rhs> - ((Mediator)inputs.get("ibmSeq")).mediate(mc); + ((Mediator)seq).mediate(mc); </rhs> </rule> @@ -456,15 +419,19 @@ <lhs> <pattern object-type="MessageContext" identifier="mc"> </pattern> - <pattern object-type="Inputs" identifier="inputs"> + <pattern object-type="String" identifier="symbol"> </pattern> - <pattern object-type="Outputs" identifier="outputs"> + <pattern identifier="seq" object-type="SequenceMediator"> + <field-binding field-name="name" identifier="a4"/> + <field-constraint field-name="name"> + <literal-restriction evaluator="==" value="sunSequence"/> + </field-constraint> </pattern> - <eval>((String)inputs.get("symbol")).equals("SUN")</eval> + <eval>symbol.equals("SUN")</eval> </lhs> <rhs> - ((Mediator)inputs.get("sunSeq")).mediate(mc); + ((Mediator)seq).mediate(mc); </rhs> </rule> @@ -472,15 +439,19 @@ <lhs> <pattern object-type="MessageContext" identifier="mc"> </pattern> - <pattern object-type="Inputs" identifier="inputs"> + <pattern object-type="String" identifier="symbol"> </pattern> - <pattern object-type="Outputs" identifier="outputs"> + <pattern identifier="seq" object-type="SequenceMediator"> + <field-binding field-name="name" identifier="a4"/> + <field-constraint field-name="name"> + <literal-restriction evaluator="==" value="msftSequence"/> + </field-constraint> </pattern> - <eval>((String)inputs.get("symbol")).equals("MSFT")</eval> + <eval>symbol.equals("MSFT")</eval> </lhs> <rhs> - ((Mediator)inputs.get("msftSeq")).mediate(mc); + ((Mediator)seq).mediate(mc); </rhs> </rule> @@ -539,13 +510,12 @@ <h2 id="Sample604">Sample 604 : Simple message transformation - Rule mediator for message transformation</h2> <pre><!-- Simple rule based transformation (changing message ) --> - <definitions xmlns="http://ws.apache.org/ns/synapse"> <!-- the SimpleURLRegistry allows access to a URL based registry (e.g. file:/// or http://) --> <registry provider="org.wso2.carbon.mediation.registry.ESBRegistry"> <!-- the root property of the simple URL registry helps resolve a resource URL as root + key --> <parameter name="root">file:repository/samples/resources/</parameter> - <!-- all resources loaded from the URL registry would be cached for this number of milli seconds --> + <!-- all resources loaded from the URL registry would be cached for this number of milliseconds --> <parameter name="cachableDuration">15000</parameter> </registry> @@ -555,12 +525,15 @@ <in> <rule> - <configuration xmlns="http://www.wso2.org/products/wso2commons/rule"> - <ruleSource key="rule-script-key"/> - <input name="symbol" expression="//m0:getQuote/m0:request/m0:symbol" - xmlns:m0="http://services.samples" type="string"/> + <configuration xmlns="http://www.wso2.org/products/rule/jsr94"> + <executionSet uri="SimpleMessageTransformationRules"> + <source key="rule-script-key"/> + </executionSet> + <session type="stateless"/> + <input name="symbol" expression="//m0:getQuote/m0:request/m0:symbol/child::text()" + class="java.lang.String" xmlns:m0="http://services.samples" type="pojo"/> <output name="symbol" expression="//m0:getQuote/m0:request/m0:symbol" - xmlns:m0="http://services.samples" type="string"/> + class="java.lang.String" xmlns:m0="http://services.samples" type="pojo"/> </configuration> </rule> @@ -584,26 +557,14 @@ xmlns="http://drools.org/drools-5.0" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://drools.org/drools-5.0 drools-4.0.xsd"> - - <import name="org.apache.synapse.MessageContext"/> - <import name="org.wso2.rule.Inputs"/> - <import name="org.wso2.rule.Outputs"/> - <rule name="Invoke Always IBM "> <lhs> - <pattern object-type="MessageContext" identifier="mc"> - </pattern> - <pattern object-type="Inputs" identifier="inputs"> + <pattern object-type="String" identifier="symbol"> </pattern> - <pattern object-type="Outputs" identifier="outputs"> - </pattern> - <eval>((String)inputs.get("symbol")).equals("MSFT") - || ((String)inputs.get("symbol")).equals("SUN") - </eval> + <eval>symbol.equals("MSFT") || symbol.equals("SUN")</eval> </lhs> - <rhs> - outputs.put("symbol","IBM"); + update(drools.getWorkingMemory().getFactHandle(symbol),"IBM"); </rhs> </rule> @@ -659,18 +620,20 @@ <out> <rule> - <configuration xmlns="http://www.wso2.org/products/wso2commons/rule"> - <ruleSource key="rule-script-key"/> - <input name="symbol" type="string" + <configuration xmlns="http://www.wso2.org/products/rule/jsr94"> + <executionSet uri="SimpleMessageTransformationRules"> + <source key="rule-script-key"/> + </executionSet> + <session type="stateless"/> + <input name="symbol" type="pojo" class="java.lang.String" expression="self::node()//m0:return/m1:symbol/child::text()" xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd"/> - <input name="price" type="double" + <input name="price" type="pojo" class="java.lang.Double" expression="self::node()//m0:return/m1:last/child::text()" xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd"/> - - <output name="price" type="double" + <output name="price" type="pojo" class="java.lang.Double" expression="self::node()//m0:return/m1:last" xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd"/> @@ -686,29 +649,20 @@ xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://drools.org/drools-5.0 drools-4.0.xsd"> - <import name="org.apache.synapse.MessageContext"/> - <import name="org.wso2.rule.Inputs"/> - <import name="org.wso2.rule.Outputs"/> - <import name="java.lang.Double"/> - - <rule name="Get commission form SUN and MSFT but not from IBM "> + <lhs> - <pattern object-type="MessageContext" identifier="mc"> + <pattern object-type="String" identifier="symbol"> </pattern> - <pattern object-type="Inputs" identifier="inputs"> + <pattern object-type="Double" identifier="price"> </pattern> - <pattern object-type="Outputs" identifier="outputs"> - </pattern> - <eval>((String)inputs.get("symbol")).equals("MSFT") - || ((String)inputs.get("symbol")).equals("SUN") - </eval> + <eval>symbol.equals("MSFT") || symbol.equals("SUN")</eval> </lhs> <rhs> - Double price = (Double)inputs.get("price"); - Object newPrice = price.doubleValue()+ 3000.68; - outputs.put("price",newPrice); + Double newPrice = price.doubleValue()+ 3000.68; + update(drools.getWorkingMemory().getFactHandle(price),newPrice); + retract(drools.getWorkingMemory().getFactHandle(symbol)); </rhs> </rule> @@ -751,7 +705,7 @@ <registry provider="org.wso2.carbon.mediation.registry.ESBRegistry"> <!-- the root property of the simple URL registry helps resolve a resource URL as root + key --> <parameter name="root">file:repository/samples/resources/</parameter> - <!-- all resources loaded from the URL registry would be cached for this number of milli seconds --> + <!-- all resources loaded from the URL registry would be cached for this number of milliseconds --> <parameter name="cachableDuration">15000</parameter> </registry> @@ -763,21 +717,22 @@ <in> <rule> - <configuration xmlns="http://www.wso2.org/products/wso2commons/rule"> - <ruleSource key="rule-script-forward-key" sourceFormat="drl"/> - <ruleSet> + <configuration xmlns="http://www.wso2.org/products/rule/jsr94"> + <executionSet uri="ForwardTransformation"> + <source key="rule-script-forward-key"/> <creation> <property name="source" value="drl"/> </creation> - </ruleSet> - + </executionSet> + <session type="stateless"/> + <input name="mc" type="context"/> <input name="symbol" expression="self::node()//m0:CheckPriceRequest/m0:Code/child::text()" - xmlns:m0="http://services.samples" type="string"/> + xmlns:m0="http://services.samples" type="pojo" class="java.lang.String"/> <output name="request" expression="self::node()//m0:CheckPriceRequest" xmlns:m0="http://services.samples" - class="samples.GetQuoteRequest" type="custom"/> + class="org.wso2.carbon.rule.samples.GetQuoteRequest" type="pojo"/> </configuration> <childMediators> <send> @@ -794,30 +749,29 @@ <out> <rule> - <configuration xmlns="http://www.wso2.org/products/wso2commons/rule"> - <ruleSource key="rule-script-back-key" sourceFormat="drl"/> - - <ruleSet> + <configuration xmlns="http://www.wso2.org/products/rule/jsr94"> + <executionSet uri="BackwardTransformation"> + <source key="rule-script-back-key"/> <creation> <property name="source" value="drl"/> </creation> - </ruleSet> - - <input name="symbol" type="string" + </executionSet> + <session type="stateless"/> + <input name="symbol" type="pojo" class="java.lang.String" expression="self::node()//m0:return/m1:symbol/child::text()" xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd"/> - - <input name="price" type="double" + <input name="price" type="pojo" class="java.lang.Double" expression="self::node()//m0:return/m1:last/child::text()" xmlns:m0="http://services.samples" xmlns:m1="http://services.samples/xsd"/> - <output name="response" type="custom" + <output name="response" type="pojo" expression="self::node()//m0:return" - class="samples.CheckPriceResponse" + class="org.wso2.carbon.rule.samples.CheckPriceResponse" xmlns:m0="http://services.samples"/> </configuration> + </rule> <send/> @@ -831,29 +785,24 @@ <![CDATA[ package ForwardTransformation; +import org.wso2.carbon.rule.samples.GetQuoteRequest ; import org.apache.synapse.MessageContext; -import org.wso2.rule.Inputs; -import org.wso2.rule.Outputs; -import samples.GetQuoteRequest; rule ForwardTransformation when -inputs : Inputs() -outputs : Outputs() - -eval( (inputs.get("symbol") != null) ) +symbol : String() +mc : MessageContext() +eval(symbol != null ) then GetQuoteRequest request = new GetQuoteRequest(); -request.setSymbol((String)inputs.get("symbol")); -outputs.put("request",request); - -outputs.put("execute_children","true"); - +request.setSymbol(symbol); +insert(request); +mc.setProperty("execute_children","true"); end ]]> @@ -865,27 +814,24 @@ <![CDATA[ package BackwardTransformation; -import org.apache.synapse.MessageContext; -import org.wso2.rule.Inputs; -import org.wso2.rule.Outputs; -import samples.CheckPriceResponse; +import org.wso2.carbon.rule.samples.CheckPriceResponse; rule BackwardTransformation when -inputs : Inputs() -outputs : Outputs() -eval( (inputs.get("price") != null) && (inputs.get("symbol") != null) ) +price : Double() +symbol : String() +eval( price != null && symbol != null ) then CheckPriceResponse response = new CheckPriceResponse(); -response.setCode((String)inputs.get("symbol")); -response.setPrice(((Double)inputs.get("price")).toString()); +response.setCode(symbol); +response.setPrice(price); -outputs.put("response",response); +insert(response); end @@ -905,7 +851,7 @@ <strong>CheckPriceResponse.java</strong> which are shown in bellow, have to be compiled and put in classpath. Easy way may be putting as a jar inside <strong>repository/components/lib</strong>. Pleas note that these classes need -to be group to package <strong>samples</strong>. </p> +to be group to package <strong>org.wso2.carbon.rule.samples</strong>. </p> <p>This sample also illustrates a advanced transformation using rule mediator. </p> @@ -920,13 +866,12 @@ the sample used following Java Objects</p> <p><strong>For input transformation</strong></p> -<pre> package samples; - /** - * Represents the GetQuote Request - only for sample demonstration - */ +<pre> package org.wso2.carbon.rule.samples; +/** + * + */ public class GetQuoteRequest { - private String symbol; public String getSymbol() { @@ -947,14 +892,14 @@ }</pre> <p><strong>For output transformation</strong></p> -<pre> package samples; - /** - * Represents the Check Price Response - only for sample demonstration +<pre> package org.wso2.carbon.rule.samples; + +/** + * */ public class CheckPriceResponse { - private String code; - private String price; + private Double price; public String getCode() { return code; @@ -964,11 +909,11 @@ this.code = code; } - public String getPrice() { + public Double getPrice() { return price; } - public void setPrice(String price) { + public void setPrice(Double price) { this.price = price; } @@ -979,7 +924,8 @@ "<m1:Price>" + price + "</m1:Price>" + "</m:CheckPriceResponse>"; } -}</pre> +} +</pre> <p>This is just a example to show what kind of cool thing can be done using rule mediator. </p> _______________________________________________ Esb-java-dev mailing list [email protected] https://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev
