Jersey - validate REST service parameters

扶醉桌前 提交于 2020-01-05 14:04:39

问题


is there any tool to simply validate query params using Jersey (and Maven)? I'm trying to do something like this using @NotNull annotation (jersey-bean-validation):

@GET
@Path("/count")
@Produces(MediaType.APPLICATION_XML)
public Response count(@NotNull @QueryParam("my_param") String my_param) {
    //TODO automatically return 400 Bad Request if my_param is null
    return Response.ok("This is a response", MediaType.APPLICATION_XML).build();
}

I'd like the method to automatically validate query parameters and return 400 Bad Request if no "my_param" is provided.


回答1:


My guess is you are using Jersey 1.x, which does not support annotated validations against PathParams or QueryParams.

See Nick Telfords comments in https://groups.google.com/forum/#!topic/dropwizard-user/wb6iwrpSrSE



来源:https://stackoverflow.com/questions/21090080/jersey-validate-rest-service-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!