Versions Compared

Key

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

There are two ways to create a rule service using the WSO2 BRS management console as follows, which are:

...

This demonstrates how to use the rule service upload UI for deploying a rule service.1.

  1. Create a valid JAR containing the Java classes of facts and results defined for the

...

  1. Order Approval

...

  1. sample

...

  1. user case in Sample Rule Definition.

...

  1. Create the Drools file that defines the rules for the sample use case. Note that the file must be in .drl format, not .dsrl.

...

  1. Create a rule service configuration using the instructions

...

  1. in File-Based Configuration. The configuration file

...

  1. which is named as service.rsl (Rule Service Language)

...

  1. and which is used for the sample is shown below.

    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>

 

...

  1. 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.
    Image Modified 

...

  1. Make an Axis2 archive file (OrderApprovalService.aar in this example) from the above content.

    Info
    titleInfor

...

  1. Log in to the WSO2 BRS management console and

...

Image Removed

...

  1. click Upload under Rules Service in the main page. 
    Image Added 
  2. The Upload Rule Service window opens. Upload the file created in step 4 and

...

  1. click Upload as shown below.
    Image Modified 

...

  1. The Deployed Services

...

  1.  window opens with the newly uploaded business rules exposed as a service. Click on it to access its dashboard and select the TryIt option on

...

  1. the Client Operations

...

  1.  panel in the service dashboard.
    Image Modified 

...

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

...

  1. below.

...

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

 

...

  1. 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.

 

...

  1. 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>

 

  1. The WSDL of the service can also be used

...

  1. 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 -

...

  1.  Unpacks the databinding classes

...

  1. .

    Code Block
    languagejava
    package org.wso2.carbon.samples;
    import org.wso2.carbon.samples.orderApprovalService.order.OrderAccept;
    import org.wso2.carbon.samples.orderApprovalService.order.PlaceOrder;
    import org.wso2.carbon.samples.orderApprovalService.order.PlaceOrderE;
    import org.wso2.carbon.samples.orderApprovalService.order.PlaceOrderRespone;
    import org.wso2.carbon.samples.orderApprovalService.stub.OrderApprovalServiceCallbackHandler;
    import org.wso2.carbon.samples.orderApprovalService.stub.OrderApprovalServiceStub;
    import java.rmi.RemoteException;
    
    public class PlaceOrderTestCase {
    
        public static void main(String[] args) {
    
            try {
                OrderApprovalServiceStub orderApprovalServiceStub = new OrderApprovalServiceStub("http://localhost:9763/services/OrderApprovalService");
                PlaceOrderE placeOrderE = new PlaceOrderE();
                PlaceOrder placeOrder = new PlaceOrder();
                placeOrder.setSymbol("Company A");
                placeOrder.setPrice(150);
                placeOrder.setQuantity(128);
                PlaceOrder[] placeOrders = new PlaceOrder[1];
                placeOrders[0] = placeOrder;
                placeOrderE.setOrder(placeOrders);
    
                PlaceOrderRespone placeOrderRespone = null; //new PlaceOrderRespone();
                try {
                    placeOrderRespone = orderApprovalServiceStub.placeOrder(placeOrders);
                } catch (RemoteException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
                OrderAccept[] orderAccepts = placeOrderRespone.getOrderAccept();
                String result = orderAccepts[0].getMessage();
                System.out.println(result);
    
    
    
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

Rule Service Wizard
Anchor
Rule Service Wizard
Rule Service Wizard

A rules service can be created through the rule service wizard of the WSO2 BRS management console, as follow.follows:1.

  1. Log in to the WSO2 BRS management console and

...

  1. click Create under Rules Service in the

...

  1. Main

...

  1. page.
    Image Modified 

...

  1. The Service Information

...

  1.  window opens. Enter the required information and

...

  1. click Next

...

  1. . The service name has to be unique.

...


  1. Image Modified 

...

  1. The Rule Set Information

...

  1.  window appears. There are four ways to specify a rule set or a rule script.

    Image Modified

    • In-lined : Script is provided in the window itself

    Image Modified

    • Registry Key: Include the rule script in the system's governance registry. (Multiple scripts can be added here).

    Image Modified

    • Rule File: Upload a Drools rules file from a folder.

    Image Modified

    • URL: Upload from a url

    Image Modified

...

  1.  

  2. Select a value for the Rule Type field to specify the format to be used to capture your business rule logic. The possible values are as follows:
    • Regular: If this rule type is selected, a rule set will be used to capture the business rule logic. Since a rule set is more flexible than a decision table, this value should be selected if your rule takes the form of unstructured sentences. You can use this rule type even in situations where your rule  takes the form of a table if some of the decision criteria is not applicable and/or output values are not defined.
    • Decision Table: If this rule type is selected a decision table will be used to capture your business rule logic. This rule type should be selected if every rule uses the same decision criteria. This enables all the common decision criteria to be captured at once. 
  3. Once the rule is uploaded click Next. The Facts Upload window appears to upload facts and results that are used in the rule script. It should be a valid jar file

...

  1. . Multiple jar files can be uploaded. For example, create a jar file from the facts and results defined

...

  1. in Sample Rule Definition.
    Image Modified

...

  1.  
  2. The Operations Summary window appears, displaying any operations available in the service. You can also use

...

  1. the Add New Operation

...

  1.  link to create a new operation.
    Image Modified 

...

  1. The Add Operation

...

  1.  window appears. Fill in the fields appropriately.

...

  1.  

    Image Modified

    • Name: Operation name which is mandatory.
    • Input and output facts: You can use fact "selector" to select a type, which you have already uploaded in the input fact upload step. In this example, one fact is added with the type

...

    • as samples.userguide.PlaceOrder

...

    •  and two outputs with types

...

    • as samples.userguide.OrderReject

...

    •  and samples.userguide.OrderAccept

...

    • . Note

...

    • that Type

...

    •  is the only mandatory attribute in both input and output facts.

...

  1. Click the Add button once done. This will bring you to the

...

  1. previous Operations Summary

...

  1.  window.

...

  1. Click Finish

...

  1.  to create and deploy the rule service.