Reputation: 265
how can I modify the request message body at filters level. Can we change the message body with our custom message using RequestWrapper
.
Upvotes: 1
Views: 2895
Reputation: 38255
The short answer is yes.
However, you don't really modify the original request body; instead, you can return a different body from the request wrapper and the servlet will just work with that.
As for how you do it, just overwrite the getInputStream()
method of the HttpServletRequestWrapper
and return a modified version of the original InputStream
.
To make sure you remove any trail of the original body, you may want to overwrite getReader()
as well. Standard implementations would return some BufferedReader
over your InputStream
when asked for a reader, but
there are mock implementations (like the one in spring-test) that don't.
Upvotes: 3