How can I grab all query parameters in Jersey JaxRS?
You can access a single param via @QueryParam("name")
or all of the params via the context:
@POSTpublic Response postSomething(@QueryParam("name") String name, @Context UriInfo uriInfo, String content) { MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); String nameParam = queryParams.getFirst("name");}
The key is the @Context
jax-rs annotation, which can be used to access:
UriInfo, Request, HttpHeaders, SecurityContext, Providers
Adding a bit more to the accepted answer. It is also possible to get all the query parameters in the following way without adding an additional parameter to the method which maybe useful when maintaining swagger documentation.
@Contextprivate UriInfo uriInfo;@POSTpublic Response postSomething(@QueryParam("name") String name) { MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters(); String nameParam = queryParams.getFirst("name");}