How can I log RESTful post data?

前端 未结 3 1317
离开以前
离开以前 2020-12-31 09:18

We have REST services exposed via Spring MVC. We use a HandlerExceptionResolver to log exceptions. We currently log the following:

  • The exception
3条回答
  •  耶瑟儿~
    2020-12-31 09:46

    There is no easy way to log the payload of the request/response. You can use a java web filter to intercept all the requests and responses and read the JSON data from the stream. But there is one problem, when you will read data from the stream the actual data will be exhausted from stream.

    Therefore, you have to implement the wrapper of actual request and response object. Only the copied version of request response will be logged. We have implemented similar solution like follows and it satisfied our requirement:

    http://www.wetfeetblog.com/servlet-filer-to-log-request-and-response-details-and-payload/431

    http://angelborroy.wordpress.com/2009/03/04/dump-request-and-response-using-javaxservletfilter/

提交回复
热议问题