Logic I have to implement is logging all requests with body served to DB.
So I decided to use: afterCompletion method of HandlerInterceptor
You can extend RequestBodyAdviceAdapter and implement the method afterBodyRead:
@ControllerAdvice
public MyRequestBodyAdviceAdapter extends RequestBodyAdviceAdapter {
@Override
public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter,
Type targetType, Class extends HttpMessageConverter>> converterType) {
// write body -your input dto- to logs or database or whatever
return body;
}
}
The RequestBodyAdvice comes in pre setp the request chain before the HandlerInterceptor. it is exactly after the http request inputstream is converted to your object.