Introducing the Sample
This sample demonstrates a basic REST-based Web Services using JAX-RS (JSR-311). The REST server provides the following services:
- A RESTful customer service is provided on URL http://localhost:9763/jaxrs_basic/services/customers/customerservice (say serviceURL). Users access this URI to operate on customer.
- A HTTP GET request to URL ${serviceURL}/customers/123 returns a customer instance whose id is 123. The XML document returns the following:
<Customer> <id>123</id> <name>John</name> </Customer>
- A HTTP GET request to URL ${serviceURL}/orders/223/products/323 returns product 323 that belongs to order 223. The XML document returns the following:
<Product> <description>product 323</description> <id>323</id> </Product>
- A HTTP POST request to URL ${serviceURL}/customers with the following data adds a customer whose name is Jack.
<Customer> <name>Jack</name> </Customer>
- A HTTP PUT request to URL ${serviceURL}/customers with following data updates the customer instance whose id is 123.
<Customer> <id>123</id> <name>John</name> </Customer>
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_basic.
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_basic), 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/wso2server.sh/.bat).
- 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 <AS_HOME>\samples\Jaxws-Jaxrs\jaxrs_basic directory to deploy the jaxrs_basic 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_basic service listed on the "Deployed Services" window.
4. Execute "sh run-client.sh" or "run-client.bat" to run the client.
5. Try the sample with different QoS options which appear on its dashboard. Run "sh run-client.sh -help" for different options.