Get RequestBody and ResponseBody at HandlerInterceptor

前端 未结 7 1755
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 11:31

Logic I have to implement is logging all requests with body served to DB.

So I decided to use: afterCompletion method of HandlerInterceptor

7条回答
  •  执笔经年
    2020-12-14 12:08

    Here's the relevant statement from javadoc for HandlerInterceptor javadoc.

    Callback after completion of request processing, that is, after rendering the view. Will be called on any outcome of handler execution, thus allows for proper resource cleanup.

    HandlerIntercepter Javadoc

    You cannot access the request body (as an InputStream) because the request was already read. If you need access to request parameters, you could do so using the request object by calling - request.getParameter("parameterName");

    You cannot access the response body because the response is already rendered. That means the response is already committed to the outputstream.

提交回复
热议问题