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 get the request body from HTTPServlet request inside HandlerInterceptorAdapter methods using the method:
request.getInputStream();
If you want it to use with scanner you can assign the scanner as follows:
Scanner scanner = new Scanner(request.getInputStream(), "UTF-8");
Then you can use the required data from the scanner using some manipulation or scanner tricks. Or else you can assign it to a string also using Apache Commons IO:
String requestStr = IOUtils.toString(request.getInputStream());