Versions Compared

Key

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

...

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 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 Shopping Service 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. Click addProduct in the left pane of the Try-it tool and issue a request similar to the following in the Try-it tool to add a product:

    Code Block
    languagehtml/xml
    <name>product name</name>
    <price>12.34</price>


    You would get the following result:
     

    Code Block
    languagexml
    <axis2ns11:addProductResponse xmlns:axis2ns11="http://com.test/shopping"/>


  6. Click purchase in the left pane of the Try-it Tool and issue another request similar to the following to make a purchase:

    Code Block
    languagehtml/xml
    <customer>Tester</customer>
    <product>Test Product</product>

     

    The following would be logged in the terminal:

    Code Block
     New Customer : Tester
    
    Customer Tester just purchased Test Product

    Repeat this step ten times. You would get the following result in the Try-it tool:

    Code Block
    languagexml
     <discount>10</discount>
     <name>Tester</name>
  7. 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
    languagejava
    package org.wso2.carbon.samples;
    
    import org.apache.axis2.AxisFault;
    import org.wso2.carbon.samples.shoppingService.product.AddProduct;
    import org.wso2.carbon.samples.shoppingService.product.Product;
    import org.wso2.carbon.samples.shoppingService.purchaseOrder.Discount;
    import org.wso2.carbon.samples.shoppingService.purchaseOrder.Purchase;
    import org.wso2.carbon.samples.shoppingService.purchaseOrder.PurchaseOrder;
    import org.wso2.carbon.samples.shoppingService.stub.ShoppingServiceStub;
    import java.rmi.RemoteException;
    
    public class ShoppingServiceTestCase {
    
        public static void main(String[] args) {
    
            ShoppingServiceStub shoppingServiceStub = null;
            try {
                shoppingServiceStub = new ShoppingServiceStub("http://localhost:9763/services/ShoppingService");
                shoppingServiceStub._getServiceClient().getOptions().setManageSession(true);
    
                AddProduct addProduct = new AddProduct();
                Product product = new Product();
                product.setName("toy");
                product.setPrice(200);
                Product[] products = new Product[1];
                products[0] = product;
    
                shoppingServiceStub.addProduct(products);
    
                PurchaseOrder purchaseOrder = new PurchaseOrder();
                Purchase purchase = new Purchase();
                purchase.setCustomer("Ishara");
                purchase.setProduct("toy");
    
                Purchase[] purchases = new Purchase[1];
                purchases[0] = purchase;
    
                purchaseOrder.setPurchase(purchases);
                Discount[] discounts = shoppingServiceStub.purchase(purchases);
                int result = discounts[0].getAmount();
                System.out.println(result);
    
            } catch (AxisFault axisFault) {
                axisFault.printStackTrace();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    }
    Excerpt
    hiddentrue

    Shopping service sample of the WSO2 Business Rules Server samples guide.

...