...
Code Block | ||
---|---|---|
| ||
<ruleService name="GreetingService" xmlns="http://wso2.org/carbon/rules" targetNamespace="http://com.test/greeting"> <ruleSet> <rule resourceType="regular" sourceType="inline"> <![CDATA[ package greeting import samples.greeting.GreetingMessage; import samples.greeting.User; rule "Is Morning" no-loop true when user : User() eval((6 < user.now()) && (user.now()< 12)) then GreetingMessage msg = new GreetingMessage(); msg.setMessage("Good Morning " + user.getName() + " !!! "); insertLogical(msg); end rule "Is afternoon" no-loop true when user : User() eval((12 <= user.now()) && (user.now() < 18)) then GreetingMessage msg = new GreetingMessage(); msg.setMessage("Good Afternoon " + user.getName() + " !!! "); insertLogical(msg); end rule "Is Night" no-loop true when user : User() eval( (18 <= user.now()) && (user.now() < 24)) then GreetingMessage msg = new GreetingMessage(); msg.setMessage("Good Night " + user.getName() + " !!! "); insertLogical(msg); end ]]> </rule> </ruleSet> <operation name="greetMe"> <input wrapperElementName="user" namespace="http://com.test/greeting"> <fact elementName="user" namespace="http://com.test/greeting" type="samples.greeting.User"></fact> </input> <output wrapperElementName="greetingMessage" namespace="http://com.test/greeting"> <fact elementName="greetingMessage" namespace="http://com.test/greeting" type="samples.greeting.GreetingMessage"></fact> </output> </operation> </ruleService> |
Executing the
...
Service
To execute the sampleservice, run the ant
command from the <PRODUCT_HOME>/samples/greeting.service
directory to run the Greetings Service.
Info |
---|
Before executing this sampleservice, 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
...
Service
- 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-it tool:
Code Block language html/xml <name>your name</name>
You would get the following response:Code Block language html/xml <message>Good Early Morning Test Name !!! </message>
Alternatively, you can click Generate Axis 2 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.
Code Block language java package org.wso2.carbon.samples; import java.lang.String; import org.wso2.carbon.samples.greetingService.greeting.*; import org.apache.axis2.AxisFault; import java.rmi.RemoteException; public class GreetingServiceTestCase { public static void main(String[] args) { try { GreetingServiceStub greetingServiceStub = new GreetingServiceStub("http://localhost:9763/services/GreetingService"); UserE userRequest = new UserE(); User user = new User(); user.setName("your name"); User[] users = new User[1]; users[0] = user; userRequest.setUser(users); GreetingMessage[] greetingMessages = greetingServiceStub.greetMe(users); String result = greetingMessages[0].getMessage(); System.out.println(result); } catch (AxisFault axisFault) { axisFault.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } } }
...