I have a use case where I need to verify if the incoming request body to my controller contains any special characters in a Hybris storefront. Though it can be achieved from the front-end by blocking any special characters, we require back-end validation.
I tried using HandlerIntercepterAdapter
to intercept the request and validate for any special characters. But whenever I use request.getReader()
or request.getInputStream()
and read the data, request body is cleared.
I tried using IOUtils.copy()
but this too reads from the original request and makes the body empty.
Even after wrapping the request with HttpServletRequestWrapper
or ContentCachingRequestWrapper
, the request body gets cleared. I guess internally somewhere it uses the same reference.
I tried following this thread but was unable to solve this issue.
I am looking for a solution where I can extract the request body and validate it without letting it get cleared so it can be used in different controllers [or] any alternative approach which can help in preventing any special characters to hit the controller.