I have a spring boot application. I change the request body of every post request. Is it possible to modify the request body before the request reaches the controller. Pleas
Short Answer
Yes, but not easily.
Details
I know of three options to change the body of a request
"before" it arrives at the handler method in the controller;
Since you are already using spring-boot, option 3, custom Spring HandlerInterceptor, seems like the best option for you.
Here is a link to a Baeldung Article covering spring HandlerInterceptors.
The Baeldung article is not the full answer for your problem
because you can only read the InputStrem returned by HttpServletRequest one time.
You will need to create a wrapper class that extends HttpServletRequest
and wrap every request in your wrapper class within your custom HandlerInterceptor or in a custom Filter (Filter might be the way to go here).
Wrapper Class
HttpServletRequest InputStream in the wrapper class constructorByteArrayOutputStream.toByteArray to retrieve the actual byte[] from the stream.getInputStream method.byte[] in a ByteArrayInputStream every time the getInputStream is called. Return this stream.How To Wrap the Request