I am building a generic web service and need to grab all the query parameters into one string for later parsing. How can I do this?
@PUT @Path("{user}/{directory:. +}") public Response doshare(@PathParam("user")String name, @PathParam("directory")String dir, @QueryParam("name")String sharename, @QueryParam("type")String type){ mongoDAOImpl impl=new mongoDAOImpl(); Mongo mongo=impl. getConnection("127.0. 0.1","27017"); DB db=impl.
You can access a single param via @QueryParam("name")
or all of the params via the context:
@POST public 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
The unparsed query part of the request URI can be obtained from the UriInfo
object:
@GET public Representation get(@Context UriInfo uriInfo) { String query = uriInfo.getRequestUri().getQuery(); ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With