Saturday, June 5, 2010

OSB dynamic routing to JRules

We want to provide a generic proxy to invoke JRules.

We provide a routing table in a jrulesEndpointLookupTable XQuery:

<operations>
<operation>
<name>checkemployee</name>
<endpoint>http://localhost:8080/DecisionService/ws/PV01_RuleApp/1.0/PV01_RuleProject/1.0</endpoint>
</operation>

<operation>
<name>checkcompany</name>
<endpoint>http://localhost:8080/DecisionService/ws/PV01_RuleApp/1.0/PV01_RuleProjectCompany/1.0</endpoint>
</operation>


</operations>


where we identify each Ruleset with an identifier (checkemployee).
The Request payload will specify this identifier (jrulesOperation), together with the JRules payload:

<xsd:element name="DecisionServiceRequest">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="jrulesOperation" type="xsd:string"/>
            <xsd:element name="jrulesPayload" type="xsd:anyType"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>


This is a sample payload:

<dec:DecisionServiceRequest xmlns:dec="http://www.ilog.com/rules/DecisionService">
    <dec:jrulesOperation>checkemployee</dec:jrulesOperation>
    <dec:jrulesPayload>
        <par:employeeRequest xmlns:par="http://www.ilog.com/rules/param" xmlns:emp="http://www.acme.com/Employee">
            <emp:EmployeeRequest>
                <emp:SSN>1234-56-7890</emp:SSN>
                <emp:name>Pierre</emp:name>
                <emp:dateOfBirth>1961-02-11</emp:dateOfBirth>
                <emp:employeeType>none</emp:employeeType>
                <emp:salary>20</emp:salary>
            </emp:EmployeeRequest>
        </par:employeeRequest>
    </dec:jrulesPayload>
</dec:DecisionServiceRequest>

where par:employeeRequest is the verbalization of the input parameter in JRules.

The OSB proxy service must:

- extract the jrulesOperation (checkemployee) and payload:

$body/dec:DecisionServiceRequest/dec:jrulesOperation/text()
$body/dec:DecisionServiceRequest/dec:jrulesPayload/node()

- do a lookup on the jrulesEndpointLookupTable to determine the endpoint:

$jrulesEndpointTable/operation[name=$jrulesOperation]/endpoint/text()

- do a Service Callout by using the Routing Option element to set the URI


- return as a body the response from JRules:

replace . in variable body with variable jrulesResponse

No comments: