users@jersey.java.net

Re: [Jersey] Bug in Jersey's header parser?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 03 Nov 2008 09:08:38 +0100

On Nov 2, 2008, at 7:46 PM, Gili wrote:

>
>
> Paul Sandoz wrote:
>>
>> Jersey will format date objects according to RFC 1123 (US locale)
>> which
>> is the recommended format for HTTP dates. Annoyingly:
>>
>> new GregorianCalendar(2003, Calendar.FEBRUARY, 1).getTime()
>>
>> returns a header of:
>>
>> Last-Modified Fri, 31 Jan 2003 23:00:00 GMT
>>
>> i.e. one day behind what is declared. I think it is a rounding error
>> when formatting.
>>
>
> Paul,
>
> Can you please clarify this? How did you end up with January 31st
> 2003? When
> I run:
>
> System.out.println(new GregorianCalendar(2003, Calendar.FEBRUARY,
> 1).getTime().toString());
>
> I get February 1st, 2003. Are you saying there is a bug in Jersey's
> Date ->
> String conversion algorithms?

Jersey defers to a SimpleDateFormat instance for RFC 1123:

         SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy
HH:mm:ss zzz", Locale.US);
         TimeZone tz = TimeZone.getTimeZone("GMT");
         sdf.setTimeZone(tz);

         GregorianCalendar d = new GregorianCalendar(2003,
Calendar.FEBRUARY, 1);

         System.out.println("toString: " + d.getTime().toString());
         System.out.println(" format: " + sdf.format(d.getTime()));

It looks like the setting of the time zone to GMT causes the date to
be formated one day earlier. From the HTTP spec the time zone must be
GMT [1]. Is this a bug in the date formatting code?

Paul.

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

> Also, is there a JAX-RS or Jersey equivalent
> to RestEasy's DateUtil class?
>
> http://www.jboss.org/file-access/default/members/resteasy/freezone/docs/1.0-beta-6/javadocs/resteasy-jaxrs/org/jboss/resteasy/util/DateUtil.html
>
> I want to embed dates inside some XML body and it probably makes
> sense to
> use the same format throughout. It's not clear how to easily
> transform a
> Date to the RFC1123 format.
>
> Gili
> --
> View this message in context: http://n2.nabble.com/Re%3A-Bug-in-Jersey%27s-header-parser--tp581274p1446307.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>