Merge branch '6.1.x'
This commit is contained in:
@@ -53,8 +53,6 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
*/
|
||||
class AspectJExpressionPointcutTests {
|
||||
|
||||
public static final String MATCH_ALL_METHODS = "execution(* *(..))";
|
||||
|
||||
private Method getAge;
|
||||
|
||||
private Method setAge;
|
||||
@@ -175,25 +173,25 @@ class AspectJExpressionPointcutTests {
|
||||
@Test
|
||||
void testFriendlyErrorOnNoLocationClassMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
pc.matches(ITestBean.class))
|
||||
.withMessageContaining("expression");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> pc.matches(ITestBean.class))
|
||||
.withMessageContaining("expression");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFriendlyErrorOnNoLocation2ArgMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
pc.matches(getAge, ITestBean.class))
|
||||
.withMessageContaining("expression");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> pc.matches(getAge, ITestBean.class))
|
||||
.withMessageContaining("expression");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFriendlyErrorOnNoLocation3ArgMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
pc.matches(getAge, ITestBean.class, (Object[]) null))
|
||||
.withMessageContaining("expression");
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> pc.matches(getAge, ITestBean.class, (Object[]) null))
|
||||
.withMessageContaining("expression");
|
||||
}
|
||||
|
||||
|
||||
@@ -210,8 +208,10 @@ class AspectJExpressionPointcutTests {
|
||||
// not currently testable in a reliable fashion
|
||||
//assertDoesNotMatchStringClass(classFilter);
|
||||
|
||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 12D)).as("Should match with setSomeNumber with Double input").isTrue();
|
||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 11)).as("Should not match setSomeNumber with Integer input").isFalse();
|
||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 12D))
|
||||
.as("Should match with setSomeNumber with Double input").isTrue();
|
||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, 11))
|
||||
.as("Should not match setSomeNumber with Integer input").isFalse();
|
||||
assertThat(methodMatcher.matches(getAge, TestBean.class)).as("Should not match getAge").isFalse();
|
||||
assertThat(methodMatcher.isRuntime()).as("Should be a runtime match").isTrue();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,6 @@ import jakarta.servlet.http.PushBuilder;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
@@ -68,21 +67,6 @@ import org.springframework.web.servlet.support.RequestContextUtils;
|
||||
*/
|
||||
public class ServletRequestMethodArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
@Nullable
|
||||
private static Class<?> pushBuilder;
|
||||
|
||||
static {
|
||||
try {
|
||||
pushBuilder = ClassUtils.forName("jakarta.servlet.http.PushBuilder",
|
||||
ServletRequestMethodArgumentResolver.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// Servlet 4.0 PushBuilder not found - not supported for injection
|
||||
pushBuilder = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
Class<?> paramType = parameter.getParameterType();
|
||||
@@ -90,7 +74,7 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
|
||||
ServletRequest.class.isAssignableFrom(paramType) ||
|
||||
MultipartRequest.class.isAssignableFrom(paramType) ||
|
||||
HttpSession.class.isAssignableFrom(paramType) ||
|
||||
(pushBuilder != null && pushBuilder.isAssignableFrom(paramType)) ||
|
||||
PushBuilder.class.isAssignableFrom(paramType) ||
|
||||
(Principal.class.isAssignableFrom(paramType) && !parameter.hasParameterAnnotations()) ||
|
||||
InputStream.class.isAssignableFrom(paramType) ||
|
||||
Reader.class.isAssignableFrom(paramType) ||
|
||||
@@ -143,8 +127,13 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
|
||||
}
|
||||
return session;
|
||||
}
|
||||
else if (pushBuilder != null && pushBuilder.isAssignableFrom(paramType)) {
|
||||
return PushBuilderDelegate.resolvePushBuilder(request, paramType);
|
||||
else if (PushBuilder.class.isAssignableFrom(paramType)) {
|
||||
PushBuilder pushBuilder = request.newPushBuilder();
|
||||
if (pushBuilder != null && !paramType.isInstance(pushBuilder)) {
|
||||
throw new IllegalStateException(
|
||||
"Current push builder is not of type [" + paramType.getName() + "]: " + pushBuilder);
|
||||
}
|
||||
return pushBuilder;
|
||||
}
|
||||
else if (InputStream.class.isAssignableFrom(paramType)) {
|
||||
InputStream inputStream = request.getInputStream();
|
||||
@@ -189,22 +178,4 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
|
||||
throw new UnsupportedOperationException("Unknown parameter type: " + paramType.getName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on Servlet API 4.0 at runtime.
|
||||
*/
|
||||
private static class PushBuilderDelegate {
|
||||
|
||||
@Nullable
|
||||
public static Object resolvePushBuilder(HttpServletRequest request, Class<?> paramType) {
|
||||
PushBuilder pushBuilder = request.newPushBuilder();
|
||||
if (pushBuilder != null && !paramType.isInstance(pushBuilder)) {
|
||||
throw new IllegalStateException(
|
||||
"Current push builder is not of type [" + paramType.getName() + "]: " + pushBuilder);
|
||||
}
|
||||
return pushBuilder;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user