From 373763723ee7dcc9dd39c9cba7e1ed093966360f Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Wed, 18 Dec 2024 17:22:06 +0000 Subject: [PATCH] Deprecate use of PathMatcher and UrlPathHelper in web Closes gh-34018 --- .../ann-methods/matrix-variables.adoc | 4 +-- .../setup/RouterFunctionMockMvcBuilder.java | 6 ++-- .../setup/StandaloneMockMvcBuilder.java | 12 ++++++-- .../servlet/samples/spr/EncodedUriTests.java | 3 +- .../cors/UrlBasedCorsConfigurationSource.java | 14 ++++++++- .../UrlBasedCorsConfigurationSourceTests.java | 1 + .../annotation/InterceptorRegistration.java | 9 +++++- .../annotation/PathMatchConfigurer.java | 29 ++++++++++++++----- .../annotation/ResourceHandlerRegistry.java | 4 +++ .../WebMvcConfigurationSupport.java | 13 +++++++++ .../support/RouterFunctionMapping.java | 2 ++ .../handler/AbstractHandlerMapping.java | 25 +++++++++++++++- .../handler/AbstractHandlerMethodMapping.java | 1 + .../handler/AbstractUrlHandlerMapping.java | 3 ++ .../handler/HandlerMappingIntrospector.java | 2 ++ .../servlet/handler/MappedInterceptor.java | 8 +++++ .../handler/MatchableHandlerMapping.java | 8 ++++- .../PathPatternMatchableHandlerMapping.java | 4 ++- .../servlet/handler/RequestMatchResult.java | 10 +++++-- .../mvc/AbstractUrlViewController.java | 24 ++++++++++++++- .../servlet/mvc/WebContentInterceptor.java | 16 ++++++++-- .../condition/PatternsRequestCondition.java | 4 +++ .../mvc/method/RequestMappingInfo.java | 28 +++++++++++++++++- .../RequestMappingInfoHandlerMapping.java | 3 ++ .../RequestMappingHandlerMapping.java | 4 ++- ...vletCookieValueMethodArgumentResolver.java | 15 +++++++--- .../resource/PathResourceResolver.java | 10 +++++++ .../resource/ResourceHttpRequestHandler.java | 11 +++++++ .../resource/ResourceTransformerSupport.java | 3 +- .../resource/ResourceUrlEncodingFilter.java | 1 + .../servlet/resource/ResourceUrlProvider.java | 17 +++++++++++ .../support/AbstractFlashMapManager.java | 10 +++++++ .../web/servlet/support/RequestContext.java | 10 +++++++ ...tationDrivenBeanDefinitionParserTests.java | 1 + .../web/servlet/config/MvcNamespaceTests.java | 8 +++++ ...ngWebMvcConfigurationIntegrationTests.java | 6 ++++ .../DelegatingWebMvcConfigurationTests.java | 6 ++-- .../annotation/InterceptorRegistryTests.java | 1 + .../ResourceHandlerRegistryTests.java | 2 ++ ...MvcConfigurationSupportExtensionTests.java | 2 ++ .../BeanNameUrlHandlerMappingTests.java | 1 + .../HandlerMappingIntrospectorTests.java | 1 + .../handler/MappedInterceptorTests.java | 3 +- .../handler/SimpleUrlHandlerMappingTests.java | 1 + .../mvc/WebContentInterceptorTests.java | 1 + .../PatternsRequestConditionTests.java | 1 + ...RequestMappingInfoHandlerMappingTests.java | 10 +++++-- .../mvc/method/RequestMappingInfoTests.java | 5 +++- .../method/annotation/CrossOriginTests.java | 1 + .../RequestMappingHandlerMappingTests.java | 1 + .../resource/PathResourceResolverTests.java | 1 + ...rceHttpRequestHandlerIntegrationTests.java | 2 ++ .../ServletWebSocketHandlerRegistry.java | 10 ++++++- .../annotation/StompEndpointRegistry.java | 8 ++++- .../WebMvcStompEndpointRegistry.java | 9 ++++++ .../WebMvcStompEndpointRegistryTests.java | 1 + 56 files changed, 352 insertions(+), 44 deletions(-) diff --git a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-methods/matrix-variables.adoc b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-methods/matrix-variables.adoc index 440bc376ed8..24706215717 100644 --- a/framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-methods/matrix-variables.adoc +++ b/framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-methods/matrix-variables.adoc @@ -157,9 +157,7 @@ Kotlin:: ---- ====== -Note that you need to enable the use of matrix variables. In the MVC Java configuration, -you need to set a `UrlPathHelper` with `removeSemicolonContent=false` through -xref:web/webmvc/mvc-config/path-matching.adoc[Path Matching]. In the MVC XML namespace, you can set +Note that you need to enable the use of matrix variables. In the MVC XML namespace, you can set ``. diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/RouterFunctionMockMvcBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/RouterFunctionMockMvcBuilder.java index 716657637d1..7f3ea90a693 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/RouterFunctionMockMvcBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/RouterFunctionMockMvcBuilder.java @@ -188,9 +188,9 @@ public class RouterFunctionMockMvcBuilder extends AbstractMockMvcBuilderBy default, this is a default instance of {@link PathPatternParser}. * @param parser the parser to use */ public RouterFunctionMockMvcBuilder setPatternParser(@Nullable PathPatternParser parser) { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java index 3b465eceeb6..b72d584fbe5 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java @@ -37,6 +37,7 @@ import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.format.support.FormattingConversionService; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.mock.web.MockServletContext; +import org.springframework.util.PathMatcher; import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; import org.springframework.util.StringValueResolver; @@ -297,9 +298,9 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilderBy default, this is a default instance of {@link PathPatternParser}. * @param parser the parser to use * @since 5.3 */ @@ -313,7 +314,11 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilderBy default this is {@link UrlPathHelper#defaultInstance}. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setUrlPathHelper(UrlPathHelper urlPathHelper) { Assert.notNull(urlPathHelper, "UrlPathHelper must not be null"); this.urlPathHelper = urlPathHelper; @@ -167,7 +171,11 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource * @param allowInitLookupPath whether to disable lazy initialization * and fail if not already resolved * @since 5.3 + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setAllowInitLookupPath(boolean allowInitLookupPath) { this.allowInitLookupPath = allowInitLookupPath; } @@ -194,7 +202,11 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource * String pattern matching even when a * {@link ServletRequestPathUtils#parseAndCache parsed} {@code RequestPath} * is available. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setPathMatcher(PathMatcher pathMatcher) { this.pathMatcher = pathMatcher; } diff --git a/spring-web/src/test/java/org/springframework/web/cors/UrlBasedCorsConfigurationSourceTests.java b/spring-web/src/test/java/org/springframework/web/cors/UrlBasedCorsConfigurationSourceTests.java index a101c442342..30cb76141ac 100644 --- a/spring-web/src/test/java/org/springframework/web/cors/UrlBasedCorsConfigurationSourceTests.java +++ b/spring-web/src/test/java/org/springframework/web/cors/UrlBasedCorsConfigurationSourceTests.java @@ -71,6 +71,7 @@ class UrlBasedCorsConfigurationSourceTests { .isThrownBy(() -> source.getCorsConfigurations().put("/**", new CorsConfiguration())); } + @SuppressWarnings("removal") @Test void allowInitLookupPath() { CorsConfiguration config = new CorsConfiguration(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java index af3e7280bcc..598ffc5c7a0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java @@ -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. @@ -29,7 +29,9 @@ import org.springframework.util.StringUtils; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.handler.MappedInterceptor; import org.springframework.web.util.ServletRequestPathUtils; +import org.springframework.web.util.UrlPathHelper; import org.springframework.web.util.pattern.PathPattern; +import org.springframework.web.util.pattern.PathPatternParser; /** * Assists with the creation of a {@link MappedInterceptor}. @@ -114,7 +116,11 @@ public class InterceptorRegistration { * String pattern matching even when a * {@link ServletRequestPathUtils#parseAndCache parsed} {@code RequestPath} * is available. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public InterceptorRegistration pathMatcher(PathMatcher pathMatcher) { this.pathMatcher = pathMatcher; return this; @@ -140,6 +146,7 @@ public class InterceptorRegistration { * Build the underlying interceptor. If URL patterns are provided, the returned * type is {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}. */ + @SuppressWarnings("removal") protected Object getInterceptor() { if (this.includePatterns == null && this.excludePatterns == null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java index 24c73e6b112..625e2b4c0c6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java @@ -65,12 +65,6 @@ public class PathMatchConfigurer { * Set the {@link PathPatternParser} to parse {@link PathPattern patterns} * with for URL path matching. Parsed patterns provide a more modern and * efficient alternative to String path matching via {@link AntPathMatcher}. - *

Note: This property is mutually exclusive with the - * following other, {@code AntPathMatcher} related properties: - *

    - *
  • {@link #setUrlPathHelper(UrlPathHelper)} - *
  • {@link #setPathMatcher(PathMatcher)} - *
*

By default, as of 6.0, a {@link PathPatternParser} with default * settings is used, which enables parsed {@link PathPattern patterns}. * Set this property to {@code null} to fall back on String path matching via @@ -110,9 +104,13 @@ public class PathMatchConfigurer { * {@link #setPatternParser(PathPatternParser)}. If set, it enables use of * String path matching, unless a {@code PathPatternParser} is also * explicitly set in which case this property is ignored. - *

By default this is an instance of {@link UrlPathHelper} with default + *

By default, this is an instance of {@link UrlPathHelper} with default * settings. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public PathMatchConfigurer setUrlPathHelper(UrlPathHelper urlPathHelper) { this.urlPathHelper = urlPathHelper; this.preferPathMatcher = true; @@ -125,9 +123,12 @@ public class PathMatchConfigurer { * {@link #setPatternParser(PathPatternParser)}. If set, it enables use of * String path matching, unless a {@code PathPatternParser} is also * explicitly set in which case this property is ignored. - *

By default this is an instance of {@link AntPathMatcher} with default + *

By default, this is an instance of {@link AntPathMatcher} with default * settings. + * @deprecated use of {@link PathMatcher} is deprecated for use at runtime + * in web modules in favor of parsed patterns with {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public PathMatchConfigurer setPathMatcher(PathMatcher pathMatcher) { this.pathMatcher = pathMatcher; this.preferPathMatcher = true; @@ -143,7 +144,10 @@ public class PathMatchConfigurer { * {@link PathMatcher} related option is explicitly set. * * @since 6.0 + * @deprecated use of {@link PathMatcher} is deprecated for use at runtime + * in web modules in favor of parsed patterns with {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) protected boolean preferPathMatcher() { return (this.patternParser == null && this.preferPathMatcher); } @@ -160,10 +164,12 @@ public class PathMatchConfigurer { return this.pathPrefixes; } + @Deprecated(since = "7.0", forRemoval = true) public @Nullable UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } + @Deprecated(since = "7.0", forRemoval = true) public @Nullable PathMatcher getPathMatcher() { return this.pathMatcher; } @@ -171,7 +177,11 @@ public class PathMatchConfigurer { /** * Return the configured UrlPathHelper or a default, shared instance otherwise. * @since 5.3 + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) protected UrlPathHelper getUrlPathHelperOrDefault() { if (this.urlPathHelper != null) { return this.urlPathHelper; @@ -185,7 +195,10 @@ public class PathMatchConfigurer { /** * Return the configured PathMatcher or a default, shared instance otherwise. * @since 5.3 + * @deprecated use of {@link PathMatcher} is deprecated for use at runtime + * in web modules in favor of parsed patterns with {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) protected PathMatcher getPathMatcherOrDefault() { if (this.pathMatcher != null) { return this.pathMatcher; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java index 9bb9d4f25df..a0f74e8094e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistry.java @@ -100,7 +100,10 @@ public class ResourceHandlerRegistry { * {@link #ResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)} * that also accepts the {@link UrlPathHelper} used for mapping requests to static resources. * @since 4.3.13 + * @deprecated in favor of + * {@link #ResourceHandlerRegistry(ApplicationContext, ServletContext, ContentNegotiationManager)} */ + @Deprecated(since = "7.0", forRemoval = true) public ResourceHandlerRegistry(ApplicationContext applicationContext, ServletContext servletContext, @Nullable ContentNegotiationManager contentNegotiationManager, @Nullable UrlPathHelper pathHelper) { @@ -167,6 +170,7 @@ public class ResourceHandlerRegistry { return new SimpleUrlHandlerMapping(urlMap, this.order); } + @SuppressWarnings("removal") private ResourceHttpRequestHandler getRequestHandler(ResourceHandlerRegistration registration) { ResourceHttpRequestHandler handler = registration.getRequestHandler(); if (this.pathHelper != null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java index aa4888cb450..387ce6c4050 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java @@ -391,7 +391,12 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv *

Note: This is only used when parsed patterns are not * {@link PathMatchConfigurer#setPatternParser enabled}. * @since 4.1 + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) @Bean public UrlPathHelper mvcUrlPathHelper() { return getPathMatchConfigurer().getUrlPathHelperOrDefault(); @@ -404,7 +409,12 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv *

Note: This is only used when parsed patterns are not * {@link PathMatchConfigurer#setPatternParser enabled}. * @since 4.1 + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) @Bean public PathMatcher mvcPathMatcher() { return getPathMatchConfigurer().getPathMatcherOrDefault(); @@ -474,6 +484,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv return mapping; } + @SuppressWarnings("removal") private void initHandlerMapping( @Nullable AbstractHandlerMapping mapping, FormattingConversionService conversionService, ResourceUrlProvider resourceUrlProvider) { @@ -554,6 +565,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv * resource handlers. To configure resource handling, override * {@link #addResourceHandlers}. */ + @SuppressWarnings("removal") @Bean public @Nullable HandlerMapping resourceHandlerMapping( @Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager, @@ -585,6 +597,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv * A {@link ResourceUrlProvider} bean for use with the MVC dispatcher. * @since 4.1 */ + @SuppressWarnings("removal") @Bean public ResourceUrlProvider mvcResourceUrlProvider() { ResourceUrlProvider urlProvider = new ResourceUrlProvider(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java index d93579a219a..6a67ff7e116 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java @@ -222,6 +222,8 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini servletRequest.setAttribute(RouterFunctions.REQUEST_ATTRIBUTE, request); } + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) @Override public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) { throw new UnsupportedOperationException("This HandlerMapping uses PathPatterns"); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index 30119647386..dfe5e6262d8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -179,6 +179,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @see org.springframework.web.util.UrlPathHelper#setAlwaysUseFullPath(boolean) * @deprecated as of 6.0, in favor of using {@link #setUrlPathHelper(UrlPathHelper)} */ + @SuppressWarnings("removal") @Deprecated(since = "6.0") public void setAlwaysUseFullPath(boolean alwaysUseFullPath) { this.urlPathHelper.setAlwaysUseFullPath(alwaysUseFullPath); @@ -194,6 +195,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @see org.springframework.web.util.UrlPathHelper#setUrlDecode(boolean) * @deprecated as of 6.0, in favor of using {@link #setUrlPathHelper(UrlPathHelper)} */ + @SuppressWarnings("removal") @Deprecated(since = "6.0") public void setUrlDecode(boolean urlDecode) { this.urlPathHelper.setUrlDecode(urlDecode); @@ -209,6 +211,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @see org.springframework.web.util.UrlPathHelper#setRemoveSemicolonContent(boolean) * @deprecated as of 6.0, in favor of using {@link #setUrlPathHelper(UrlPathHelper)} */ + @SuppressWarnings("removal") @Deprecated(since = "6.0") public void setRemoveSemicolonContent(boolean removeSemicolonContent) { this.urlPathHelper.setRemoveSemicolonContent(removeSemicolonContent); @@ -221,7 +224,12 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * Configure the UrlPathHelper to use for resolution of lookup paths. *

Note: This property is mutually exclusive with and * ignored when {@link #setPatternParser(PathPatternParser)} is set. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) public void setUrlPathHelper(UrlPathHelper urlPathHelper) { Assert.notNull(urlPathHelper, "UrlPathHelper must not be null"); this.urlPathHelper = urlPathHelper; @@ -232,7 +240,11 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport /** * Return the {@link #setUrlPathHelper configured} {@code UrlPathHelper}. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } @@ -241,9 +253,14 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * Configure the PathMatcher to use. *

Note: This property is mutually exclusive with and * ignored when {@link #setPatternParser(PathPatternParser)} is set. - *

By default this is {@link AntPathMatcher}. + *

By default, this is {@link AntPathMatcher}. * @see org.springframework.util.AntPathMatcher + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) public void setPathMatcher(PathMatcher pathMatcher) { Assert.notNull(pathMatcher, "PathMatcher must not be null"); this.pathMatcher = pathMatcher; @@ -254,7 +271,11 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport /** * Return the {@link #setPathMatcher configured} {@code PathMatcher}. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public PathMatcher getPathMatcher() { return this.pathMatcher; } @@ -311,6 +332,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @since 4.2 * @see #setCorsProcessor(CorsProcessor) */ + @SuppressWarnings("removal") public void setCorsConfigurations(Map corsConfigurations) { if (CollectionUtils.isEmpty(corsConfigurations)) { this.corsConfigurationSource = null; @@ -339,6 +361,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @since 5.1 * @see #setCorsProcessor(CorsProcessor) */ + @SuppressWarnings("removal") public void setCorsConfigurationSource(CorsConfigurationSource source) { Assert.notNull(source, "CorsConfigurationSource must not be null"); this.corsConfigurationSource = source; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java index 930f94fc58a..f62f4c20e09 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMethodMapping.java @@ -525,6 +525,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * Return the request mapping paths that are not patterns. * @since 5.3 */ + @SuppressWarnings("removal") protected Set getDirectPaths(T mapping) { Set urls = Collections.emptySet(); for (String path : getMappingPathPatterns(mapping)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java index 586db1c0e59..3411cb146b9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractUrlHandlerMapping.java @@ -319,6 +319,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i * @see #exposePathWithinMapping * @see AntPathMatcher */ + @SuppressWarnings("removal") protected @Nullable Object lookupHandler(String lookupPath, HttpServletRequest request) throws Exception { Object handler = getDirectMatch(lookupPath, request); if (handler != null) { @@ -452,7 +453,9 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i request.setAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVariables); } + @SuppressWarnings("removal") @Override + @Deprecated(since = "7.0", forRemoval = true) public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) { Assert.state(getPatternParser() == null, "This HandlerMapping uses PathPatterns."); String lookupPath = UrlPathHelper.getResolvedLookupPath(request); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java index d6067631e92..b982a84b4b8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java @@ -570,6 +570,8 @@ public class HandlerMappingIntrospector return this.delegate.getPatternParser(); } + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) @Override public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) { pattern = initFullPathPattern(pattern); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java index c4596727797..1fd2d2b0d7e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java @@ -172,14 +172,22 @@ public final class MappedInterceptor implements HandlerInterceptor { * String pattern matching even when a * {@linkplain ServletRequestPathUtils#parseAndCache parsed} {@code RequestPath} * is available. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setPathMatcher(PathMatcher pathMatcher) { this.pathMatcher = pathMatcher; } /** * Get the {@linkplain #setPathMatcher(PathMatcher) configured} PathMatcher. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public PathMatcher getPathMatcher() { return this.pathMatcher; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MatchableHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MatchableHandlerMapping.java index 0fcf32a92ab..2b8f24e9e22 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MatchableHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MatchableHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 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. @@ -19,7 +19,9 @@ package org.springframework.web.servlet.handler; import jakarta.servlet.http.HttpServletRequest; import org.jspecify.annotations.Nullable; +import org.springframework.util.PathMatcher; import org.springframework.web.servlet.HandlerMapping; +import org.springframework.web.util.UrlPathHelper; import org.springframework.web.util.pattern.PathPatternParser; /** @@ -49,7 +51,11 @@ public interface MatchableHandlerMapping extends HandlerMapping { * @param request the current request * @param pattern the pattern to match * @return the result from request matching, or {@code null} if none + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) @Nullable RequestMatchResult match(HttpServletRequest request, String pattern); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/PathPatternMatchableHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/PathPatternMatchableHandlerMapping.java index 18541f2e59c..8537daf75cd 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/PathPatternMatchableHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/PathPatternMatchableHandlerMapping.java @@ -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. @@ -56,6 +56,8 @@ class PathPatternMatchableHandlerMapping implements MatchableHandlerMapping { this.parser = delegate.getPatternParser(); } + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) @Override public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) { PathPattern pathPattern = this.pathPatternCache.computeIfAbsent(pattern, value -> { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/RequestMatchResult.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/RequestMatchResult.java index 96b1aaef464..4fcafdb64f8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/RequestMatchResult.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/RequestMatchResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 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. @@ -23,7 +23,9 @@ import org.jspecify.annotations.Nullable; import org.springframework.http.server.PathContainer; import org.springframework.util.Assert; import org.springframework.util.PathMatcher; +import org.springframework.web.util.UrlPathHelper; import org.springframework.web.util.pattern.PathPattern; +import org.springframework.web.util.pattern.PathPatternParser; /** * Container for the result from request pattern matching via @@ -71,7 +73,11 @@ public class RequestMatchResult { * @param pattern the pattern that was matched, possibly with a '/' appended * @param lookupPath the mapping path * @param pathMatcher the PathMatcher instance used for the match + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public RequestMatchResult(String pattern, String lookupPath, PathMatcher pathMatcher) { Assert.hasText(pattern, "'matchingPattern' is required"); Assert.hasText(lookupPath, "'lookupPath' is required"); @@ -87,7 +93,7 @@ public class RequestMatchResult { /** * Extract URI template variables from the matching pattern as defined in - * {@link PathMatcher#extractUriTemplateVariables}. + * {@link PathPattern#matchAndExtract(PathContainer)}. * @return a map with URI template variables */ @SuppressWarnings({"ConstantConditions", "NullAway"}) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractUrlViewController.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractUrlViewController.java index 768b8ad3f7c..fd5ffd2c5ec 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractUrlViewController.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/AbstractUrlViewController.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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. @@ -20,9 +20,11 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.util.Assert; +import org.springframework.util.PathMatcher; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.support.RequestContextUtils; import org.springframework.web.util.UrlPathHelper; +import org.springframework.web.util.pattern.PathPatternParser; /** * Abstract base class for {@code Controllers} that return a view name @@ -48,7 +50,11 @@ public abstract class AbstractUrlViewController extends AbstractController { * if applicable (i.e. in the case of a ".../*" servlet mapping in web.xml). * Default is "false". * @see org.springframework.web.util.UrlPathHelper#setAlwaysUseFullPath + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setAlwaysUseFullPath(boolean alwaysUseFullPath) { this.urlPathHelper.setAlwaysUseFullPath(alwaysUseFullPath); } @@ -60,7 +66,11 @@ public abstract class AbstractUrlViewController extends AbstractController { *

Uses either the request encoding or the default encoding according * to the Servlet spec (ISO-8859-1). * @see org.springframework.web.util.UrlPathHelper#setUrlDecode + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setUrlDecode(boolean urlDecode) { this.urlPathHelper.setUrlDecode(urlDecode); } @@ -68,7 +78,11 @@ public abstract class AbstractUrlViewController extends AbstractController { /** * Set if ";" (semicolon) content should be stripped from the request URI. * @see org.springframework.web.util.UrlPathHelper#setRemoveSemicolonContent(boolean) + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setRemoveSemicolonContent(boolean removeSemicolonContent) { this.urlPathHelper.setRemoveSemicolonContent(removeSemicolonContent); } @@ -79,7 +93,11 @@ public abstract class AbstractUrlViewController extends AbstractController { * or to share common UrlPathHelper settings across multiple MethodNameResolvers * and HandlerMappings. * @see org.springframework.web.servlet.handler.AbstractUrlHandlerMapping#setUrlPathHelper + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setUrlPathHelper(UrlPathHelper urlPathHelper) { Assert.notNull(urlPathHelper, "UrlPathHelper must not be null"); this.urlPathHelper = urlPathHelper; @@ -87,7 +105,11 @@ public abstract class AbstractUrlViewController extends AbstractController { /** * Return the UrlPathHelper to use for the resolution of lookup paths. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) protected UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/WebContentInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/WebContentInterceptor.java index 6526fed409f..71a47e165b9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/WebContentInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/WebContentInterceptor.java @@ -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. @@ -73,7 +73,7 @@ import org.springframework.web.util.pattern.PathPatternParser; */ public class WebContentInterceptor extends WebContentGenerator implements HandlerInterceptor { - private static PathMatcher defaultPathMatcher = new AntPathMatcher(); + private static final PathMatcher defaultPathMatcher = new AntPathMatcher(); private final PathPatternParser patternParser; @@ -148,7 +148,11 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle * @see #addCacheMapping * @see #setCacheMappings * @see org.springframework.util.AntPathMatcher + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setPathMatcher(PathMatcher pathMatcher) { Assert.notNull(pathMatcher, "PathMatcher must not be null"); this.pathMatcher = pathMatcher; @@ -265,7 +269,11 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle * relies on String pattern matching with {@link PathMatcher}. * @param lookupPath the path to match to * @return the matched {@code CacheControl}, or {@code null} if no match + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) protected @Nullable CacheControl lookupCacheControl(String lookupPath) { for (Map.Entry entry : this.cacheControlMappings.entrySet()) { if (this.pathMatcher.match(entry.getKey().getPatternString(), lookupPath)) { @@ -297,7 +305,11 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle * matching with {@link PathMatcher}. * @param lookupPath the path to match to * @return the matched cacheSeconds, or {@code null} if there is no match + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) protected @Nullable Integer lookupCacheSeconds(String lookupPath) { for (Map.Entry entry : this.cacheMappings.entrySet()) { if (this.pathMatcher.match(entry.getKey().getPatternString(), lookupPath)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java index 66ae0f79c69..587c5b11e7e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java @@ -48,7 +48,11 @@ import org.springframework.web.util.pattern.PathPatternParser; * * @author Rossen Stoyanchev * @since 3.1 + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ +@Deprecated(since = "7.0", forRemoval = true) public class PatternsRequestCondition extends AbstractRequestCondition { private static final Set EMPTY_PATH_PATTERN = Collections.singleton(""); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java index 60ce3b1b428..9f0c0bfc3f9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java @@ -65,6 +65,7 @@ public final class RequestMappingInfo implements RequestConditionThis is mutually exclusive with {@link #getPathPatternsCondition()} * such that when one returns {@code null} the other one returns an instance. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) public @Nullable PatternsRequestCondition getPatternsCondition() { return this.patternsCondition; } @@ -230,6 +240,7 @@ public final class RequestMappingInfo implements RequestCondition getDirectPaths() { RequestCondition condition = getActivePatternsCondition(); return (condition instanceof PathPatternsRequestCondition pprc ? @@ -241,6 +252,7 @@ public final class RequestMappingInfo implements RequestCondition getPatternValues() { RequestCondition condition = getActivePatternsCondition(); return (condition instanceof PathPatternsRequestCondition pprc ? @@ -251,6 +263,7 @@ public final class RequestMappingInfo implements RequestCondition condition = getActivePatternsCondition(); return (condition instanceof PathPatternsRequestCondition pprc ? @@ -324,6 +337,7 @@ public final class RequestMappingInfo implements RequestConditionExample: combine type- and method-level request mappings. * @return a new request mapping info instance; never {@code null} */ + @SuppressWarnings("removal") @Override public RequestMappingInfo combine(RequestMappingInfo other) { String name = combineNames(other); @@ -369,6 +383,7 @@ public final class RequestMappingInfo implements RequestConditionBy default, this is not set. You must set it explicitly if you want * {@link PathMatcher} to be used, or otherwise {@link RequestMappingInfo} * defaults to using {@link PathPatternParser}. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setPathMatcher(@Nullable PathMatcher pathMatcher) { this.pathMatcher = pathMatcher; } /** * Return a custom PathMatcher to use for the PatternsRequestCondition, if any. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public @Nullable PathMatcher getPathMatcher() { return this.pathMatcher; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java index ea06a048449..5923e9ead26 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java @@ -135,6 +135,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe * @see HandlerMapping#MATRIX_VARIABLES_ATTRIBUTE * @see HandlerMapping#PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE */ + @SuppressWarnings("removal") @Override protected void handleMatch(RequestMappingInfo info, String lookupPath, HttpServletRequest request) { super.handleMatch(info, lookupPath, request); @@ -180,6 +181,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe request.setAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables); } + @SuppressWarnings("removal") private void extractMatchDetails( PatternsRequestCondition condition, String lookupPath, HttpServletRequest request) { @@ -203,6 +205,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe request.setAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables); } + @SuppressWarnings("removal") private Map> extractMatrixVariables( HttpServletRequest request, Map uriVariables) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java index b30058bbe39..57917a34664 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java @@ -135,7 +135,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi } @Override - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") public void afterPropertiesSet() { this.config = new RequestMappingInfo.BuilderConfiguration(); this.config.setContentNegotiationManager(getContentNegotiationManager()); @@ -390,6 +390,8 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi } } + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) @Override public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) { Assert.state(getPatternParser() == null, "This HandlerMapping uses PathPatterns."); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java index f1226fc170a..13f96cabe11 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java @@ -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. @@ -23,10 +23,12 @@ import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.util.Assert; +import org.springframework.util.PathMatcher; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.annotation.AbstractCookieValueMethodArgumentResolver; import org.springframework.web.util.UrlPathHelper; import org.springframework.web.util.WebUtils; +import org.springframework.web.util.pattern.PathPatternParser; /** * An {@link org.springframework.web.method.annotation.AbstractCookieValueMethodArgumentResolver} @@ -37,7 +39,7 @@ import org.springframework.web.util.WebUtils; */ public class ServletCookieValueMethodArgumentResolver extends AbstractCookieValueMethodArgumentResolver { - private UrlPathHelper urlPathHelper = new UrlPathHelper(); + private UrlPathHelper urlPathHelper = UrlPathHelper.defaultInstance; public ServletCookieValueMethodArgumentResolver(@Nullable ConfigurableBeanFactory beanFactory) { @@ -50,18 +52,23 @@ public class ServletCookieValueMethodArgumentResolver extends AbstractCookieValu * {@link UrlPathHelper#decodeRequestString(HttpServletRequest, String)}. * A shortcut for doing the same by setting a {@link UrlPathHelper} with * its {@code urlDecode} property set accordingly. - *

By default set to "true" in which case cookie values are decoded. + *

By default, set to "true" in which case cookie values are decoded. * @since 6.1.2 */ public void setUrlDecode(boolean urlDecode) { - this.urlPathHelper.setUrlDecode(urlDecode); + this.urlPathHelper = (urlDecode ? UrlPathHelper.defaultInstance : UrlPathHelper.rawPathInstance); } /** * Set the {@code UrlPathHelper} to use to decode cookie values with via * {@link UrlPathHelper#decodeRequestString(HttpServletRequest, String)}. * For most cases you can use {@link #setUrlDecode(boolean)} instead. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) public void setUrlPathHelper(UrlPathHelper urlPathHelper) { this.urlPathHelper = urlPathHelper; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java index 46634264183..ce83de99cdd 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java @@ -33,10 +33,12 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.server.PathContainer; +import org.springframework.util.PathMatcher; import org.springframework.util.StringUtils; import org.springframework.web.util.ServletRequestPathUtils; import org.springframework.web.util.UriUtils; import org.springframework.web.util.UrlPathHelper; +import org.springframework.web.util.pattern.PathPatternParser; /** * A simple {@code ResourceResolver} that tries to find a resource under the given @@ -111,7 +113,11 @@ public class PathResourceResolver extends AbstractResourceResolver { * static resources. This helps to derive information about the lookup path * such as whether it is decoded or not. * @since 4.3.13 + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper) { this.urlPathHelper = urlPathHelper; } @@ -119,7 +125,11 @@ public class PathResourceResolver extends AbstractResourceResolver { /** * The configured {@link UrlPathHelper}. * @since 4.3.13 + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public @Nullable UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java index f9ffc15eb7a..b4f1ce5ba0b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java @@ -49,6 +49,7 @@ import org.springframework.http.server.ServletServerHttpResponse; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; +import org.springframework.util.PathMatcher; import org.springframework.util.StringUtils; import org.springframework.util.StringValueResolver; import org.springframework.web.HttpRequestHandler; @@ -60,6 +61,7 @@ import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.support.WebContentGenerator; import org.springframework.web.util.UrlPathHelper; +import org.springframework.web.util.pattern.PathPatternParser; /** * {@code HttpRequestHandler} that serves static resources in an optimized way @@ -314,7 +316,11 @@ public class ResourceHttpRequestHandler extends WebContentGenerator * static resources. This helps to derive information about the lookup path * such as whether it is decoded or not. * @since 4.3.13 + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper) { this.urlPathHelper = urlPathHelper; } @@ -322,7 +328,11 @@ public class ResourceHttpRequestHandler extends WebContentGenerator /** * The configured {@link UrlPathHelper}. * @since 4.3.13 + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public @Nullable UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } @@ -477,6 +487,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator * resolvers and set its {@code allowedLocations} property (if empty) to * match the {@link #setLocations locations} configured on this class. */ + @SuppressWarnings("removal") protected void initAllowedLocations() { if (CollectionUtils.isEmpty(getLocations())) { return; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java index e4b948a8cb9..d14eecca15f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 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. @@ -91,6 +91,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer * @param request the referer request * @return the absolute request path for the given resource path */ + @SuppressWarnings("removal") protected String toAbsolutePath(String path, HttpServletRequest request) { String absolutePath = path; if (!path.startsWith("/")) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java index ea5eac1ef4e..82673e2e814 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java @@ -89,6 +89,7 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { } } + @SuppressWarnings("removal") private void initLookupPath(ResourceUrlProvider urlProvider) { this.resourceUrlProvider = urlProvider; if (this.indexLookupPath == null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java index 19896a4d066..317f0d2e33a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java @@ -75,7 +75,11 @@ public class ResourceUrlProvider implements ApplicationListenerA default UrlPathHelper is always available. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setUrlPathHelper(UrlPathHelper urlPathHelper) { Assert.notNull(urlPathHelper, "UrlPathHelper must not be null"); this.urlPathHelper = urlPathHelper; @@ -509,7 +515,11 @@ public class RequestContext { * Return the UrlPathHelper used for context path and request URI decoding. * Can be used to configure the current UrlPathHelper. *

A default UrlPathHelper is always available. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParserTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParserTests.java index f435df73531..f5ed7dcdb8c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParserTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/AnnotationDrivenBeanDefinitionParserTests.java @@ -78,6 +78,7 @@ class AnnotationDrivenBeanDefinitionParserTests { .asInstanceOf(BOOLEAN).isTrue(); } + @SuppressWarnings("removal") @Test public void testPathMatchingConfiguration() { loadBeanDefinitions("mvc-config-path-matching.xml"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java index 4f0bc8a1c3f..46d334ef44c 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java @@ -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"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationIntegrationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationIntegrationTests.java index b485c5fac27..5d07e480acb 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationIntegrationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationIntegrationTests.java @@ -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) diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java index 8c2a6841f70..f0e05be62ac 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfigurationTests.java @@ -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) diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java index 39c2a9d7ff0..d66f8c8da5a 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/InterceptorRegistryTests.java @@ -120,6 +120,7 @@ public class InterceptorRegistryTests { verifyWebInterceptor(interceptors.get(1), this.webInterceptor2); } + @SuppressWarnings("removal") @Test void addInterceptorsWithCustomPathMatcher() { PathMatcher pathMatcher = mock(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistryTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistryTests.java index ae7a811357b..322683fdefd 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistryTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistryTests.java @@ -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/"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java index 551d4596559..23b27e63ec5 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupportExtensionTests.java @@ -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()); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMappingTests.java index e3056633b8c..cfb2829d8c1 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/BeanNameUrlHandlerMappingTests.java @@ -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 { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingIntrospectorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingIntrospectorTests.java index 77311119c75..9c334fcc1fd 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingIntrospectorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/HandlerMappingIntrospectorTests.java @@ -138,6 +138,7 @@ class HandlerMappingIntrospectorTests { assertThat(initIntrospector(context).allHandlerMappingsUsePathPatternParser()).isFalse(); } + @SuppressWarnings("removal") @ParameterizedTest @ValueSource(booleans = {true, false}) void getMatchable(boolean usePathPatterns) throws Exception { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/MappedInterceptorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/MappedInterceptorTests.java index 128db22c5b8..b5d0ba7d5c9 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/MappedInterceptorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/MappedInterceptorTests.java @@ -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 requestFactory) { MappedInterceptor interceptor = new MappedInterceptor(new String[] { "/foo/[0-9]*" }, null, delegate); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java index 991f865fbc6..7f9adb88e98 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMappingTests.java @@ -65,6 +65,7 @@ class SimpleUrlHandlerMappingTests { .isInstanceOf(NoSuchBeanDefinitionException.class); } + @SuppressWarnings("removal") @Test void newlineInRequestShouldMatch() throws Exception { Object controller = new Object(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java index 98dd9182d62..a6f83b11ae5 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/WebContentInterceptorTests.java @@ -103,6 +103,7 @@ class WebContentInterceptorTests { assertThat(cacheControlHeaders).isEmpty(); } + @SuppressWarnings("removal") @Test void throwsExceptionWithNullPathMatcher() { assertThatIllegalArgumentException() diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java index 9e3de4c38b8..457950e39f7 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/condition/PatternsRequestConditionTests.java @@ -30,6 +30,7 @@ import static org.assertj.core.api.InstanceOfAssertFactories.STRING; * * @author Rossen Stoyanchev */ +@SuppressWarnings("removal") class PatternsRequestConditionTests { @Test diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java index ce405fc4d6c..c6cb7c4045d 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java @@ -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) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoTests.java index d6eb9d60fd6..c7dca30e762 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoTests.java @@ -48,7 +48,7 @@ import static org.springframework.web.bind.annotation.RequestMethod.HEAD; */ class RequestMappingInfoTests { - @SuppressWarnings("unused") + @SuppressWarnings({"unused", "removal"}) static Stream> 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(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java index d36cbdf4e49..6660089705d 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/CrossOriginTests.java @@ -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); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java index 28d070a8522..4a9813937de 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMappingTests.java @@ -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) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java index 5cc34dd9a40..edb18ed940e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java @@ -149,6 +149,7 @@ class PathResourceResolverTests { assertThat(path).isNull(); } + @SuppressWarnings("removal") @Test void relativePathEncodedForUrlResource() throws Exception { TestUrlResource location = new TestUrlResource("file:///tmp"); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerIntegrationTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerIntegrationTests.java index 6046b5e1c43..d0ca6cd0e2e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerIntegrationTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerIntegrationTests.java @@ -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(); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistry.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistry.java index 8e62f2be356..e9b9f17502a 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistry.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 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. @@ -26,12 +26,14 @@ import org.jspecify.annotations.Nullable; import org.springframework.scheduling.TaskScheduler; import org.springframework.util.MultiValueMap; +import org.springframework.util.PathMatcher; import org.springframework.web.HttpRequestHandler; import org.springframework.web.servlet.handler.AbstractHandlerMapping; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.server.support.WebSocketHandlerMapping; import org.springframework.web.util.UrlPathHelper; +import org.springframework.web.util.pattern.PathPatternParser; /** * {@link WebSocketHandlerRegistry} with Spring MVC handler mappings for the @@ -77,11 +79,16 @@ public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry /** * Set the UrlPathHelper to configure on the {@code SimpleUrlHandlerMapping} * used to map handshake requests. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) public void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper) { this.urlPathHelper = urlPathHelper; } + @Deprecated(since = "7.0", forRemoval = true) public @Nullable UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } @@ -111,6 +118,7 @@ public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry .forEach(registration -> registration.setTaskScheduler(scheduler)); } + @SuppressWarnings("removal") public AbstractHandlerMapping getHandlerMapping() { Map urlMap = new LinkedHashMap<>(); for (ServletWebSocketHandlerRegistration registration : this.registrations) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/StompEndpointRegistry.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/StompEndpointRegistry.java index 78866719ce3..dd001ddc437 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/StompEndpointRegistry.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/StompEndpointRegistry.java @@ -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. @@ -16,8 +16,10 @@ package org.springframework.web.socket.config.annotation; +import org.springframework.util.PathMatcher; import org.springframework.web.socket.messaging.StompSubProtocolErrorHandler; import org.springframework.web.util.UrlPathHelper; +import org.springframework.web.util.pattern.PathPatternParser; /** * A contract for registering STOMP over WebSocket endpoints. @@ -42,7 +44,11 @@ public interface StompEndpointRegistry { /** * Configure a customized {@link UrlPathHelper} for the STOMP endpoint * {@link org.springframework.web.servlet.HandlerMapping HandlerMapping}. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @Deprecated(since = "7.0", forRemoval = true) void setUrlPathHelper(UrlPathHelper urlPathHelper); /** diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistry.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistry.java index 9a65c420ac9..e54cb5aca09 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistry.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistry.java @@ -27,6 +27,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.scheduling.TaskScheduler; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; +import org.springframework.util.PathMatcher; import org.springframework.web.HttpRequestHandler; import org.springframework.web.servlet.handler.AbstractHandlerMapping; import org.springframework.web.socket.WebSocketHandler; @@ -36,6 +37,7 @@ import org.springframework.web.socket.messaging.StompSubProtocolHandler; import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler; import org.springframework.web.socket.server.support.WebSocketHandlerMapping; import org.springframework.web.util.UrlPathHelper; +import org.springframework.web.util.pattern.PathPatternParser; /** * A registry for STOMP over WebSocket endpoints that maps the endpoints with a @@ -125,12 +127,18 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry { /** * Set the UrlPathHelper to configure on the {@code HandlerMapping} * used to map handshake requests. + * @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated + * for use at runtime in web modules in favor of parsed patterns with + * {@link PathPatternParser}. */ + @SuppressWarnings("removal") + @Deprecated(since = "7.0", forRemoval = true) @Override public void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper) { this.urlPathHelper = urlPathHelper; } + @Deprecated(since = "7.0", forRemoval = true) protected @Nullable UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } @@ -158,6 +166,7 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry { /** * Return a handler mapping with the mapped ViewControllers. */ + @SuppressWarnings("removal") public AbstractHandlerMapping getHandlerMapping() { Map urlMap = new LinkedHashMap<>(); for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) { diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistryTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistryTests.java index 09579c98e6f..81a78705c6c 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistryTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistryTests.java @@ -69,6 +69,7 @@ class WebMvcStompEndpointRegistryTests { assertThat(protocolHandlers.get("v12.stomp")).isNotNull(); } + @SuppressWarnings("removal") @Test void handlerMapping() { SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) this.endpointRegistry.getHandlerMapping();