HandlerMethod evaluates ResponseStatus annotation for early caching
Issue: SPR-15227
This commit is contained in:
@@ -31,12 +31,10 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.reactive.HandlerResult;
|
||||
@@ -57,8 +55,6 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
|
||||
private static final Object NO_ARG_VALUE = new Object();
|
||||
|
||||
private HttpStatus responseStatus;
|
||||
|
||||
|
||||
private List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
|
||||
|
||||
@@ -67,23 +63,12 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
|
||||
public InvocableHandlerMethod(HandlerMethod handlerMethod) {
|
||||
super(handlerMethod);
|
||||
initResponseStatus();
|
||||
}
|
||||
|
||||
public InvocableHandlerMethod(Object bean, Method method) {
|
||||
super(bean, method);
|
||||
initResponseStatus();
|
||||
}
|
||||
|
||||
private void initResponseStatus() {
|
||||
ResponseStatus annotation = getMethodAnnotation(ResponseStatus.class);
|
||||
if (annotation == null) {
|
||||
annotation = AnnotatedElementUtils.findMergedAnnotation(getBeanType(), ResponseStatus.class);
|
||||
}
|
||||
if (annotation != null) {
|
||||
this.responseStatus = annotation.code();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the argument resolvers to use to use for resolving method
|
||||
@@ -132,8 +117,9 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||
try {
|
||||
Object value = doInvoke(args);
|
||||
HandlerResult result = new HandlerResult(this, value, getReturnType(), bindingContext);
|
||||
if (this.responseStatus != null) {
|
||||
exchange.getResponse().setStatusCode(this.responseStatus);
|
||||
HttpStatus status = getResponseStatus();
|
||||
if (status != null) {
|
||||
exchange.getResponse().setStatusCode(status);
|
||||
}
|
||||
return Mono.just(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user