SimpleWsldRestServiceDemo

Simple WSDL-based REST Service Demo

Prerequisites:

NB 6.0 > Milestone 10 + Sun App Server b.49 + SWDP R2 installer.

Preparation Steps:

  • Create new Web Application targeting Sun AS.
  • Right click on project node and do 'New > Entity Classes from Database...' and generate a set of entity classes from jdbc/sample database connection. (Note: might hit bug JPA, so work-around by start from a pre-existing sample database entity classes). Make sure you also have a Persistence Unit for the project, if not create one using 'New > Other... > Persistence > Persistence Unit'.
  • Right click on the entity classes package, do 'New > REST Web Services from Entity Classes...', select all and accept all default.

Test Sub-resource Generated Code:

  • Open under server package java class CustomerResource.
  • Drag 'Tax Complete 40' from component palette section 'StrikeIron' on to CustomerResource.java.
  • The code generator will dynamically pull down the WSDL defining 'TaxDataComplete' operation and create a WSDL Client for it before generate REST wrapper service class and sub resource method. This could take a while if the service client is generated for the first time for the project.
  • When the code generation is done, the cursor is put on the method getTaxDataComplete of CustomerResource:

    @UriTemplate(value = "taxDataComplete/")
    public tata.service.TaxDataCompleteResource getTaxDataComplete(
            @UriParam(value = "customerId") Integer id, 
            @QueryParam(value = "userID") String userID, 
            @QueryParam(value = "password") String password) 
    {
        return new TaxDataCompleteResource(
            getEntity(id).getEmail(), userID, password, getEntity(id).getZip());
    }

  • The USAddressVerificationResource.java is generated in the same package as CustomerResource, with the following constructor:

    public TaxDataCompleteResource(
            String unregisteredUserEmail, String userID, String password, 
            String zipCode) 
    {
        this.unregisteredUserEmail = unregisteredUserEmail;
        this.userID = userID;
        this.password = password;
        this.zipCode = zipCode;
    }


  • Delete userID and password from sub-resource method parameters and "getEntity(id).getEmail(), userID, password," from the TaxDataCompleteResource constructor invocation. The resulting code should look like this:

    @UriTemplate("taxDataComplete/")
    public tata.service.TaxDataCompleteResource getTaxDataComplete(
            @UriParam("customerId") Integer id) 
    {
        return new TaxDataCompleteResource(
            getEntity(id).getZip());
    }


  • Delete parameters 'unregisteredUserEmail', 'userID', 'password' from the TaxDataCompleteResource constructor. Initialize userID and password with proper values. The resulting code should looks like this:

    public TaxDataCompleteResource(String zipCode) {
        this.userID = "USER";
        this.password = "PASSWORD";
        this.zipCode = zipCode;
    }

  • Right click on web project node and do 'Test REST Services'.
  • In the test client navigate to one of the customer, you will see a sub-resource link called 'taxDataComplete/'. Click on this sub-resource link and do GET button, will invoke the tax data service on the address of the customer resource.
  • The result will be display in XML format in the output Raw view.

Test Directly on Wrapper REST Service:

  • Click on Test Client left panel link '/getUSATaxRatesByZipCode'
  • Fill out the query form, skip unnecessary fields by making sure they are blank.
  • Hit Test button; the tax data for the entered zip code.
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo