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 (HttpServletRequest
using @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
@NameBinding
to decorate custom annotation - Use the custom annotation on the JAX-RS method
No comments:
Post a Comment