users@jersey.java.net

Re: [Jersey] webkit date format If-Modified-Since

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 14 Apr 2009 18:06:27 +0200

Hi Brian,

Did you verify if that modification works for you?

The fix you provide will break when the time zone is not present,
which is the correct formatting for ANSI C's asctime() format [1], for
example "Sun Nov 6 08:49:37 1994".

Plus the format you state will not parse the date in the If-Modified-
Since header (see simple example code at the end of the email).

The date in the Safari header

   "Tue Apr 14 2009 05:58:52 GMT-0700 (PDT)"

does not conform to any of the required supported date formats. Notice
that the year comes after the day of the month. I think this is a bug
in Safari.

There is a bug though Jersey, should log a warning that the data
cannot be parsed rather than silently ignoring it.

Paul.

[1] http://greenbytes.de/tech/webdav/rfc2616.html#full.date


public class Main {

     public static void main(String[] args) throws Exception {
         SimpleDateFormat asctime = new SimpleDateFormat("EEE MMM d
HH:mm:ss yyyy", Locale.US);

         Date d;

         d = asctime.parse("Sun Nov 6 08:49:37 1994");

         SimpleDateFormat asctimeWithTimezon = new
SimpleDateFormat("EEE MMM d HH:mm:ss yyyy zzz", Locale.US);
         d = asctime.parse("Tue Apr 14 2009 05:58:52 GMT-0700 (PDT)");
     }

}



On Apr 14, 2009, at 5:14 PM, brian walsh wrote:

> We are getting the following date formats from safari clients
>
> If-Modified-Since Tue Apr 14 2009 05:58:52 GMT-0700 (PDT)
>
> This causes our application to return 200 when we expected 304.
>
> Tracing the code, it appears com.sun.jersey.core.header.HttpDateFormat
> contains the following...
>
>
> /**
> * The date format pattern for ANSI C asctime().
> */
> private static final String ANSI_C_ASCTIME_DATE_FORMAT_PATTERN =
> "EEE MMM d HH:mm:ss yyyy";
>
>
> Shouldn't it be ...
>
> /**
> * The date format pattern for ANSI C asctime().
> */
> private static final String ANSI_C_ASCTIME_DATE_FORMAT_PATTERN =
> "EEE MMM dd HH:mm:ss yyyy zzz";
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>