The Rule Mediator is used to integrate the WSO2 Rules component to the WSO2 ESB in order to define dynamic integration decisions in terms of rules.
The Rule mediator uses an XML message as an input and produces a processed XML message after applying a set of rules. The result xml message can be used as the new soap body message. Alternatively, the information in the processed XML message can be used route the message or do any further processing. or the information can be used to route the message. The use the information to route the message or do any other processing.
...
Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
<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 Main Elements of the Rule Token
<ruleset>
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 Ruleset can be given as a child node of <source
> element. If the Ruleset is non-XML, you may need to wrap it with a CDATA section inside a XML tag. For example,
Code Block | ||
---|---|---|
XML | XML | <X><![CDATA[ native code]]></X>
|
Info | ||
---|---|---|
| ||
The key or inline Rule script must be defined. Otherwise, the Rule Mediator configuration will be invalid. |
<session
>
The Rule Session specifies 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, "stateless" is assumed. There are optional properties, which are used when creating the Rule Session.
Info | ||
---|---|---|
| ||
Rule Session is optional and the default one is "Stateful." |
<facts
> / <results
>
- Facts - Specifies the facts being used in Ruleset. It also defines how to formulate facts from the message, etc.
- Results - Defines how to handle results from the Ruleset execution. Result-adapters usually 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.
The Main Attributes of the <facts
> and <results
> elements:
- "name" - The unique name.
- "value" - Represents any static value.
"expression" - XPath expression for extracting data from the message being passed between ESB components.
Info title Tip The default value is the first child of the SOAP Body.
- type- Defines the type of the input data. There are a few built-in types:
- Message
- Context
- Map
- POJO
Mediator
Info title Note Using the
rule-component.conf
, you can register new types along with adapters, which are responsible for formulating specified types from the data. If there is no registered adapter for a given type, then, we assume the given type as a valid Java class name and uses POJO adapter to formulate the POJO instance whose class is the given type.
...
UI Configuration
The parameters available to configure the Rule mediator are categorised into the following main elements.
...
Parameter Name | Description | ||||
---|---|---|---|---|---|
Rule Script As | This parameter is used to specify how you want to enter the rule script. Possible options are as follows.
| Rule Type | This parameter is used to specify whether
|
Input Facts
Output Facts
The Main Elements of the Rule Mediator
...
A rule script can be given as a registry key or an in-line script. To give rule script as in-lined, you can use the editor.
Rule Set options:
- URI
- In-lined - Allows to create or edit the Script of the Rule using the "Rule Script Editor."
- Registry Lookup - Allows to choose the key from Configuration Registry or Governance Registry.
...
title | Tip |
---|
...
|
...
|
...
It is possible to have properties for rules set creation, registration, de-registration. There are add property options for each.
For example, when using the Drool native language (DRL) for rule script, it is necessary to provide a DSL file.This can be done using the attribute named source
and value DRL
.
...
<ruleSet>
<creation>
<property name="source" value="drl"/>
</creation>
</ruleSet>
|
...
| |
Rule |
...
Those are used when creating a Rule Set.
Options for Rule Set Creation Properties:
- Name - The name of the Rule Set property.
- Value - The type of the property value.
- Action - Deletes the property.
...
Session Type - Indicates the stateful or stateless behavior of the Rule engine:
- Stateful - Rule engine will execute Rules in a stateful manner.
- Stateless
...
Used when creating Rule Session.
Options for Rule Session Configuration Properties:
- Name - The name of the Rule Set property.
- Value - The type of the property value.
- Action - Deletes the property.
...
...
- New Type
- Build-in Type:
- message
- dom
- content
- omelement
- mediator
...
Type | This parameter is used to specify whether the rule type is Regular or Decision Table. |
Input Facts
Input facts are facts that are sent by the rule service client. This section contains parameters that can be used to configure the input facts. Values should be defined for the following parameters before you add the individual input facts.
Parameter Name | Description |
---|---|
Wrapper Name | The name of the wrapping element for all the facts. |
NameSpace | The namespace for the wrapping element. |
You can click Add a Fact to add an input fact. The parameters available to configure an input fact are as follows.
Parameter Name | Description |
---|---|
Type | The fact type. You can select any of the registered fact types. |
Element Name | The element name of the fact in the XML configuration. |
NameSpace | The namespace for the element. |
XPath | This parameter can be used to enter an XPath expression to create an input fact using a part of the input XML. |
NS Editor | Click this link to edit the namespaces. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. |
Action | This parameter can be used to delete and existing fact. |
Output Facts
Output facts are the facts received by the rule service client after the rules in the rule set are applied.
Parameter Name | Description |
---|---|
Wrapper Name | The name of the wrapping element for all the output facts. |
NameSpace | The namespace for the wrapping element. |
You can click Add a Fact to add an output fact. The parameters available to configure an output fact are as follows.
Parameter Name | Description |
---|---|
Type | The fact type. You can select any of the registered fact types. |
Element Name | The fact type. You can select any of the registered fact types. |
NameSpace | The namespace of the element. |
Action | This parameter can be used to delete and existing fact. |
Info | ||
---|---|---|
| ||
You can configure the Mediator mediator using XML. Click on "switch to source view " in the "Mediator" window. |
...
Example
Code Block | ||||
---|---|---|---|---|
| ||||
<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> |
...