This documentation is for WSO2 Business Rules Server 2.0.0.View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

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

Rule Service Upload

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

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

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

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


        <rule resourceType="regular" sourceType="file">orderApprovalRules.drl</rule>
    <operation name="placeOrder">
        <input wrapperElementName="placeOrder" namespace="http://com.test/placeorder">
            <fact elementName="order" namespace="http://com.test/placeorder" type="samples.userguide.PlaceOrder"></fact>
        <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>


4. 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.
5. Make an Axis2 archive file (OrderApprovalService.aar in this example) from the above content.


6. Log in to the WSO2 BRS management console and select "Rule Service -> Upload" in the "Main" menu.

7. The "Upload Rule Service" window opens. Upload the file created in step 4 and click "Upload". For example,

8. The "Deployed Services" 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 the "Client Operations" panel in the service dashboard.

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


<symbol>Company A</symbol>


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


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


11. 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".

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[] placeOrders = new PlaceOrder[1];
            placeOrders[0] = placeOrder;

            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();

        } catch (Exception e) {

Rule Service Wizard

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

1. Log in to the WSO2 BRS management console and select "Rule Service -> Create" in the "Main" menu.

2. The "Service Information" window opens. Enter the required information and click "Next". The service name has to be unique. For example,

3. The "Rule Set Information" window appears. There are four ways to specify a rule set or a rule script.

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

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

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

  • URL: Upload from a url

4. 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 and multiple jar files can be uploaded. For example, create a jar file from the facts and results defined in Sample Rule Definition.

5. The "Operation Summary" window appears, displaying any operations available in the service. You can also use the "Add New Operation" link to create a new operation.

6. The "Add Operation" window appears. Fill in the fields appropriately. For example,

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

7. Click the "Add" button once done. This will bring you to the previous "Operations Summary" window. Click "Finish" to create and deploy the rule service.

  • No labels