I have a requirement to edit my HttpResponse to add header value. I was searching for single point to implement it and found that ResponseBodyadvice
would be helpful.
But both methods That overrode in my new class was never called. Could you please tell if I have missed any configurations.
@ControllerAdvice
public class EditResponseHeader implements ResponseBodyAdvice<object> {
@Override
public boolean supports(MethodParameter returnType,
Class<? extends HttpMessageConverter<?>> converterType) {
return true;
}
....
@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType,
MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType,
ServerHttpRequest request, ServerHttpResponse response) {
....
return body;
}
}
What about :
@Override
@ExceptionHandler(Exception.class)
public Response<?> beforeBodyWrite(Response<?> body, MethodParameter returnType,
MediaType selectedContentType,
Class<? extends HttpMessageConverter<?>> selectedConverterType,
ServerHttpRequest request, ServerHttpResponse response) {
....
return body;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With