Versions Compared

Key

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

...

Deploying and Testing the Sample

  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 Insurance 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-it tool.
     
    The Car:

    Code Block
    languagehtml/xml
    <color>red</color>
    <style>sport</style>

    The Driver:

    Code Block
    languagehtml/xml
    <age>20</age>
    <name>your name</name>
    <male>true</male>


    You would get the following result:

    Code Block
    languagexml
    <premium>120000.0</premium>
  6. 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.insuranceService.insurance.ApplyForInsurance;
    import org.wso2.carbon.samples.insuranceService.insurance.Car;
    import org.wso2.carbon.samples.insuranceService.insurance.Driver;
    import org.wso2.carbon.samples.insuranceService.insurance.Policy;
    import org.wso2.carbon.samples.insuranceService.stub.InsuranceServiceStub;
    import java.rmi.RemoteException;
    
    public class InsuranceServiceTestCase {
    
        public static void main(String[] args) {
    
            try {
                InsuranceServiceStub insuranceServiceStub =
                        new InsuranceServiceStub("http://localhost:9763/services/InsuranceService");
                ApplyForInsurance applyForInsurance = new ApplyForInsurance();
    
                Car car = new Car();
                car.setColor("red");
                car.setStyle("sport");
                Car[] cars = new Car[1];
                cars[0] = car;
    
                Driver driver = new Driver();
                driver.setName("your name");
                driver.setAge(24);
                driver.setMale(true);
                Driver[] drivers = new Driver[1];
                drivers[0] = driver;
    
                applyForInsurance.setCarInsurance(cars);
                applyForInsurance.setDriverInsurance(drivers);
    
                Policy[] policies = insuranceServiceStub.applyForInsurance(cars, drivers);
                double result = policies[0].getPremium();
                System.out.println(result);
            } catch (AxisFault axisFault) {
                axisFault.printStackTrace();
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
    }
    Excerpt
    hiddentrue

    Car insurance service sample of the WSO2 Business Rules Server samples guide.

...