dev@jsr311.java.net

Re: Parsing headers, was: Abstract from HTTP <was> Re: Welcome to JSR 311

From: Dhanji R. Prasanna <dhanji_at_gmail.com>
Date: Wed, 11 Apr 2007 08:15:11 +1000

On 4/11/07, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

>
> Dhanji R. Prasanna wrote:
> >
> > I dont think I get this--how would a parameterized List of MediaType
> > indicate to the runtime that index 0 is a component type
> > [foo/bar;ext="a,b"] and index 1 is [text/plain].
> > I think Im missing something basic here...
> >
>
> Because:
>
> 1) the runtime knows the Accept header value can be a comma separated
> list of media type values; and


I thought Julian's point was that knowing it's a comma separated list is not
enough? That a separate component-specific parser must be installed by the
user--or is this what you mean by the runtime knowing? If so that makes
sense...

2) either MediaType or the runtime, via the knowledge of the MediaType
> class, knows how to parse a media type as specified by the HTTP grammar.


Yea this I saw in the javadoc, which I think is a very good idea. I like the
use of the static factory "valueOf" too--also, mightn't it be prudent to
annotate the factory rather than relying on a naming convention (same
applies for the ctor)? That will make it explicit, type-safe and
self-documented, in the case where it's a user-provided class:

@HeaderProducer(Headers.ACCEPT)
public static MyClass valueOf(String header) { .. }

Dhanji.