users@jersey.java.net

Re: java.io.File and conditional GETs

From: Rob Koberg <rob_at_koberg.com>
Date: Wed, 7 Apr 2010 13:59:41 -0700

How about something like:


    String reqLastMod = httpreq.getHeader("If-Modified-Since");
    if (reqLastMod != null) {
      return req.evaluatePreconditions(Date.valueOf(reqLastMod),
             new EntityTag(httpreq.getHeader("If-None-Match"))).build();
    }
    return Response.ok(file).contentLocation(file.toURI()).build();

? Or is there a recommended way?

-Rob

On Wed, Apr 7, 2010 at 1:34 PM, Rob Koberg <rob_at_koberg.com> wrote:
> Hi,
>
> What is the best way to handle conditional GETs when targeting files
> that exist on the local file system that are being retrieved through a
> jersey resource? Currently it looks like I am using
> com.sun.jersey.core.impl.provider.entity.FileProvider (which doesn't
> appear the javadoc, checking out the project now...). Perhaps that
> could/should place an ETag and Last-Modified header by default?
>
> thanks,
> -Rob
>