Versions Compared

Key

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

...

Rule Service Configuration (service.rsl)

 

Code Block
languagehtml/xml
<ruleService
        name="GetQuoteService"
        xmlns="http://wso2.org/carbon/rules"
        targetNamespace="http://com.test/quotation">
    <ruleSet>
        <rule resourceType="regular" sourceType="inline">
            <![CDATA[
                package quotation

                import samples.quotation.Customer;
                import samples.quotation.Quotation;

                rule "Gold Customer"
                when
                      Customer( status == "gold" )
                then
                      Quotation q = new Quotation();
                      q.setPrice(3);
                      insertLogical(q);
                end

                rule "Silver Customer"
                when
                      Customer( status == "silver" )
                then
                      Quotation q = new Quotation();
                      q.setPrice(4);
                      insertLogical(q);
                end

                rule "Bronze Customer"
                when
                      Customer( status == "bronze" )
                then
                      Quotation q = new Quotation();
                      q.setPrice(5);
                      insertLogical(q);
                end
            ]]>
        </rule>
    </ruleSet>
    <operation name="getQuote">
        <input wrapperElementName="placeCustomerDetail" namespace="http://com.test/placeCustomerDetail">
            <fact elementName="customerDetail" namespace="http://com.test/placeCustomerDetail" type="samples.quotation.Customer"></fact>
        </input>
        <output wrapperElementName="placeCustomerDetailRespone" namespace="http://com.test/placeCustomerDetail">
            <fact elementName="getQuotation" namespace="http://com.test/placeCustomerDetail" type="samples.quotation.Quotation"></fact>
        </output>
    </operation>
</ruleService>

 

Executing the sample

To execute the sample, run the ant command from the  <BRS_Home>/samples/quotation.service directory to run the GetQuote Service.

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 Exposing Rules as Services.

2. After deployment, the service will appear in the Deployed Services window of the BRS management console. Access the service's dashboard by clicking on it.

3. In the Client Operations widget of the dashboard, invoke the Try-it tool to test the service.

4. In the service's Try-it window, issue a request similar to the following.

...