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. Issue a request similar to the following in the Try the Shoppingservice window .
    Adding to add a product.

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

    Doing
    Image Added
    You would get the following result:
     

  6. Issue another request similar to the following to make a purchase:

    Code Block
    languagehtml/xml
    <customer>your name </customer>
    <product>product name</product>

     

    You would get the following result:

     

  7. Alternatively, you can use Generate 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.

...