This documentation is for WSO2 Application Server version 5.0.0. View documentation for the latest release.

Skip to end of metadata
Go to start of metadata

Introducing the Sample

The sample shows some advanced functionalities of REST-based Web Services using JAX-RS (JSR-311). The REST server provides the following services:   

       "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.

This sample can be found at <CARBON_HOME>\samples\Jaxws-Jaxrs\jaxrs_sample_02. 

Building and Running the Sample  

Using Maven

1. Install and run the WSO2 Application Server. Refer to the  Installation Guide for instructions.

2. From the base directory of this sample (<CARBON_HOME>\samples\Jaxws-Jaxrs\jaxrs_sample_02), the maven pom.xml file can be used to build and run the sample using either UNIX or Windows.

3. To build the sample and create a WAR file, run mvn clean install command.

4. Start the Application Server (run bin/

  • mvn -Pdeploy (deploys the generated WAR file on WSO2 AS with related logs on the console)
  • mvn -Pclient (runs the client)

Using Apache Ant 

 1. Run "ant" on <CARBON_HOME>\samples\Jaxws-Jaxrs\jaxrs_sample_02 directory to deploy the jaxrs_sample_02 service on the server.

2. Start the application server and access its Management Console at https://localhost:9443/carbon.

3. Go to "Services -> List" menu to find the jaxrs_sample_02 service listed on the "Deployed Services" window.

4. Execute "sh" or "run-client.bat" to run the client.

5. Try the sample with different QoS options which appear on its dashboard. Run "sh -help" for different options.

  • No labels