users@jersey.java.net

[Jersey] Etag usage

From: Jonathan Cook - FM&T <Jonathan.Cook2_at_bbc.co.uk>
Date: Tue, 11 Jan 2011 14:32:08 +0000

Hello,

I am exploring the use of Etags and was a little bit confused, does the
evaluatePreconditions handle checking to see if the If-None-Match header
exists or is it down to resource to determine this. For example I have the
following piece of code:
        
    @GET
    @Path("competition/{comp}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public Response getTable(@Context Request request, @PathParam("comp")
final String comp) throws WebApplicationException {
        String result =
executeXQuery(String.format(FIND_TABLE_BY_COMP_XQUERY, comp),
                CACHE_KEY_PREFIX+comp);
        
        CacheControl cacheControl = new CacheControl();
        cacheControl.setMaxAge(cacheControlMaxAge);
        
        EntityTag etag = computeEntityTag(result);
        Response.ResponseBuilder responseBuilder =
request.evaluatePreconditions(etag);
        if (responseBuilder != null) {
              LOG.debug("Table has not changed..returning unmodified
response code");
              return responseBuilder.cacheControl(cacheControl).build();
        }
        
        return
Response.ok(result).cacheControl(cacheControl).tag(etag).build();
    }

But it doesnąt appear to take into account whether If-None-Match is in the
request header or not. I canąt actually find the source for
evaluatePreconditions.

Thanks
Jon