users@jersey.java.net

Re: [Jersey] QueryParam not injected

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 03 Jun 2009 08:37:39 -0700

On Jun 3, 2009, at 3:45 AM, Anna Vagelin wrote:

> Hi,
>
> I'm trying Jersey in a Apache Tomcat solution where we used to run
> all requests through Servlets. There is a filterchain with filters
> doing all sorts of things e.g. adding parameters to the incoming
> request.

How are the filters adding parameters?

Jersey extracts the query parameters from the request URI. Namely,
from the HttpServletRequest.getQueryString().

You can print out the request URI Jersey is using, that was created
from the servlet by using UriInfo, for example

  @Context UriInfo ui;

   ...

     System.out.println(ui.getRequestUri());

I would be interested in knowing what the request URI is. I suspect
that it does not have the "resolution" query parameter.

Paul.

> When injecting one of these additional parameters as @QueryParam
> into the Resource, the parameter is null. However, if injecting the
> request via @Context and then pulling the parameter from it the
> parameter is instantiated correctly. How is this possible? What can
> I do to be able to use the @QueryParam?
>
> I'm using Jersey 1.0.
>
> @GET
> @Produces("*/xml")
> public Response getXml(@QueryParam("resolution") @DefaultValue("not
> defined") String resolution, @Context HttpServletRequest request)
> throws IOException {
>
> if (resolution == "not defined") {
> System.out.println("Resolution not defined in
> parameter); //Always printed
> }
> if (request != null) {
> System.out.println("Resolution from request" +
> request.getParameter("resolution")); //Always printed correctly
> }
>
> return ...
> }
>
> Best Regards
>
> Anna Vagelin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>