users@jersey.java.net

Produces, type mapping and wierd filter behaviour

From: John Lister <john.lister_at_kickstone.com>
Date: Wed, 22 Sep 2010 22:21:03 +0100

  Hi, I have a resource filter which check some state to determine if a
request is authorised and if not throws an exception. This exception
(along with others) is caught in a custom mapper which returns an error
object wrapped in a response that depending upon the accept type is
rendered in various ways.

To determine if the checks are required I annotate either the class or
method with a custom annotation and use a resource filter factory to
apply the filter to every method tagged (or all if the class is tagged).

All seems to work well, except if I use @Produces on my methods and have
an accept type of */*.

For example take the following:

@Path("/test/")
@AuthorisedCheck
@Produces("application/xml")
public Response getTest(){....}


If I set the request header to application/xml, all goes to plan and I
get back an xml error when the checks fail. Using an explicit type of
text/html results in a 406 (Not acceptable) error as expected. However
there are 2 exceptions to this behaviour:
- if just */* is supplied as the accept type then html is returned even
though I would expect xml
- secondly if the list of types includes xml or a matching wildcard,
then the first type in the list is matched incorrectly. For example
    text/html,application/xml would match and return html, again I
would expect xml to be returned?

This would appear to be a bug in the filter exception handling, in that
if I don't use the filter and throw the exception directly from the
resource, the correct type is used.

Any suggestions

Thanks

John