Skip to end of metadata
Go to start of metadata

This sample shows some advanced functionalities of REST-based Web Services using JAX-RS (JSR-311). Please note that this sample was called jaxrs_sample_02 in the AS 5.1.0 release. It has been renamed to provide better clarity.

Building the sample 

  1. Open a command line, and navigate to the <AS_HOME>\samples\Jaxws-Jaxrs\jaxrs_starbucks_service directory.
  2. Run the relevant command to deploy the web app:
    • Using Maven

      1. Create a WAR file for the sample using the following command:

        mvn clean install
      2. Deploy the generated WAR file on WSO2 AS with the related logs on the console:

        mvn -Pdeploy
    • Using Ant

  3. Start  the WSO2 Application Server by executing one of the following commands, where <PRODUCT_HOME> is the directory where you installed the product distribution:

    On Windows
    <PRODUCT_HOME>\bin\wso2server.bat --run
    On Linux/Solaris
    sh <PRODUCT_HOME>/bin/wso2server.sh  
  4. Log in to the management console and click List on the Main menu, under Manage/Applications. This opens the Running Applications page. The deployed applications will be listed here.

  5. You can open the required web application by clicking the Find Services action.

Running the sample

This JAX-RS webapp provides following services:    

  • A RESTful Starbucks outlet service is provided on URL http://localhost:9763/jaxrs_starbucks_service/services/Starbucks_Outlet_Service (say serviceURL). Users access this URI to perform operations of drink orders.      
  • A HTTP GET request to URL ${serviceURL}/orders/123 returns a drink order added with the generated id 123. The JSON document returns: 

           "drinkName":"Vanilla Flavored Coffee",
  • A HTTP POST request to URL ${serviceURL}/orders  with the following data adds an order. 

       <drinkName>Mocha Flavored Coffee</drinkName>
  • An id for this order is generated at server-side and returned in the response.   The response body looks like the following in JSON format. 

       "drinkName":"Mocha Flavored Coffee",
  • A HTTP PUT request to URL ${serviceURL}/orders with the following data, where the 'orderId' is set to the one received in the response body when the order was added: 

           "additions":"Chocolate Chip Cookies"
  • It updates the 'additions' of the order "ee1a9ec2-c8a5-4afe-8585-74df591f9990" from "Caramel" to "Chocolate Chip Cookies". The response will be in XML-format as follows.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
          <additions>Chocolate Chip Cookies</additions>
          <drinkName>Full Leaf Green Tea</drinkName>
  • A HTTP DELETE request to URL ${serviceURL}/orders/ee1a9ec2-c8a5-4afe-8585-74df591f9990 with an empty request body will delete the order details of order "ee1a9ec2-c8a5-4afe-8585-74df591f9990".

The client code demonstrates how to send HTTP GET/POST/PUT/DELETE requests whereas the server code demonstrates how to build a RESTful endpoint through JAX-RS (JSR-311) APIs.

  • No labels