Java Reference
In-Depth Information
Chapter 19. Examples for Chapter 4
Chapter 4 discussed three things. First, it mentioned how the
annotation works and how to define and bind Java methods to new HTTP methods. Next, it
talked about the intricacies of the @Path annotation, and explained how you can use complex
regular expressions to define your application's published URIs. Finally, the chapter went
over the concept of subresource locators.
This chapter walks you through three different example programs that you can build and run
to illustrate the concepts in Chapter 4 . The first example uses @HttpMethod to define a new
HTTP method called PATCH. The second example expands on the customer service database
example from Chapter 18 by adding some funky regular expression mappings with @Path .
The third example implements the subresource locator example shown in Full Dynamic Dis-
patching in Chapter 4 .
Example ex04_1: HTTP Method Extension
This example shows you how your JAX-RS services can consume HTTP methods other than
the common standard ones defined in HTTP 1.1. Specifically, the example implements the
PATCH method. The PATCH method was originally mentioned in an earlier draft version of
the HTTP 1.1 specification: [ 21 ]
The PATCH method is similar to PUT except that the entity contains a list of differences
between the original version of the resource identified by the Request-URI and the desired con-
tent of the resource after the PATCH action has been applied.
The idea of PATCH is that instead of transmitting the entire representation of a resource to
update it, you only have to provide a partial representation in your update request. PUT re-
quires that you transmit the entire representation, so the original plan was to include PATCH
for scenarios where sending everything is not optimal.
Build and Run the Example Program
Perform the following steps:
1. Open a command prompt or shell terminal and change to the ex04_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 mvn install .
Search WWH ::

Custom Search