Rule mediator is to integrate the WSO2 Rules component to the WSO2 ESB in order to define dynamic integration decisions in terms of rules.
<rule> <ruleset> <source [ key="xs:string" ]> [ in-Lined ] </source> <creation> <property name="xs:string" value="xs:string"/>* </creation> </ruleset> <session type="[stateless|stateful]"/>* <facts> <fact name="xs:string" type="xs:string" expression="xs:string" value="xs:string"/>+ </facts> <results> <result name="xs:string" type="xs:string" expression="xs:string" value="xs:string"/>* </results> [ <childMediators> <mediator/>* </childMediators> ] </rule>
The source is the only mandatory element of the ruleset. However, the properties required for the creation of the ruleset can also be specified within ruleset. The key attribute is a registry key, which is to lookup the rule script from the registry if the rule script is in the registry. The rule set can be given as a child node of source elemenent. If the rule set is non-XML, you may need to wrap it with a CDATA section inside a XML tag ex: <X><![CDATA[ native code]]></X>
Note : The key or in-lined rule script must be defined. Otherwise, the rule mediator configuration is invalid.
Rule Session specify the stateful or stateless behavior of the rule engine. If this has value 'stateful', then the rule engine will execute rules in a stateful manner, for any other value, it assumes as stateless. There are optional properties, which are used when creating the rule session. Rule session is optional and the default one is stateful.
Facts specify the facts being used in rule set. It also defines how to formulate facts from the message, etc. Results define how to handle results from the rule set execution. Usually, results adapters enrich the message with results. For example, If you are using POJO adapter (i.e. a java class as the type; the class name of a result), then we transform POJO into an XML and attached to the SOAP message.
Figure1: Rule Mediator
Each of configuration elements is described in following section
Rule script can be given as a registry key or an in-lined script. To give rule script as in-lined, you can use editor.
The format (language) of the rule script . If it is a XML, then this attribute should be 'xml'. Any other value, rule mediator assumes that the rule script is in native format. If the rule script is in native format, it should be given by wrapping as a CDATA section inside a XML tag ex: <X><![CDATA[ native code]]></X>.
Note: The key or in-lined rule script must be defined. Otherwise, rule mediator is invalid.
Session Type - Indicates the stateful or stateless behavior of the rule engine. If this has value ' stateful ' , then rule engine will executes rules in a state full manner , for any other value , it assumes as stateless.
property - Those are used when creating rule session.
It is possible to exists properties for rules set creation, registration, deregistration and there are add property options for each.
Example Usage: When using Drool native language (.drl) for rule script, it is needed to provide .dsl file .This can be done using attribute named 'source' and value 'drl'.
<ruleSet>
<creation>
<property name="source" value="drl"/>
</creation>
</ruleSet>
Input defines what are the facts that should injected to Rule Engine in order to fire rules whereas Output describes what should do with return value form rule engine.
Figure 2 shows a one senario of addting input
width="1319"
height="122">
Figure 2 Inputs of the Rule Mediator
Type : According to current implementation valid types are as bellow.
Name : Value Type Static Value or XPath expression
Value / Expression : value - Represents any static value. expression- XPath expression is used to extract data from either external XML source or SOAP envelope. There is no default value.
Registry Key : The registry or Message context key .This is used for getting data from either registry or message context
Registry Browser : If the key is registry resource, the browser to select the resource.
NS Editor : You can click this link to add namespaces if you are providing an expression. You will be provided another panel named 'Namespace Editor' where you can provide any number of namespace prefixes and url
Action : Delete the input out put
<rule> <ruleset> <source key="rule/sample.xml"/> </ruleset> <facts> <fact name="symbol" type="java.lang.String" expression="//m0:getQuote/m0:request/m0:symbol/child::text()" xmlns:m0="http://services.samples"/> </facts> <childMediators> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> <drop/> </childMediators> </rule>