Using spring validation on request headers

Is it possible to use spring framework with spring MVC to check the presence / absence and value of the HTTP request header?

Thank!

+2


source to share


1 answer


I don't see how this would be possible, as the validation framework only works on your domain objects and not on the HTTP request itself. In particular, the Validator interface does not specify any methods that take an HttpServletRequest object, which is what you need to have access in order to grab the headers and validate them.



Using an authentication system seems like the wrong solution to whatever problem you're trying to solve, especially since it's hard to figure out what the unique HTTP request header would be for a given form. Do you want to check the HTTP header that should always be present in your application's requests? Then you can consider implementing a HandlerInterceptor that will intercept and process all page requests that you mapped in any HanderMappings. Do you want to check the HTTP header, which should always be present in any page view of your application? Next, you will want to implement a Filter that runs outside of the Spring MVC context.

+4


source







All Articles