I'd like to have an @ControllerAdvice
that is called for all HTTP requests on all controllers. Unfortunately it only triggers if there is a HTTP body in the request. If not, it's completely ignored. Isn't spring supposed to call handleEmptyBody()
in this case?
Edit
All controllers are annotated with @RestController
.
Any ideas?
@ControllerAdvice
public class CatchAllRequestsAdvice implements RequestBodyAdvice {
private static final Logger LOGGER = LoggerFactory.getLogger(CatchAllRequestsAdvice.class);
@Override
public boolean supports(
MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType
) {
LOGGER.info("");
return true;
}
@Override
public HttpInputMessage beforeBodyRead(
HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType
) throws IOException {
LOGGER.info("");
return inputMessage;
}
@Override
public Object afterBodyRead(
Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType
) {
LOGGER.info("");
return body;
}
@Override
public Object handleEmptyBody(
Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType
) {
LOGGER.info("");
return body;
}
}