users@jsr311.java.net

Re: MediaType.isComaptible

From: Reto Bachmann-Gmür <reto_at_gmuer.ch>
Date: Thu, 14 Aug 2008 11:02:32 +0200

Paul Sandoz wrote:
>
> Or the Accept header could be:
> Accept: image/jpeg
>
> and i could have a resource method:
>
> @Produces("image/*")
> public Response getGeneralImage() { ... }
>
> Changing this method to be asymmetric will essentially render it useless.

With the accept header image/jpeg a producer of image/jpeg is to be
preferred over image/jpeg, so you could first iterate over the candidate
producer (sorting them by q-value) checking if there is a subtype of
image/jpeg if no match look for exactly image/* and then */*. Returning
a subtype (where a type is a subtype of itself) is best, using a generic
producer is a fall-back.

Looking at this, I realize that it's no clear to me, what
wildchar-producer are supposed to do if they cannot produce the
requested concrete type, say we have a BodyWriter with
Produces("image/*") able to produce many image formats and one with
Produces("images/png") and a request with

Accept: image/x-weird-format, image/png;q=.9

the BodyWriter for image/* matches image/x-weird-format but will fail to
  produce that format and throw an exception. Had the mediatype been
passed to isWriteable the BodyWriter could have detected that it doesn't
support image/x-weird-format allowing the producer for next accepted
format to be used.

Reto