JBoss.orgCommunity Documentation

Chapter 4. Web Service Test View

4.1. Preliminaries
4.2. Testing a RESTful Web Service
4.2.1. RestfulSample project
4.2.2. RESTEasy sample project

JBoss Tools provides a view to test web services. The Web Services Test View can be displayed by following the steps in Web Services Test View.

Procedure 4.1. Web Services Test View

The following sections describe testing JAX-RS web services, including the necessary preliminary steps.

The following procedure describes the steps to perform before testing a web service.

Procedure 4.2. Testing a web service

Testing a RESTful ( JAX-RS ) web service is achieved by following a similar procedure to testing a JAX-WS web service. Instead of selecting the JAX-WS option in the combobox, the JAX-RS service is invoked by sending HTTP method requests of the form OPTIONS, GET, POST, PUT and DELETE. As there is no WSDL file associated with a JAX-RS service, the available options can be determined by selecting OPTIONS in the combobox.

A JAX-RS web service can be tested by using the Web Service Tester View displayed in Figure 4.1, “Web Service Test View”. The JAX-RS test is specified by:

  1. Selecting the OPTIONS combobox option.

  2. Entering the url of the JAX-RS web service.

The test procedure is discussed in the following sections for both the RestfulSample and the RESTEasy sample projects developed earlier.

Procedure 4.3. RestfulSample test

    1. Query the available options

      Select OPTIONS from the available combobox options.

    2. Enter the url of the web service in the editable drop-down list: http://localhost:8080/RestfulSample/MyRESTApplication.

    3. Click the Invoke button

      Result:

      The Response Headers text area indicates that the allowed options are [GET, OPTIONS, HEAD] as shown in Figure 4.3, “JAX-RS Response Header Text”.

      Figure 4.3. JAX-RS Response Header Text


  1. Test the GET request

    1. Having established that the GET request is valid, select GET from the available combobox options.

    2. Click the Invoke button.

      Result:

      The Response Body text area displays the expected “Hello World” text as shown in Figure 4.4, “JAX-RS Response Body Text”.

      Figure 4.4. JAX-RS Response Body Text


Procedure 4.4. Testing a JAX-RS web service- POST and GET requests

    1. Query the available options

      Following the preliminary steps described in Testing a web service, select the OPTIONS method from the operations text area.

    2. Enter the url of the web service in the editable drop-down list http://localhost:8080/simple/rest-services/customers.

    3. Click the Invoke button

      Result:

      The Response Headers text area indicates that the allowed options are [POST, OPTIONS] as shown in Figure 4.5, “JAX-RS RESTEasy project Body Text”.

      Figure 4.5. JAX-RS RESTEasy project Body Text


  1. Test the POST option

    1. Select POST method in the the operations drop-down list.

    2. We will post xml data to this particular web service. Complete the header details by entering content-type=application/xml in the text area and click Add to add it to the Headers list.

      Result:

      The content-type is added to the Headers list as shown in Figure 4.6, “content-type header”.

      Figure 4.6. content-type header


    3. Enter customer details

      Enter the customer details in the Body Text area as displayed in Figure 4.7, “Customer data”.

      Figure 4.7. Customer data


    4. Click the Invoke button.

      Result:

      The Response Headers area indicated that a record was created and lists the location as http://localhost:8080/simple/rest-services/customers/1 as shown in Figure 4.8, “Customer added”.

      Figure 4.8. Customer added


      The console also indicates the successful creation of the customer: 10:44:33,846 INFO [STDOUT] Created customer 1

  2. Test the GET option

    1. Select the GET method in the the operations drop-down list.

    2. We will retrieve the record created in the previous step. Enter the url for the record returned in the previous step http://localhost:8080/simple/rest-services/customers/1

    3. Click the Invoke button.

      Result:

      The Response Headers area indicates a [HTTP/1.1 200 OK] response and the customer data is retrieved and displayed in the Response Body area as shown in Figure 4.9, “GET response”.

      Figure 4.9. GET response


  3. Test the PUT option

    1. Editing a record is achieved by using the PUT method. Select the PUT method in the operations drop-down list.

    2. Enter the url of the record to be edited http://localhost:8080/simple/rest-services/customers/1

    3. Enter the data in the Body Text area. Replace the first-name with a different entry as in Figure 4.10, “Updated customer data”

      Figure 4.10. Updated customer data


    4. Ensure that the content-type=application/xml header is in the Headers list.

    5. Click the Invoke button.

      Result:

      The Response Headers area indicates a No Response ([HTTP/1.1 204 No Content]) Figure 4.11, “Response header following PUT”.

      Figure 4.11. Response header following PUT


      In this instance, the console does not indicate an update was performed, however, the console may provide useful information following an operation.

  4. Check the updated data with a GET

    Perform a GET operation by following the steps in Step 3.

    Result:

    The Response Body area displays the updated data.

    Figure 4.12. Customer data updated


  5. Test the DELETE option

    1. Deleting a record is a similar process to posting. Select the DELETE method in the operations drop-down list.

    2. Enter the url of the record to be deleted http://localhost:8080/simple/rest-services/customers/1

    3. Click the Invoke button.

      Result:

      The Response Headers area indicates a No Response ([HTTP/1.1 204 No Content]) as was the case for the PUT operation in Figure 4.11, “Response header following PUT”.

      Once again, the console does not indicate an update was performed, however, the console may provide useful information following an operation.

  6. Check the DELETE operation with a GET

    Perform a GET operation by following the steps in Step 3.

    Result:

    The Response Body area returns an error report indicating that The requested resource () is not available and the Response Headers area returns a [HTTP/1.1 404 Not Found].

    Figure 4.13. Customer data deleted


    The response header and body messages indicate that the data was successfully deleted.