Tom Norton Tom Norton - 7 months ago 30
Java Question

How can I log RESTful post data?

We have REST services exposed via Spring MVC. We use a

HandlerExceptionResolver
to log exceptions. We currently log the following:


  • The exception and its stack trace

  • The URL

  • The request headers



It would make debugging easier if we could also log the JSON post data as well. Any suggestions on how to get this?

Answer

You need a filter that would save request body when it's being read and provide the saved data to your exception logger later.

Spring contains AbstractRequestLoggingFilter that does the similar thing. Though it's not directly suitable for your problem, you can use it as a reference to implement your own filter.

Comments