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

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »


This sample demonstrates an order approval process which uses business rules to check whether the required conditions for approving an order are met.


To run this sample:

Sample configuration

Sample rule definition


Rule 1 : An order for stocks of Company IBM is accepted only if the number of stocks is higher than 10.
Rule 2 : An order for stocks of Company SUN is accepted only if the stock price is higher than 100 $.
Rule 3 : An order for stocks of Company MSFT is accepted only if the stock price is higher than 50 $ and the number of stocks is lower than 200.


There is one fact named Order. OrderAccept and OrderReject are used to capture the result of the service.

Rule service configuration (service.rsl) 

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

Executing the service

To execute the service, run the ant command from the  <PRODUCT_HOME>/samples/quotation.service directory to run the OrderApproval Service.

Before executing this service, it is recommended that you refer Exposing Rules as Services Exposing Rules as Services which explains in detail the process of writing and deploying a business rule.

Deploying and testing the service

  1. Deploy the rule service through the BRS management console. You can follow either of the two methods:

    • Bundle all artifacts in an .aar file and upload it (Rule Service -> Upload menu).
    • Create using the Rule Service wizard UI (Rule Service -> Create menu).

    The above steps are discussed in detail in section  Exposing Rules as Services.
  2. After deployment, click on List under Services in the main tab of the management console. The service will appear in the Deployed Services page.
  3. Click OrderApproval to access the dashboard of the service.
  4. Click Try this service in the Client Operations widget of the dashboard to invoke the Try-it tool.
  5. Issue a request similar to the following in the Try-it tool.


    You would get the following response:

          <reason>An Order for stocks of IBM is accepted only if the number of stocks is higher than 10.</reason>
  6. Enter another request as follows:


    You would get the following response

          <message>Accepted order for: 100 stocks of SUN at$ 120.0</message>
  7. Enter another request as follows:


    You would get the following result: 

          <reason>An Order for stocks of MSFT is accepted only if the stock price is higher than 50 $ and the number of stocks is lower than 200.</reason>
  8. Alternatively, you can use Generate Axis2 Client link in the  Client Operations widget of the dashboard to invoke the service. A client using generated stub codes is shown below where the codes were generated with the Unpacks the data binding classes check box checked. 

            *  OrderApprovalServiceStub java implementation
            public class OrderApprovalServiceStub extends org.apache.axis2.client.Stub
            protected org.apache.axis2.description.AxisOperation[] _operations;
            //hashmaps to keep the fault mapping
            private java.util.HashMap faultExceptionNameMap = new java.util.HashMap();
            private java.util.HashMap faultExceptionClassNameMap = new java.util.HashMap();
            private java.util.HashMap faultMessageMap = new java.util.HashMap();
            private static int counter = 0;
            private static synchronized java.lang.String getUniqueSuffix(){
                // reset the counter if it is greater than 99999
                if (counter > 99999){
                    counter = 0;
                counter = counter + 1; 
                return java.lang.Long.toString(java.lang.System.currentTimeMillis()) + "_" + counter;
        private void populateAxisService() throws org.apache.axis2.AxisFault {
         //creating the Service with a unique name
         _service = new org.apache.axis2.description.AxisService("OrderApprovalService" + getUniqueSuffix());
            //creating the operations
            org.apache.axis2.description.AxisOperation __operation;
            _operations = new org.apache.axis2.description.AxisOperation[1];
                       __operation = new org.apache.axis2.description.OutInAxisOperation();
                __operation.setName(new javax.xml.namespace.QName("http://com.test/orderApproval", "placeOrder"));
  • No labels