I have service(WildFly 10.1) which looks like that :
@GET
@Path("/retrieve")
public Response getModels(@BeanParam ModelQueryParams queryParams) {
return getModels();
}
With ModelQueryParams:
public class ModelQueryParams{
@QueryParam("offset")
private Long offset;
@QueryParam("limit")
private Long limit;
}
So the user can call endpoint like:
/retrieve?offset=100&limit=4
But how can I validate case when user pass into the query wrong parameter?
/retrieve?offset=100&limit=4&WRONG_PARAMETER=55
Is there the way to validate it somehow?
if you don't have any field or method parameters annotated with @QueryParam
, then those extra parameters are not your problem and it's best to deal with only parameters you expect for your resource.
If you still need access to all query parameters, then inject UriInfo
with @Context
and call it's getQueryParameters()
to get a MultivaluedMap
of request parameters