C
C
cyberorg2014-01-17 22:13:00
Java
cyberorg, 2014-01-17 22:13:00

How to get RequestBody and ResponseBody from HttpServletRequest and HttpServletResponse objects?

What would you like to implement?
Logging of each request + request body + response body to the database.
The project uses Spring MVC, and therefore it was decided to do logging in the afterCompletion method of our HandlerInterceptor implementation.
Question: how to correctly get the request body and object body from the HttpServletRequest and HttpServletResponse objects that are passed to the afterCompletion method?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan Lopatin, 2014-01-18
@lorus

In the standard way - no way.
The request body is formed based on the HTTP request data. Based on the response body, respectively, an HTTP response is formed. Various implementations of the HttpMessageConverter interface do this.
If you need - write your own implementations. You can simply expand existing ones. If you don't feel like it, you can try using interception through AOP.

P
perk, 2014-01-20
@perk

Look towards Filters, Listeners

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question