t’s easy to validate parameters in JAX-RS using filters –
ContainerRequestFilter to be specific. There are other options at your disposal, e.g. using (CDI or EJB) interceptors, or injecting (HttpServletRequestusing @Context)Scenario: Validate Query Parameter Passed in by the Caller
Steps
- Implement filter
- Extracts query parameter from
ContainerRequestContext - Performs the validation – aborts the request with an appropriate response status (and the error message)
Enforce Filter
- Use
@NameBindingto decorate custom annotation - Use the custom annotation on the JAX-RS method
No comments:
Post a Comment