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.

Arav Vijay
  • 251
  • 5
  • 13
  • jersey sure does, check http://stackoverflow.com/questions/6154861/handling-multiple-query-parameters-in-jersey – user311174 Sep 21 '12 at 05: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. – Arav Vijay Sep 21 '12 at 12:11
  • you're right, i was also looking for the same solution, how about this? http://stackoverflow.com/questions/5722506/how-do-you-map-multiple-query-parameters-to-the-fields-of-a-bean-on-jersey-get-r – user311174 Sep 21 '12 at 14:32

1 Answers1

5

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.

cassiomolin
  • 124,154
  • 35
  • 280
  • 359