users@jersey.java.net

Access to HttpServletRequest from custom parameter class

From: Daniel Larsson <daniel.j.larsson_at_gmail.com>
Date: Fri, 27 Mar 2009 20:49:16 +0100

Hi,
I recently ran into a "problem" with a custom parameter class for a
QueryParam, e.g.

@GET
public getFoo(@Context HttpServletRequest r, @QueryParam("bar") Bar bar) {
  Baz baz = bar.getValue(r.getLocale());
}

The bar class needs to know the current Locale in order to parse the
incoming string correctly, and I believe I can't get the request object
(HttpServletRequest) from inside Bar. Right now I've resorted to have a
method on Bar to extract the "real" value, taking a Locale as input.

Is there a neater way that I've missed? Does the StringReader<T> class
posted last month help out any? (e.g.. can I add @Context annotated objects
into my StringReaderProvider?).

Daniel