Improve @RequestAttribute WebFlux resolver

The resolver now takes into account the possibility the attribute
itself may be a reactive type.

Issue: SPR-16158
This commit is contained in:
Rossen Stoyanchev
2017-11-06 21:44:45 -05:00
parent 14f02d7192
commit 9786750b5a
3 changed files with 107 additions and 34 deletions

View File

@@ -24,6 +24,7 @@ import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.MatrixVariable;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -62,6 +63,10 @@ public class MvcAnnotationPredicates {
return new RequestPartPredicate();
}
public static RequestAttributePredicate requestAttribute() {
return new RequestAttributePredicate();
}
public static MatrixVariablePredicate matrixAttribute() {
return new MatrixVariablePredicate();
}
@@ -256,6 +261,38 @@ public class MvcAnnotationPredicates {
}
}
public static class RequestAttributePredicate implements Predicate<MethodParameter> {
private String name;
private boolean required = true;
public RequestAttributePredicate name(String name) {
this.name = name;
return this;
}
public RequestAttributePredicate noName() {
this.name = "";
return this;
}
public RequestAttributePredicate notRequired() {
this.required = false;
return this;
}
@Override
public boolean test(MethodParameter parameter) {
RequestAttribute annotation = parameter.getParameterAnnotation(RequestAttribute.class);
return annotation != null &&
(this.name == null || annotation.name().equals(this.name)) &&
annotation.required() == this.required;
}
}
public static class ResponseStatusPredicate implements Predicate<Method> {
private HttpStatus code = HttpStatus.INTERNAL_SERVER_ERROR;