Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

1. Create a valid jar containing the java classes of facts and results defined for the "Order Approval" sample usecase use case in section Sample Rule Definition. 

2. Create a rule service configuration using the instruction in section BRS Configuration Languageinstructions in File-Based Configuration. The configuration file used for the sample is shown below, which is named as service.rsl (Rule Service Language).

 

Code Block
languagehtml/xml
titleservice.rsl
<ruleService
        name="OrderApprovalService"
        xmlns="http://wso2.org/carbon/rules"
        targetNamespace="http://com.test/orderApproval">
  <ruleSet>
        <rule resourceType="regular" sourceType="file">orderApprovalRules.drl</rule>
    </ruleSet>
    <operation name="placeOrder">
        <input wrapperElementName="placeOrder" namespace="http://com.test/placeorder">
            <fact elementName="order" namespace="http://com.test/placeorder" type="samples.userguide.PlaceOrder"></fact>
        </input>
        <output wrapperElementName="placeOrderRespone" namespace="http://com.test/placeorder">
            <fact elementName="orderAccept" namespace="http://com.test/placeorder" type="samples.userguide.OrderAccept"></fact>
            <fact elementName="orderReject" namespace="http://com.test/placeorder" type="samples.userguide.OrderReject"></fact>
        </output>
    </operation>
</ruleService>

 

3. You have so far created a .jar file, orderApprovalRules.drl and a service.rsl file. Place these files in a hierarchical folder structure as displayed below.

...

8. The Try-It tool can be used to test the sample through a request similar to the one shown bellow.

 

Code Block
<symbol>Company A</symbol>
<quantity>223</quantity>
<price>14</price>

 

9. Each rule can be tested by changing values in the symbol, price and quantity. For the request given above, the response will be as follows.

 

Code Block
languagehtml/xml
<brs:placeOrderResponse>
     <brs:result>
         <brs:OrderAccept xsi:type="ax2277:OrderAccept">
                <ax2275:message>Accepted order for: 223 stocks of Company A at$ 14.0</ax2275:message>
         </brs:OrderAccept>
     </brs:result>
</brs:placeOrderResponse>

 

10. Also, the WSDL of the service can be used to generate client-side code (stub) required for the service invocation. There is an option for code generation in the services management page. A client using generated stub codes is shown below and the codes are generated with option - "Unpacks the databinding classes".

...