4

I have a requirement to send dynamic query parameters to REST web service GET method [as shown below].

host:port/app?field1=XXX&value1=VVV&field2=XXX&value2=XXX ....

The consumer can send parameters up to fieldn and valuen. Each field maps to the value.

With this type of requirement, I can't code a finite set of QueryParams on the server side method.

Is there any type of REST library that supports this? I checked RESTEasy and Jersey, and they both don't seem to support this [as far as I checked].

Thanks.

3
  • jersey sure does, check stackoverflow.com/questions/6154861/… Commented Sep 21, 2012 at 5:48
  • Thanks for your response. But that solution is for getting query parameters of same name. But in my case, the names will be different as in field1, field2, field3 and so on. Commented Sep 21, 2012 at 12:11
  • you're right, i was also looking for the same solution, how about this? stackoverflow.com/questions/5722506/… Commented Sep 21, 2012 at 14:32

1 Answer 1

6

Use UriInfo.getQueryParameters(), as following:

@GET
@Path("/foo")
@Produces(MediaType.APPLICATION_JSON)
public Response foo(@Context UriInfo uriInfo) {
    MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); 
    ...
}

It returns a MultivaluedMap. Then just iterate over it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.