Versions Compared

Key

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

...

  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.
     

    Code Block
    languagexml
    <price>10</price>
    <quantity>9</quantity>
    <symbol>IBM</symbol> 


    You would get the following response:

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

    Code Block
    languagexml
    <price>120</price>
    <quantity>100</quantity>
    <symbol>SUN</symbol> 

    You would get the following response

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

    Code Block
    languagexml
    <price>50</price>
    <quantity>160</quantity>
    <symbol>MSFT</symbol> 


    You would get the following result: 

    Code Block
    languagexml
      <orderReject>
          <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>
       </orderReject>
  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. 

    Code Block
    languagexmljava
    package testorg.wso2.comcarbon.orderapprovalsamples;
    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  OrderApprovalServiceStub java implementationmain(String[] args) {
    
            */try {
                OrderApprovalServiceStub orderApprovalServiceStub =  public class OrderApprovalServiceStub extends org.apache.axis2.client.Stubnew OrderApprovalServiceStub("http://localhost:9763/services/OrderApprovalService");
              {  PlaceOrderE placeOrderE =     protected org.apache.axis2.description.AxisOperation[] _operationsnew PlaceOrderE();
            //hashmaps to keep the fault mapping
            private java.util.HashMap faultExceptionNameMap PlaceOrder placeOrder = new java.util.HashMapPlaceOrder();
            private java.util.HashMap faultExceptionClassNameMap = new javaplaceOrder.util.HashMap(setSymbol("Company A");
            private java.util.HashMap faultMessageMap = new javaplaceOrder.util.HashMapsetPrice(150);
            private static int counter = 0 placeOrder.setQuantity(128);
            private static synchronized java.lang.String getUniqueSuffix(){
        PlaceOrder[] placeOrders = new PlaceOrder[1];
            // reset the counter if it is greater than 99999placeOrders[0] = placeOrder;
                  if (counter > 99999){placeOrderE.setOrder(placeOrders);
    
                PlaceOrderRespone placeOrderRespone  counter = 0null; //new PlaceOrderRespone();
              }  try {
             counter = counter + 1;   placeOrderRespone           return java.lang.Long.toString(java.lang.System.currentTimeMillis()) + "_" + counter;= orderApprovalServiceStub.placeOrder(placeOrders);
                } catch    
        private void populateAxisService() throws org.apache.axis2.AxisFault (RemoteException e) {
         //creating the Service with a unique name      _service = new org.apache.axis2.description.AxisService("OrderApprovalService" + getUniqueSuffix()e.printStackTrace();  //To change body of catch addAnonymousOperations();statement use File | Settings | File Templates.
     //creating the operations         org.apache.axis2.description.AxisOperation __operation;}
             _operations = new org.apache.axis2.description.AxisOperation[1];
       OrderAccept[] orderAccepts = placeOrderRespone.getOrderAccept();
                String result = orderAccepts[0].getMessage();
             __operation = new orgSystem.apache.axis2.description.OutInAxisOperation(out.println(result);
    
    
    
            } catch (Exception e) {
                 __operation.setName(new javax.xml.namespace.QName("http://com.test/orderApproval", "placeOrder"));
    	    _service.addOperation(__operation);
    
    e.printStackTrace();
            }
        }
    }