2

I have a HandlerInterceptor that would like to scan the arguments defined by the passed hander and if one has been annotated with the RequestBody annotiation, it would like to read it in and check the RequestBody content to make a decision on whether to return true or false on the preHandle method.

I know the request body can only be read once and what I want is my interceptor to read it in instead of the DispatcherSevlet when calling the HandlerAdapter's handle method immediately after invoking the preHandle interceptors.

mario
  • 25
  • 1
  • 8
  • 18
  • You can use RequestBodyAdvice, see my answer here: https://stackoverflow.com/questions/21193380/get-requestbody-and-responsebody-at-handlerinterceptor/53128795#53128795 – Muhammad Hewedy Nov 03 '18 at 06:00

1 Answers1

1

You Can Use Java 8 Stream API:

String s = request.getReader()
    .lines()
    .collect(Collectors.joining()); 
Uwe Allner
  • 3,399
  • 9
  • 35
  • 49
sohrab
  • 11
  • 1