Java Reference
In-Depth Information
public Product(String id) {
System.out.println("Creating product: " + id);
this.id = id;
this.name = "";
this.qty = 1;
}
//setters and getters left out...
@Override
public String toString() {
return "ID=" + id;
}
}
The Product class doesn't contain any JAX-RS-specific code. It's just a regular class that
might wrap a row in a database, and it follows the JavaBeans conventions.
The REST resource is shown in Example 8-34 . It has both GET and POST methods for the
list of products.
Example8-34.The OrderResource.java class
package com.soacoobook.rest.order;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.Path;
/**
* Collects the products that an inventory manager wants
* to order from a vendor.
*/
@Path("order")
public class OrderResource {
//holds products user adds to order
private List<Product> products = new ArrayList<Product>();
//constructor
public OrderResource() {
System.out.println("Constructing OrderResource");
}
Search WWH ::




Custom Search