This sample demonstrates how to use the BRS for a simple greetings service.
To run this sample:
- Windows, Linux or Solaris operating system should exist.
- WSO2 BRS should be installed. To install the BRS, refer Installing the Product. This also includes installing Apache Ant as one of the Installation Prerequisites.
- WSO2 BRS should be started as described in Running the Product.
Sample Rule Definition
Rule 1 : If the time is between 12 and 18, say good afternoon.
Rule 2 : If the time is between 6 and 12, say good morning.
Rule 3 : If the time is between 18 and 24, say good night.
There is a fact named
A user logged in into the system.
GreetingMessage is used to capture the result of the rule execution.
Rule Service Configuration (service.rsl)
An in-line rule set is used within the service.rsl file as follows.
Executing the Sample
To execute the sample, run the
ant command from the
<BRS_Home>/samples/greeting.service directory to run the Greetings Service.
Before executing this sample, it is recommended that you refer Exposing Rules as Services which explains in detail the process of writing and deploying a business rule.
Deploying and Testing the Sample
- 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.
- After deployment, click on List under Services in the main tab of the management console. The service will appear in the Deployed Services page.
- Click Greeting Service to access the dashboard of the service.
- Click Try this service in the Client Operations widget of the dashboard to invoke the Try-it tool.
Issue a request similar to the following in the Try the GreetingService service window.
You would get the following response:
Alternatively, you can click Generate Client 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 databinding classes check box checked.