Deprecate use of PathMatcher and UrlPathHelper in web

Closes gh-34018
This commit is contained in:
rstoyanchev
2024-12-18 17:22:06 +00:00
parent 41a9db376d
commit 373763723e
56 changed files with 352 additions and 44 deletions
@@ -78,6 +78,7 @@ class AnnotationDrivenBeanDefinitionParserTests {
.asInstanceOf(BOOLEAN).isTrue();
}
@SuppressWarnings("removal")
@Test
public void testPathMatchingConfiguration() {
loadBeanDefinitions("mvc-config-path-matching.xml");
@@ -196,6 +196,7 @@ public class MvcNamespaceTests {
}
@SuppressWarnings("removal")
@Test
void testDefaultConfig() throws Exception {
loadBeanDefinitions("mvc-config.xml");
@@ -325,6 +326,7 @@ public class MvcNamespaceTests {
doTestCustomValidator("mvc-config-custom-validator.xml");
}
@SuppressWarnings("removal")
private void doTestCustomValidator(String xml) throws Exception {
loadBeanDefinitions(xml);
@@ -379,6 +381,7 @@ public class MvcNamespaceTests {
assertThat(chain.getInterceptorList()).hasSize(3);
}
@SuppressWarnings("removal")
@Test
void testResources() throws Exception {
loadBeanDefinitions("mvc-config-resources.xml");
@@ -425,6 +428,7 @@ public class MvcNamespaceTests {
.isInstanceOf(NoResourceFoundException.class);
}
@SuppressWarnings("removal")
@Test
void testUseDeprecatedPathMatcher() throws Exception {
loadBeanDefinitions("mvc-config-deprecated-path-matcher.xml");
@@ -437,6 +441,7 @@ public class MvcNamespaceTests {
});
}
@SuppressWarnings("removal")
@Test
void testUsePathPatternParser() throws Exception {
loadBeanDefinitions("mvc-config-custom-pattern-parser.xml");
@@ -465,6 +470,7 @@ public class MvcNamespaceTests {
assertThat(handler.getCacheSeconds()).isEqualTo(3600);
}
@SuppressWarnings("removal")
@Test
void testResourcesWithResolversTransformers() {
loadBeanDefinitions("mvc-config-resources-chain.xml");
@@ -615,6 +621,7 @@ public class MvcNamespaceTests {
assertThat(interceptor2.getParamName()).isEqualTo("style");
}
@SuppressWarnings("removal")
@Test
void testViewControllers() throws Exception {
loadBeanDefinitions("mvc-config-view-controllers.xml");
@@ -911,6 +918,7 @@ public class MvcNamespaceTests {
assertThat(compositeResolver.getOrder()).isEqualTo(123);
}
@SuppressWarnings("removal")
@Test
void testPathMatchingHandlerMappings() {
loadBeanDefinitions("mvc-config-path-matching-mappings.xml");
@@ -70,6 +70,7 @@ class DelegatingWebMvcConfigurationIntegrationTests {
"mvcContentNegotiationManager", "testContentNegotiationManager");
}
@SuppressWarnings("removal")
@Test
void viewControllerHandlerMappingUsesMvcInfrastructureByDefault() {
load(context -> context.registerBean(ViewControllerConfiguration.class));
@@ -78,6 +79,7 @@ class DelegatingWebMvcConfigurationIntegrationTests {
assertThat(handlerMapping.getUrlPathHelper()).isSameAs(this.context.getBean("mvcUrlPathHelper"));
}
@SuppressWarnings("removal")
@Test
void viewControllerHandlerMappingWithPrimaryUsesQualifiedPathMatcher() {
load(registerPrimaryBean("testPathMatcher", PathMatcher.class)
@@ -88,6 +90,7 @@ class DelegatingWebMvcConfigurationIntegrationTests {
"mvcPathMatcher", "testPathMatcher");
}
@SuppressWarnings("removal")
@Test
void viewControllerHandlerMappingWithPrimaryUsesQualifiedUrlPathHelper() {
load(registerPrimaryBean("testUrlPathHelper", UrlPathHelper.class)
@@ -98,6 +101,7 @@ class DelegatingWebMvcConfigurationIntegrationTests {
"mvcUrlPathHelper", "testUrlPathHelper");
}
@SuppressWarnings("removal")
@Test
void resourceHandlerMappingUsesMvcInfrastructureByDefault() {
load(context -> context.registerBean(ResourceHandlerConfiguration.class));
@@ -106,6 +110,7 @@ class DelegatingWebMvcConfigurationIntegrationTests {
assertThat(handlerMapping.getUrlPathHelper()).isSameAs(this.context.getBean("mvcUrlPathHelper"));
}
@SuppressWarnings("removal")
@Test
void resourceHandlerMappingWithPrimaryUsesQualifiedPathMatcher() {
load(registerPrimaryBean("testPathMatcher", PathMatcher.class)
@@ -116,6 +121,7 @@ class DelegatingWebMvcConfigurationIntegrationTests {
"mvcPathMatcher", "testPathMatcher");
}
@SuppressWarnings("removal")
@Test
void resourceHandlerMappingWithPrimaryUsesQualifiedUrlPathHelper() {
load(registerPrimaryBean("testUrlPathHelper", UrlPathHelper.class)
@@ -230,15 +230,15 @@ public class DelegatingWebMvcConfigurationTests {
assertThat(resolver.getErrorResponseInterceptors()).containsExactly(interceptor);
}
@SuppressWarnings("removal")
@Test
@SuppressWarnings("deprecation")
public void configurePathMatcher() {
PathMatcher pathMatcher = mock();
UrlPathHelper pathHelper = mock();
WebMvcConfigurer configurer = new WebMvcConfigurer() {
@Override
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUrlPathHelper(pathHelper).setPathMatcher(pathMatcher);
}
@@ -293,6 +293,7 @@ public class DelegatingWebMvcConfigurationTests {
configAssertion.accept(webMvcConfig.mvcUrlPathHelper(), webMvcConfig.mvcPathMatcher());
}
@SuppressWarnings("removal")
@Test
void configurePathPatternParser() {
PathPatternParser patternParser = new PathPatternParser();
@@ -300,6 +301,7 @@ public class DelegatingWebMvcConfigurationTests {
UrlPathHelper pathHelper = mock();
WebMvcConfigurer configurer = new WebMvcConfigurer() {
@SuppressWarnings("removal")
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setPatternParser(patternParser)
@@ -120,6 +120,7 @@ public class InterceptorRegistryTests {
verifyWebInterceptor(interceptors.get(1), this.webInterceptor2);
}
@SuppressWarnings("removal")
@Test
void addInterceptorsWithCustomPathMatcher() {
PathMatcher pathMatcher = mock();
@@ -60,6 +60,7 @@ class ResourceHandlerRegistryTests {
private MockHttpServletResponse response;
@SuppressWarnings("removal")
@BeforeEach
void setup() {
GenericWebApplicationContext appContext = new GenericWebApplicationContext();
@@ -202,6 +203,7 @@ class ResourceHandlerRegistryTests {
assertThat(transformers).containsExactly(cachingTransformer, cssLinkTransformer);
}
@SuppressWarnings("removal")
@Test
void urlResourceWithCharset() {
this.registration.addResourceLocations("[charset=ISO-8859-1]file:///tmp/");
@@ -123,6 +123,7 @@ class WebMvcConfigurationSupportExtensionTests {
this.config.setServletContext(this.context.getServletContext());
}
@SuppressWarnings("removal")
@Test
void handlerMappings() throws Exception {
RequestMappingHandlerMapping rmHandlerMapping = this.config.requestMappingHandlerMapping(
@@ -414,6 +415,7 @@ class WebMvcConfigurationSupportExtensionTests {
exceptionResolvers.add(0, new ResponseStatusExceptionResolver());
}
@SuppressWarnings("removal")
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setPathMatcher(new TestPathMatcher());
@@ -116,6 +116,7 @@ class BeanNameUrlHandlerMappingTests {
assertThat(hec != null && hec.getHandler() == bean).as("Handler is correct bean").isTrue();
}
@SuppressWarnings("removal")
@Test
void requestsWithFullPaths() throws Exception {
@@ -138,6 +138,7 @@ class HandlerMappingIntrospectorTests {
assertThat(initIntrospector(context).allHandlerMappingsUsePathPatternParser()).isFalse();
}
@SuppressWarnings("removal")
@ParameterizedTest
@ValueSource(booleans = {true, false})
void getMatchable(boolean usePathPatterns) throws Exception {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 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.
@@ -97,6 +97,7 @@ class MappedInterceptorTests {
assertThat(interceptor.matches(requestFactory.apply("/path3/foo/bar/path2"))).isFalse();
}
@SuppressWarnings("removal")
@PathPatternsParameterizedTest
void customPathMatcher(Function<String, MockHttpServletRequest> requestFactory) {
MappedInterceptor interceptor = new MappedInterceptor(new String[] { "/foo/[0-9]*" }, null, delegate);
@@ -65,6 +65,7 @@ class SimpleUrlHandlerMappingTests {
.isInstanceOf(NoSuchBeanDefinitionException.class);
}
@SuppressWarnings("removal")
@Test
void newlineInRequestShouldMatch() throws Exception {
Object controller = new Object();
@@ -103,6 +103,7 @@ class WebContentInterceptorTests {
assertThat(cacheControlHeaders).isEmpty();
}
@SuppressWarnings("removal")
@Test
void throwsExceptionWithNullPathMatcher() {
assertThatIllegalArgumentException()
@@ -30,6 +30,7 @@ import static org.assertj.core.api.InstanceOfAssertFactories.STRING;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("removal")
class PatternsRequestConditionTests {
@Test
@@ -75,7 +75,7 @@ import static org.junit.jupiter.api.Named.named;
*/
class RequestMappingInfoHandlerMappingTests {
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "removal"})
static Stream<?> pathPatternsArguments() {
TestController controller = new TestController();
@@ -259,7 +259,7 @@ class RequestMappingInfoHandlerMappingTests {
assertThat(chain).isNull();
}
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "removal"})
@PathPatternsParameterizedTest
void handleMatchUriTemplateVariables(TestRequestMappingInfoHandlerMapping mapping) {
RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration();
@@ -278,7 +278,7 @@ class RequestMappingInfoHandlerMappingTests {
assertThat(uriVariables.get("path2")).isEqualTo("2");
}
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "removal"})
@PathPatternsParameterizedTest // SPR-9098
void handleMatchUriTemplateVariablesDecode(TestRequestMappingInfoHandlerMapping mapping) {
RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration();
@@ -302,6 +302,7 @@ class RequestMappingInfoHandlerMappingTests {
assertThat(uriVariables.get("identifier")).isEqualTo("a/b");
}
@SuppressWarnings("removal")
@PathPatternsParameterizedTest
void handleMatchBestMatchingPatternAttribute(TestRequestMappingInfoHandlerMapping mapping) {
RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration();
@@ -314,6 +315,7 @@ class RequestMappingInfoHandlerMappingTests {
assertThat(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)).isEqualTo("/{path1}/2");
}
@SuppressWarnings("removal")
@PathPatternsParameterizedTest
void handleMatchBestMatchingPatternAttributeInObservationContext(TestRequestMappingInfoHandlerMapping mapping) {
RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration();
@@ -402,6 +404,7 @@ class RequestMappingInfoHandlerMappingTests {
}
}
@SuppressWarnings("removal")
@PathPatternsParameterizedTest // SPR-10140, SPR-16867
void handleMatchMatrixVariablesDecoding(TestRequestMappingInfoHandlerMapping mapping) {
@@ -616,6 +619,7 @@ class RequestMappingInfoHandlerMappingTests {
}
}
@SuppressWarnings("removal")
private RequestMappingInfo.BuilderConfiguration getBuilderConfig() {
RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration();
if (getPatternParser() != null) {
@@ -48,7 +48,7 @@ import static org.springframework.web.bind.annotation.RequestMethod.HEAD;
*/
class RequestMappingInfoTests {
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "removal"})
static Stream<Named<RequestMappingInfo.Builder>> pathPatternsArguments() {
RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration();
config.setPathMatcher(new AntPathMatcher());
@@ -59,6 +59,7 @@ class RequestMappingInfoTests {
}
@SuppressWarnings({"removal", "DataFlowIssue"})
@PathPatternsParameterizedTest
void createEmpty(RequestMappingInfo.Builder infoBuilder) {
@@ -92,6 +93,7 @@ class RequestMappingInfoTests {
assertThat(info.getCustomCondition()).isSameAs(result.getCustomCondition());
}
@SuppressWarnings("removal")
@Test // gh-31662
void pathPatternByDefault() {
RequestMappingInfo info = RequestMappingInfo.paths().build();
@@ -319,6 +321,7 @@ class RequestMappingInfoTests {
assertThat(match).as("Pre-flight should match the ACCESS_CONTROL_REQUEST_METHOD").isNull();
}
@SuppressWarnings("removal")
@Test
void mutate() {
RequestMappingInfo.BuilderConfiguration options = new RequestMappingInfo.BuilderConfiguration();
@@ -593,6 +593,7 @@ class CrossOriginTests {
return AnnotationUtils.findAnnotation(beanType, Controller.class) != null;
}
@SuppressWarnings("removal")
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
RequestMapping annotation = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
@@ -143,6 +143,7 @@ class RequestMappingHandlerMappingTests {
assertThat(info.getActivePatternsCondition().getMatchingCondition(request)).isNull();
}
@SuppressWarnings("removal")
private void initRequestPath(RequestMappingHandlerMapping mapping, MockHttpServletRequest request) {
PathPatternParser parser = mapping.getPatternParser();
if (parser != null) {
@@ -149,6 +149,7 @@ class PathResourceResolverTests {
assertThat(path).isNull();
}
@SuppressWarnings("removal")
@Test
void relativePathEncodedForUrlResource() throws Exception {
TestUrlResource location = new TestUrlResource("file:///tmp");
@@ -229,6 +229,7 @@ class ResourceHttpRequestHandlerIntegrationTests {
static class DecodingUrlPathHelperConfig implements WebMvcConfigurer {
@SuppressWarnings("removal")
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
UrlPathHelper helper = new UrlPathHelper();
@@ -240,6 +241,7 @@ class ResourceHttpRequestHandlerIntegrationTests {
static class NonDecodingUrlPathHelperConfig implements WebMvcConfigurer {
@SuppressWarnings("removal")
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
UrlPathHelper helper = new UrlPathHelper();