Java Reference
In-Depth Information
1. Open a command prompt or shell terminal and change to the ex10_1 directory of the
workbook example code.
2. Make sure your PATH is set up to include both the JDK and Maven, as described in
Chapter 17 .
3. Perform the build and run the example by typing maven install .
Example ex10_2: Link Headers
There are two educational goals I want to get across with this example. The first is the use of
Link headers within a RESTful application. The second is that if your services provide the
appropriate links, you only need one published URL to navigate through your system. When
you look at the client code for this example, you'll see that only one URL is hardcoded to
start the whole process of the example.
To illustrate these techniques, a few more additional JAX-RS services were built beyond the
simple customer database example that has been repeated so many times throughout this
book. Chapter 2 discussed the design of an ecommerce application. This chapter starts the
process of implementing this application by introducing an order-entry RESTful service.
The Server Code
The Order and LineItem classes are added to the JAXB domain model. They are used to
marshal the XML that represents order entries in the system. They are not that interesting, so
I'm not going to get into much detail here.
OrderResource
The OrderResource class is used to create, post, and cancel orders in our ecommerce sys-
tem. The purge operation is also available to destroy any leftover order entries that have been
cancelled but not removed from the order entry database. Let's look:
src/main/java/com/restfully/shop/services/OrderResource.java
@Path ( "/orders" )
public
public class
class OrderResource
OrderResource
{
private
private Map < Integer , Order > orderDB =
new
new Hashtable < Integer , Order >();
private
private AtomicInteger idCounter = new
new AtomicInteger ();
@POST
@Consumes ( "application/xml" )
public
public Response createOrder ( Order order , @Context UriInfo uriInfo )
Search WWH ::




Custom Search