...
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 user case in Sample Rule Definition.
...
- Create the Drools file that defines the rules for the sample use case. Note that the file must be in .drl format, not .dsrl.
...
Create a rule service configuration using the instructions
...
in File-Based Configuration. The configuration file which is named as service.rsl (Rule Service Language) and which is used for the sample is shown below.
Code Block language html/xml title service.rsl <ruleService name="OrderApprovalService" xmlns="http://wso2.org/carbon/rules" targetNamespace="http://com.test/orderApproval"> <ruleSet> <rule resourceType="regular" sourceType="file">orderApprovalRules.drl</rule> </ruleSet> <operation name="placeOrder"> <input wrapperElementName="placeOrder" namespace="http://com.test/placeorder"> <fact elementName="order" namespace="http://com.test/placeorder" type="samples.userguide.PlaceOrder"></fact> </input> <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> </output> </operation> </ruleService>
...
- 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.
...
Make an Axis2 archive file (OrderApprovalService.aar in this example) from the above content.
Info title Infor - To learn how to create an Axis2 service using WSO2 Carbon Studio, refer to: http://markmail.org/download.xqy?id=tsctqe7x5rnwexls&number=1
- To learn how to create an Axis2 service using Eclipse, refer to: http://wso2.org/library/tutorials/create-axis2-web-service-in-3-steps-using-eclipse
...
- Log in to the WSO2 BRS management console and
...
- click Upload
...
- under Rules
...
- Service in the main page.
...
- The Upload Rule Service
...
- window opens. Upload the file created in step 4 and
...
- click Upload as shown below.
...
- 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.
...
The Try-It tool can be used to test the sample through a request similar to the one shown
...
below.
...
Code Block <symbol>Company A</symbol> <quantity>223</quantity> <price>14</price>
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.
...
Code Block language html/xml <brs:placeOrderResponse> <brs:result> <brs:OrderAccept xsi:type="ax2277:OrderAccept"> <ax2275:message>Accepted order for: 223 stocks of Company A at$ 14.0</ax2275:message> </brs:OrderAccept> </brs:result> </brs:placeOrderResponse>
The WSDL of the service can also 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.
Code Block language java 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.setPrice(150); placeOrder.setQuantity(128); PlaceOrder[] placeOrders = new PlaceOrder[1]; placeOrders[0] = placeOrder; placeOrderE.setOrder(placeOrders); 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(); System.out.println(result); } catch (Exception e) { e.printStackTrace(); } } }
Rule Service Wizard
Anchor | ||||
---|---|---|---|---|
|
...