Java Reference
In-Depth Information
@GET
@Produces("application/xml")
public Employee(@PathParam("joiningdate") Date joiningdate,
@Context Request req,
@Context UriInfo ui) {
this.joiningdate = joiningdate;
...
this.tag = computeEntityTag(ui.getRequestUri());
if (req.getMethod().equals("GET")) {
Response.ResponseBuilder rb =
req.evaluatePreconditions(tag);
if (rb != null) {
throw new WebApplicationException(rb.build());
}
}
}
}
In this code snippet, the constructor of the Employee class computes the entity tag from
the request URI and calls the request.evaluatePreconditions method with
that tag. If a client request returns an If-none-match header with a value that has the
same entity tag that was computed, evaluate.Preconditions returns a pre-filled-
out response with a 304 status code and an entity tag set that may be built and returned.
Runtime Content Negotiation
The @Produces and @Consumes annotations handle static content negotiation in JAX-
RS. These annotations specify the content preferences of the server. HTTP headers such
as Accept , Content-Type , and Accept-Language define the content negotiation
preferences of the client.
For more details on the HTTP headers for content negotiation, see HTTP/1.1 - Content
Negotiation
( http://www.w3.org/Protocols/rfc2616/
rfc2616-sec12.html ) .
The following code snippet shows the server content preferences:
Click here to view code image
@Produces("text/plain")
@Path("/employee")
public class Employee {
@GET
Search WWH ::




Custom Search