users@jersey.java.net

Re: [Jersey] Re: java.io.File and conditional GETs

From: Marc Hadley <marc.hadley_at_oracle.com>
Date: Wed, 7 Apr 2010 18:00:36 -0400

On Apr 7, 2010, at 4:59 PM, Rob Koberg wrote:

> 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?
>
You aren't really checking the preconditions above, you are just comparing the value of the If-Modified-Since header with itself. What you need to do is get the last modified date from the backing file and use that in the call to req.evaluatePreconditions. That will see if there's an If-Modified-Since or whatever in the request and compare it to the value you passed in. A null return means the preconditions were met and you should go ahead and process the request, a non-null return means the pre-conditions weren't met and you should return the returned response after adding any additional metadata and building it.

Marc.

>
> 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
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>