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

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

On 4/11/07, Paul Sandoz <> 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

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:

public static MyClass valueOf(String header) { .. }