I have some web services that require quite a few options for query parameters. Rather than have a long list of @QueryParam parameters and then manually setting them to a criteria object I've created, I thought I would use UriInfo and get the MultivaluedMap from getQueryParameters, then pass that MultivaluedMap to a constructor (or a setter) for my criteria object.
So here's a concrete example. In my old method:
@GET
public Item[] getItems(@QueryParam String regionCode, @QueryParam String customerCode, @QueryParam Integer pageSize, @QueryParam Integer page) {
ItemCriteria criteria = new ItemCriteria();
criteria.setRegionCode(regionCode);
criteria.setCustomerCode(customerCode);
criteria.setPageSize(pageSize);
criteria.setPage(page);
return itemDao.getItemsByCriteria(criteria);
}
Replace that with:
@GET
public Item[] getItems(@Context UriInfo ui) {
ItemCriteria criteria = new ItemCriteria(ui.getQueryParameters());
return itemDao.getItemsByCriteria(criteria);
}
It works great, and I can do a lot with unit tests that I would have otherwise probably had to do with integration tests. The problem is that I don't get to use @param javadoc comments to produce my extended WADL anymore. I can just manually format all of the expected parameters, but is there a way to do this that I'm missing?