Polishing
This commit is contained in:
@@ -94,17 +94,17 @@ class CglibAopProxy implements AopProxy, Serializable {
|
|||||||
private static final int INVOKE_HASHCODE = 6;
|
private static final int INVOKE_HASHCODE = 6;
|
||||||
|
|
||||||
|
|
||||||
|
private static final String COROUTINES_FLOW_CLASS_NAME = "kotlinx.coroutines.flow.Flow";
|
||||||
|
|
||||||
|
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent(
|
||||||
|
"kotlinx.coroutines.reactor.MonoKt", CglibAopProxy.class.getClassLoader());
|
||||||
|
|
||||||
/** Logger available to subclasses; static to optimize serialization. */
|
/** Logger available to subclasses; static to optimize serialization. */
|
||||||
protected static final Log logger = LogFactory.getLog(CglibAopProxy.class);
|
protected static final Log logger = LogFactory.getLog(CglibAopProxy.class);
|
||||||
|
|
||||||
/** Keeps track of the Classes that we have validated for final methods. */
|
/** Keeps track of the Classes that we have validated for final methods. */
|
||||||
private static final Map<Class<?>, Boolean> validatedClasses = new WeakHashMap<>();
|
private static final Map<Class<?>, Boolean> validatedClasses = new WeakHashMap<>();
|
||||||
|
|
||||||
private static final String COROUTINES_FLOW_CLASS_NAME = "kotlinx.coroutines.flow.Flow";
|
|
||||||
|
|
||||||
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt",
|
|
||||||
CglibAopProxy.class.getClassLoader());;
|
|
||||||
|
|
||||||
|
|
||||||
/** The configuration used to configure this proxy. */
|
/** The configuration used to configure this proxy. */
|
||||||
protected final AdvisedSupport advised;
|
protected final AdvisedSupport advised;
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
|||||||
|
|
||||||
private static final String COROUTINES_FLOW_CLASS_NAME = "kotlinx.coroutines.flow.Flow";
|
private static final String COROUTINES_FLOW_CLASS_NAME = "kotlinx.coroutines.flow.Flow";
|
||||||
|
|
||||||
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt",
|
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent(
|
||||||
JdkDynamicAopProxy.class.getClassLoader());;
|
"kotlinx.coroutines.reactor.MonoKt", JdkDynamicAopProxy.class.getClassLoader());
|
||||||
|
|
||||||
/** We use a static Log to avoid serialization issues. */
|
/** We use a static Log to avoid serialization issues. */
|
||||||
private static final Log logger = LogFactory.getLog(JdkDynamicAopProxy.class);
|
private static final Log logger = LogFactory.getLog(JdkDynamicAopProxy.class);
|
||||||
|
|||||||
@@ -64,8 +64,9 @@ import org.springframework.util.ReflectionUtils;
|
|||||||
*/
|
*/
|
||||||
public abstract class AopUtils {
|
public abstract class AopUtils {
|
||||||
|
|
||||||
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent("kotlinx.coroutines.reactor.MonoKt",
|
private static final boolean coroutinesReactorPresent = ClassUtils.isPresent(
|
||||||
AopUtils.class.getClassLoader());;
|
"kotlinx.coroutines.reactor.MonoKt", AopUtils.class.getClassLoader());
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.
|
* Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.
|
||||||
@@ -349,8 +350,8 @@ public abstract class AopUtils {
|
|||||||
// Use reflection to invoke the method.
|
// Use reflection to invoke the method.
|
||||||
try {
|
try {
|
||||||
ReflectionUtils.makeAccessible(method);
|
ReflectionUtils.makeAccessible(method);
|
||||||
return coroutinesReactorPresent && KotlinDetector.isSuspendingFunction(method) ?
|
return (coroutinesReactorPresent && KotlinDetector.isSuspendingFunction(method) ?
|
||||||
KotlinDelegate.invokeSuspendingFunction(method, target, args) : method.invoke(target, args);
|
KotlinDelegate.invokeSuspendingFunction(method, target, args) : method.invoke(target, args));
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException ex) {
|
catch (InvocationTargetException ex) {
|
||||||
// Invoked method threw a checked exception.
|
// Invoked method threw a checked exception.
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ import org.springframework.lang.Nullable;
|
|||||||
*/
|
*/
|
||||||
class KotlinReflectionBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
|
class KotlinReflectionBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
|
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
|
||||||
Class<?> beanClass = registeredBean.getBeanClass();
|
Class<?> beanClass = registeredBean.getBeanClass();
|
||||||
if (KotlinDetector.isKotlinType(beanClass)) {
|
if (KotlinDetector.isKotlinType(beanClass)) {
|
||||||
@@ -45,6 +45,7 @@ class KotlinReflectionBeanRegistrationAotProcessor implements BeanRegistrationAo
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class AotContribution implements BeanRegistrationAotContribution {
|
private static class AotContribution implements BeanRegistrationAotContribution {
|
||||||
|
|
||||||
private final Class<?> beanClass;
|
private final Class<?> beanClass;
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ class ServletServerHttpRequestTests {
|
|||||||
assertThat(headers).as("No HttpHeaders returned").isNotNull();
|
assertThat(headers).as("No HttpHeaders returned").isNotNull();
|
||||||
assertThat(headers.containsKey(headerName)).as("Invalid headers returned").isTrue();
|
assertThat(headers.containsKey(headerName)).as("Invalid headers returned").isTrue();
|
||||||
List<String> headerValues = headers.get(headerName);
|
List<String> headerValues = headers.get(headerName);
|
||||||
|
assertThat(headerValues).as("No header values returned").isNotNull();
|
||||||
assertThat(headerValues.size()).as("Invalid header values returned").isEqualTo(2);
|
assertThat(headerValues.size()).as("Invalid header values returned").isEqualTo(2);
|
||||||
assertThat(headerValues.contains(headerValue1)).as("Invalid header values returned").isTrue();
|
assertThat(headerValues.contains(headerValue1)).as("Invalid header values returned").isTrue();
|
||||||
assertThat(headerValues.contains(headerValue2)).as("Invalid header values returned").isTrue();
|
assertThat(headerValues.contains(headerValue2)).as("Invalid header values returned").isTrue();
|
||||||
@@ -150,7 +151,7 @@ class ServletServerHttpRequestTests {
|
|||||||
assertThat(headers.getContentType()).isNull();
|
assertThat(headers.getContentType()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-27957
|
@Test // gh-27957
|
||||||
void getHeadersWithWildcardContentType() {
|
void getHeadersWithWildcardContentType() {
|
||||||
mockRequest.setContentType("*/*");
|
mockRequest.setContentType("*/*");
|
||||||
mockRequest.removeHeader("Content-Type");
|
mockRequest.removeHeader("Content-Type");
|
||||||
@@ -166,7 +167,7 @@ class ServletServerHttpRequestTests {
|
|||||||
assertThat(result).as("Invalid content returned").isEqualTo(content);
|
assertThat(result).as("Invalid content returned").isEqualTo(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-13318
|
@Test // gh-13318
|
||||||
void getFormBody() throws IOException {
|
void getFormBody() throws IOException {
|
||||||
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||||
mockRequest.setMethod("POST");
|
mockRequest.setMethod("POST");
|
||||||
@@ -189,7 +190,7 @@ class ServletServerHttpRequestTests {
|
|||||||
assertThat(result).as("Invalid content returned").isEqualTo(content);
|
assertThat(result).as("Invalid content returned").isEqualTo(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-31327
|
@Test // gh-31327
|
||||||
void getFormBodyWhenQueryParamsAlsoPresent() throws IOException {
|
void getFormBodyWhenQueryParamsAlsoPresent() throws IOException {
|
||||||
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||||
mockRequest.setMethod("POST");
|
mockRequest.setMethod("POST");
|
||||||
@@ -203,7 +204,7 @@ class ServletServerHttpRequestTests {
|
|||||||
assertThat(result).as("Invalid content returned").isEqualTo(content);
|
assertThat(result).as("Invalid content returned").isEqualTo(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-32471
|
@Test // gh-32471
|
||||||
void getFormBodyWhenNotEncodedCharactersPresent() throws IOException {
|
void getFormBodyWhenNotEncodedCharactersPresent() throws IOException {
|
||||||
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||||
mockRequest.setMethod("POST");
|
mockRequest.setMethod("POST");
|
||||||
|
|||||||
@@ -150,8 +150,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
boolean condition = result instanceof String;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(result).as("Invalid result").isEqualTo(expected);
|
assertThat(result).as("Invalid result").isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,12 +160,10 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
boolean condition = result instanceof String[];
|
assertThat(result).as("Invalid result").isEqualTo(expected);
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat((String[]) result).as("Invalid result").isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-32577
|
@Test // gh-32577
|
||||||
void resolveStringArrayWithEmptyArraySuffix() throws Exception {
|
void resolveStringArrayWithEmptyArraySuffix() throws Exception {
|
||||||
String[] expected = new String[] {"foo", "bar"};
|
String[] expected = new String[] {"foo", "bar"};
|
||||||
request.addParameter("name[]", expected[0]);
|
request.addParameter("name[]", expected[0]);
|
||||||
@@ -175,9 +171,7 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
boolean condition = result instanceof String[];
|
assertThat(result).isEqualTo(expected);
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat((String[]) result).isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -189,8 +183,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile.class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile.class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
boolean condition = result instanceof MultipartFile;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(result).as("Invalid result").isEqualTo(expected);
|
assertThat(result).as("Invalid result").isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,9 +198,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
|
|
||||||
boolean condition = result instanceof List;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
|
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,9 +224,7 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(MultipartFile[].class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
|
assertThat(result instanceof MultipartFile[]).isTrue();
|
||||||
boolean condition = result instanceof MultipartFile[];
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
MultipartFile[] parts = (MultipartFile[]) result;
|
MultipartFile[] parts = (MultipartFile[]) result;
|
||||||
assertThat(parts).hasSize(2);
|
assertThat(parts).hasSize(2);
|
||||||
assertThat(expected1).isEqualTo(parts[0]);
|
assertThat(expected1).isEqualTo(parts[0]);
|
||||||
@@ -266,9 +253,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part.class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part.class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
|
|
||||||
boolean condition = result instanceof Part;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(result).as("Invalid result").isEqualTo(expected);
|
assertThat(result).as("Invalid result").isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,9 +270,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, Part.class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(List.class, Part.class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
|
|
||||||
boolean condition = result instanceof List;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
|
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,9 +300,7 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Part[].class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
|
assertThat(result instanceof Part[]).isTrue();
|
||||||
boolean condition = result instanceof Part[];
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
Part[] parts = (Part[]) result;
|
Part[] parts = (Part[]) result;
|
||||||
assertThat(parts).hasSize(2);
|
assertThat(parts).hasSize(2);
|
||||||
assertThat(expected1).isEqualTo(parts[0]);
|
assertThat(expected1).isEqualTo(parts[0]);
|
||||||
@@ -350,8 +329,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotNotPresent().arg(MultipartFile.class);
|
MethodParameter param = this.testMethod.annotNotPresent().arg(MultipartFile.class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
boolean condition = result instanceof MultipartFile;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(result).as("Invalid result").isEqualTo(expected);
|
assertThat(result).as("Invalid result").isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,8 +345,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
.annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
|
.annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
|
||||||
|
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
boolean condition = result instanceof List;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
|
assertThat(result).isEqualTo(Arrays.asList(expected1, expected2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,8 +399,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(Part.class);
|
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(Part.class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
boolean condition = result instanceof Part;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(result).as("Invalid result").isEqualTo(expected);
|
assertThat(result).as("Invalid result").isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,8 +406,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
void resolveDefaultValue() throws Exception {
|
void resolveDefaultValue() throws Exception {
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
boolean condition = result instanceof String;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(result).as("Invalid result").isEqualTo("bar");
|
assertThat(result).as("Invalid result").isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,7 +423,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
WebDataBinderFactory binderFactory = mock();
|
WebDataBinderFactory binderFactory = mock();
|
||||||
given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder);
|
given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder);
|
||||||
|
|
||||||
request.addParameter("stringNotAnnot", "");
|
request.addParameter("stringNotAnnot", "");
|
||||||
|
|
||||||
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
||||||
@@ -466,7 +436,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
WebDataBinderFactory binderFactory = mock();
|
WebDataBinderFactory binderFactory = mock();
|
||||||
given(binderFactory.createBinder(webRequest, null, "booleanParam")).willReturn(binder);
|
given(binderFactory.createBinder(webRequest, null, "booleanParam")).willReturn(binder);
|
||||||
|
|
||||||
request.addParameter("booleanParam", " ");
|
request.addParameter("booleanParam", " ");
|
||||||
|
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Boolean.class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Boolean.class);
|
||||||
@@ -481,7 +450,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
WebDataBinderFactory binderFactory = mock();
|
WebDataBinderFactory binderFactory = mock();
|
||||||
given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);
|
given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);
|
||||||
|
|
||||||
request.addParameter("name", "");
|
request.addParameter("name", "");
|
||||||
|
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired()).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired()).arg(String.class);
|
||||||
@@ -489,14 +457,13 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
assertThat(arg).isNull();
|
assertThat(arg).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-29550
|
@Test // gh-29550
|
||||||
public void missingRequestParamEmptyValueNotRequiredWithDefaultValue() throws Exception {
|
public void missingRequestParamEmptyValueNotRequiredWithDefaultValue() throws Exception {
|
||||||
WebDataBinder binder = new WebRequestDataBinder(null);
|
WebDataBinder binder = new WebRequestDataBinder(null);
|
||||||
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
|
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
|
||||||
|
|
||||||
WebDataBinderFactory binderFactory = mock();
|
WebDataBinderFactory binderFactory = mock();
|
||||||
given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);
|
given(binderFactory.createBinder(webRequest, null, "name")).willReturn(binder);
|
||||||
|
|
||||||
request.addParameter("name", " ");
|
request.addParameter("name", " ");
|
||||||
|
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||||
@@ -509,9 +476,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
request.setParameter("stringNotAnnot", "plainValue");
|
request.setParameter("stringNotAnnot", "plainValue");
|
||||||
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
Object result = resolver.resolveArgument(param, null, webRequest, null);
|
||||||
|
|
||||||
boolean condition = result instanceof String;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(result).isEqualTo("plainValue");
|
assertThat(result).isEqualTo("plainValue");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,9 +622,7 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, MultipartFile.class);
|
||||||
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
|
Object result = resolver.resolveArgument(param, null, webRequest, binderFactory);
|
||||||
|
assertThat(result instanceof Optional).isTrue();
|
||||||
boolean condition = result instanceof Optional;
|
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat(((Optional<?>) result).get()).as("Invalid result").isEqualTo(expected);
|
assertThat(((Optional<?>) result).get()).as("Invalid result").isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,8 +188,8 @@ class ControllerAdviceTests {
|
|||||||
TestController controller = context.getBean(TestController.class);
|
TestController controller = context.getBean(TestController.class);
|
||||||
controller.setException(exception);
|
controller.setException(exception);
|
||||||
|
|
||||||
Object actual = handle(adapter, controller, this.postExchange, Duration.ofMillis(100)
|
Object actual = handle(adapter, controller, this.postExchange, Duration.ofMillis(1000),
|
||||||
, "threadWithArg", String.class).getReturnValue();
|
"threadWithArg", String.class).getReturnValue();
|
||||||
assertThat(actual).isEqualTo(expected);
|
assertThat(actual).isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,6 +242,7 @@ class ControllerAdviceTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
static class TestController {
|
static class TestController {
|
||||||
|
|
||||||
@@ -249,7 +250,6 @@ class ControllerAdviceTests {
|
|||||||
|
|
||||||
private Throwable exception;
|
private Throwable exception;
|
||||||
|
|
||||||
|
|
||||||
void setValidator(Validator validator) {
|
void setValidator(Validator validator) {
|
||||||
this.validator = validator;
|
this.validator = validator;
|
||||||
}
|
}
|
||||||
@@ -258,7 +258,6 @@ class ControllerAdviceTests {
|
|||||||
this.exception = exception;
|
this.exception = exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@InitBinder
|
@InitBinder
|
||||||
public void initDataBinder(WebDataBinder dataBinder) {
|
public void initDataBinder(WebDataBinder dataBinder) {
|
||||||
if (this.validator != null) {
|
if (this.validator != null) {
|
||||||
@@ -291,6 +290,7 @@ class ControllerAdviceTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
@Order(1)
|
@Order(1)
|
||||||
static class OneControllerAdvice {
|
static class OneControllerAdvice {
|
||||||
@@ -323,6 +323,7 @@ class ControllerAdviceTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
@Order(2)
|
@Order(2)
|
||||||
static class SecondControllerAdvice {
|
static class SecondControllerAdvice {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import reactor.test.StepVerifier;
|
|||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.ReactiveAdapterRegistry;
|
import org.springframework.core.ReactiveAdapterRegistry;
|
||||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||||
import org.springframework.web.reactive.BindingContext;
|
import org.springframework.web.reactive.BindingContext;
|
||||||
@@ -58,7 +59,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setup() throws Exception {
|
void setup() throws Exception {
|
||||||
|
|
||||||
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
|
||||||
this.resolver = new RequestParamMethodArgumentResolver(null, adapterRegistry, true);
|
this.resolver = new RequestParamMethodArgumentResolver(null, adapterRegistry, true);
|
||||||
|
|
||||||
@@ -70,7 +70,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void supportsParameter() {
|
void supportsParameter() {
|
||||||
|
|
||||||
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
MethodParameter param = this.testMethod.annot(requestParam().notRequired("bar")).arg(String.class);
|
||||||
assertThat(this.resolver.supportsParameter(param)).isTrue();
|
assertThat(this.resolver.supportsParameter(param)).isTrue();
|
||||||
|
|
||||||
@@ -105,12 +104,12 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doesNotSupportReactiveWrapper() {
|
void doesNotSupportReactiveWrapper() {
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException()
|
||||||
this.resolver.supportsParameter(this.testMethod.annot(requestParam()).arg(Mono.class, String.class)))
|
.isThrownBy(() -> this.resolver.supportsParameter(this.testMethod.annot(requestParam()).arg(Mono.class, String.class)))
|
||||||
.withMessageStartingWith("RequestParamMethodArgumentResolver does not support reactive type wrapper");
|
.withMessageStartingWith("RequestParamMethodArgumentResolver does not support reactive type wrapper");
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException()
|
||||||
this.resolver.supportsParameter(this.testMethod.annotNotPresent(RequestParam.class).arg(Mono.class, String.class)))
|
.isThrownBy(() -> this.resolver.supportsParameter(this.testMethod.annotNotPresent(RequestParam.class).arg(Mono.class, String.class)))
|
||||||
.withMessageStartingWith("RequestParamMethodArgumentResolver does not support reactive type wrapper");
|
.withMessageStartingWith("RequestParamMethodArgumentResolver does not support reactive type wrapper");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -125,19 +124,15 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/path?name=foo&name=bar").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?name=foo&name=bar").build();
|
||||||
Object result = resolve(param, MockServerWebExchange.from(request));
|
Object result = resolve(param, MockServerWebExchange.from(request));
|
||||||
boolean condition = result instanceof String[];
|
assertThat(result).isEqualTo(new String[] {"foo", "bar"});
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat((String[]) result).isEqualTo(new String[] {"foo", "bar"});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-32577
|
@Test // gh-32577
|
||||||
void resolveStringArrayWithEmptyArraySuffix() {
|
void resolveStringArrayWithEmptyArraySuffix() {
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
||||||
MockServerHttpRequest request = MockServerHttpRequest.get("/path?name[]=foo&name[]=bar").build();
|
MockServerHttpRequest request = MockServerHttpRequest.get("/path?name[]=foo&name[]=bar").build();
|
||||||
Object result = resolve(param, MockServerWebExchange.from(request));
|
Object result = resolve(param, MockServerWebExchange.from(request));
|
||||||
boolean condition = result instanceof String[];
|
assertThat(result).isEqualTo(new String[] {"foo", "bar"});
|
||||||
assertThat(condition).isTrue();
|
|
||||||
assertThat((String[]) result).isEqualTo(new String[] {"foo", "bar"});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -146,7 +141,7 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
assertThat(resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/")))).isEqualTo("bar");
|
assertThat(resolve(param, MockServerWebExchange.from(MockServerHttpRequest.get("/")))).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // SPR-17050
|
@Test // SPR-17050
|
||||||
public void resolveAndConvertNullValue() {
|
public void resolveAndConvertNullValue() {
|
||||||
MethodParameter param = this.testMethod
|
MethodParameter param = this.testMethod
|
||||||
.annot(requestParam().notRequired())
|
.annot(requestParam().notRequired())
|
||||||
@@ -156,7 +151,6 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void missingRequestParam() {
|
void missingRequestParam() {
|
||||||
|
|
||||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/"));
|
||||||
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(String[].class);
|
||||||
Mono<Object> mono = this.resolver.resolveArgument(param, this.bindContext, exchange);
|
Mono<Object> mono = this.resolver.resolveArgument(param, this.bindContext, exchange);
|
||||||
@@ -221,6 +215,7 @@ class RequestParamMethodArgumentResolverTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Object resolve(MethodParameter parameter, ServerWebExchange exchange) {
|
private Object resolve(MethodParameter parameter, ServerWebExchange exchange) {
|
||||||
return this.resolver.resolveArgument(parameter, this.bindContext, exchange).block(Duration.ZERO);
|
return this.resolver.resolveArgument(parameter, this.bindContext, exchange).block(Duration.ZERO);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user