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

View File

@ -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
`<mvc:annotation-driven enable-matrix-variables="true"/>`.

View File

@ -188,9 +188,9 @@ public class RouterFunctionMockMvcBuilder extends AbstractMockMvcBuilder<RouterF
}
/**
* Enable URL path matching with parsed
* {@link org.springframework.web.util.pattern.PathPattern PathPatterns}
* instead of String pattern matching with a {@link org.springframework.util.PathMatcher}.
* Configure the parser to use for
* {@link org.springframework.web.util.pattern.PathPattern PathPatterns}.
* <p>By default, this is a default instance of {@link PathPatternParser}.
* @param parser the parser to use
*/
public RouterFunctionMockMvcBuilder setPatternParser(@Nullable PathPatternParser parser) {

View File

@ -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 AbstractMockMvcBuilder<StandaloneM
}
/**
* Enable URL path matching with parsed
* {@link org.springframework.web.util.pattern.PathPattern PathPatterns}
* instead of String pattern matching with a {@link org.springframework.util.PathMatcher}.
* Configure the parser to use for
* {@link org.springframework.web.util.pattern.PathPattern PathPatterns}.
* <p>By 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 AbstractMockMvcBuilder<StandaloneM
* Set if ";" (semicolon) content should be stripped from the request URI. The value,
* if provided, is in turn set on
* {@link 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 StandaloneMockMvcBuilder setRemoveSemicolonContent(boolean removeSemicolonContent) {
this.removeSemicolonContent = removeSemicolonContent;
return this;
@ -428,6 +433,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
/** Using the MVC Java configuration as the starting point for the "standalone" setup. */
private class StandaloneConfiguration extends WebMvcConfigurationSupport {
@SuppressWarnings("removal")
public RequestMappingHandlerMapping getHandlerMapping(
FormattingConversionService mvcConversionService,
ResourceUrlProvider mvcResourceUrlProvider) {

View File

@ -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.
@ -105,6 +105,7 @@ public class EncodedUriTests {
@Component
static class HandlerMappingConfigurer implements BeanPostProcessor, PriorityOrdered {
@SuppressWarnings("removal")
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof RequestMappingHandlerMapping requestMappingHandlerMapping) {

View File

@ -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.
@ -141,7 +141,11 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource
* parsed {@code PathPatterns} are used instead.
* For further details on that, see {@link #setAllowInitLookupPath(boolean)}.
* <p>By 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;
}

View File

@ -71,6 +71,7 @@ class UrlBasedCorsConfigurationSourceTests {
.isThrownBy(() -> source.getCorsConfigurations().put("/**", new CorsConfiguration()));
}
@SuppressWarnings("removal")
@Test
void allowInitLookupPath() {
CorsConfiguration config = new CorsConfiguration();

View File

@ -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) {

View File

@ -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}.
* <p><strong>Note:</strong> This property is mutually exclusive with the
* following other, {@code AntPathMatcher} related properties:
* <ul>
* <li>{@link #setUrlPathHelper(UrlPathHelper)}
* <li>{@link #setPathMatcher(PathMatcher)}
* </ul>
* <p>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.
* <p>By default this is an instance of {@link UrlPathHelper} with default
* <p>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.
* <p>By default this is an instance of {@link AntPathMatcher} with default
* <p>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.
* </ul>
* @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;

View File

@ -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) {

View File

@ -391,7 +391,12 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
* <p><b>Note:</b> 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
* <p><b>Note:</b> 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();

View File

@ -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");

View File

@ -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.
* <p><strong>Note:</strong> 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.
* <p><strong>Note:</strong> This property is mutually exclusive with and
* ignored when {@link #setPatternParser(PathPatternParser)} is set.
* <p>By default this is {@link AntPathMatcher}.
* <p>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<String, CorsConfiguration> 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;

View File

@ -525,6 +525,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
* Return the request mapping paths that are not patterns.
* @since 5.3
*/
@SuppressWarnings("removal")
protected Set<String> getDirectPaths(T mapping) {
Set<String> urls = Collections.emptySet();
for (String path : getMappingPathPatterns(mapping)) {

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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 -> {

View File

@ -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"})

View File

@ -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 {
* <p>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;
}

View File

@ -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<PathPattern, CacheControl> 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<PathPattern, Integer> entry : this.cacheMappings.entrySet()) {
if (this.pathMatcher.match(entry.getKey().getPatternString(), lookupPath)) {

View File

@ -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<PatternsRequestCondition> {
private static final Set<String> EMPTY_PATH_PATTERN = Collections.singleton("");

View File

@ -65,6 +65,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
private static final PathPatternsRequestCondition EMPTY_PATH_PATTERNS = new PathPatternsRequestCondition();
@SuppressWarnings("removal")
private static final PatternsRequestCondition EMPTY_PATTERNS = new PatternsRequestCondition();
private static final RequestMethodsRequestCondition EMPTY_REQUEST_METHODS = new RequestMethodsRequestCondition();
@ -84,6 +85,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
private final @Nullable PathPatternsRequestCondition pathPatternsCondition;
@SuppressWarnings("removal")
private final @Nullable PatternsRequestCondition patternsCondition;
private final RequestMethodsRequestCondition methodsCondition;
@ -108,6 +110,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
* @deprecated as of 5.3 in favor using {@link RequestMappingInfo.Builder} via
* {@link #paths(String...)}.
*/
@SuppressWarnings("removal")
@Deprecated
public RequestMappingInfo(@Nullable String name, @Nullable PatternsRequestCondition patterns,
@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
@ -130,6 +133,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
* @deprecated as of 5.3 in favor using {@link RequestMappingInfo.Builder} via
* {@link #paths(String...)}.
*/
@SuppressWarnings("removal")
@Deprecated
public RequestMappingInfo(@Nullable PatternsRequestCondition patterns,
@Nullable RequestMethodsRequestCondition methods, @Nullable ParamsRequestCondition params,
@ -149,6 +153,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
info.consumesCondition, info.producesCondition, customRequestCondition);
}
@SuppressWarnings("removal")
private RequestMappingInfo(@Nullable String name,
@Nullable PathPatternsRequestCondition pathPatternsCondition,
@Nullable PatternsRequestCondition patternsCondition,
@ -202,7 +207,12 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
* {@link PathMatcher} is in use.
* <p>This 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<RequestMapping
* Return the mapping paths that are not patterns.
* @since 5.3
*/
@SuppressWarnings("removal")
public Set<String> getDirectPaths() {
RequestCondition<?> condition = getActivePatternsCondition();
return (condition instanceof PathPatternsRequestCondition pprc ?
@ -241,6 +252,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
* patterns condition as Strings.
* @since 5.3
*/
@SuppressWarnings("removal")
public Set<String> getPatternValues() {
RequestCondition<?> condition = getActivePatternsCondition();
return (condition instanceof PathPatternsRequestCondition pprc ?
@ -251,6 +263,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
* Whether the request mapping has an empty URL path mapping.
* @since 6.0.10
*/
@SuppressWarnings("removal")
public boolean isEmptyMapping() {
RequestCondition<?> condition = getActivePatternsCondition();
return (condition instanceof PathPatternsRequestCondition pprc ?
@ -324,6 +337,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
* <p>Example: 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 RequestCondition<RequestMapping
* patterns on top.
* @return a new instance in case of a match; or {@code null} otherwise
*/
@SuppressWarnings("removal")
@Override
public @Nullable RequestMappingInfo getMatchingCondition(HttpServletRequest request) {
RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request);
@ -479,7 +494,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
return this.hashCode;
}
@SuppressWarnings({"ConstantConditions", "NullAway"})
@SuppressWarnings({"ConstantConditions", "NullAway", "removal"})
private static int calculateHashCode(
@Nullable PathPatternsRequestCondition pathPatterns, @Nullable PatternsRequestCondition patterns,
RequestMethodsRequestCondition methods, ParamsRequestCondition params, HeadersRequestCondition headers,
@ -688,6 +703,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
return this;
}
@SuppressWarnings("removal")
@Override
public RequestMappingInfo build() {
@ -733,6 +749,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
private @Nullable PathPatternsRequestCondition pathPatternsCondition;
@SuppressWarnings("removal")
private @Nullable PatternsRequestCondition patternsCondition;
private RequestMethodsRequestCondition methodsCondition;
@ -762,6 +779,7 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
this.options = other.options;
}
@SuppressWarnings("removal")
@Override
public Builder paths(String... paths) {
PathPatternParser parser = this.options.getPatternParserToUse();
@ -912,14 +930,22 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
* <p>By 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;
}

View File

@ -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<String, MultiValueMap<String, String>> extractMatrixVariables(
HttpServletRequest request, Map<String, String> uriVariables) {

View File

@ -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.");

View File

@ -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.
* <p>By default set to "true" in which case cookie values are decoded.
* <p>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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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("/")) {

View File

@ -89,6 +89,7 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean {
}
}
@SuppressWarnings("removal")
private void initLookupPath(ResourceUrlProvider urlProvider) {
this.resourceUrlProvider = urlProvider;
if (this.indexLookupPath == null) {

View File

@ -75,7 +75,11 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
* Configure a {@code UrlPathHelper} to use in
* {@link #getForRequestUrl(jakarta.servlet.http.HttpServletRequest, String)}
* in order to derive the lookup path for a target request URL path.
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
* for use at runtime in web modules. After the deprecation phase, it will no
* longer be possible to set a customized PathMatcher instance.
*/
@Deprecated(since = "7.0", forRemoval = true)
public void setUrlPathHelper(UrlPathHelper urlPathHelper) {
this.urlPathHelper = urlPathHelper;
}
@ -83,7 +87,11 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
/**
* Return the configured {@code UrlPathHelper}.
* @since 4.2.8
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
* for use at runtime in web modules. After the deprecation phase, it will no
* longer be possible to set a customized PathMatcher instance.
*/
@Deprecated(since = "7.0", forRemoval = true)
public UrlPathHelper getUrlPathHelper() {
return this.urlPathHelper;
}
@ -91,14 +99,22 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
/**
* Configure a {@code PathMatcher} to use when comparing target lookup path
* against resource mappings.
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
* for use at runtime in web modules. After the deprecation phase, it will no
* longer be possible to set a customized PathMatcher instance.
*/
@Deprecated(since = "7.0", forRemoval = true)
public void setPathMatcher(PathMatcher pathMatcher) {
this.pathMatcher = pathMatcher;
}
/**
* Return the configured {@code PathMatcher}.
* @deprecated use of {@link PathMatcher} and {@link UrlPathHelper} is deprecated
* for use at runtime in web modules. After the deprecation phase, it will no
* longer be possible to set a customized PathMatcher instance.
*/
@Deprecated(since = "7.0", forRemoval = true)
public PathMatcher getPathMatcher() {
return this.pathMatcher;
}
@ -181,6 +197,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
return (resolvedLookupPath != null ? prefix + resolvedLookupPath + suffix : null);
}
@SuppressWarnings("removal")
private int getLookupPathIndex(HttpServletRequest request) {
UrlPathHelper pathHelper = getUrlPathHelper();
if (request.getAttribute(UrlPathHelper.PATH_ATTRIBUTE) == null) {

View File

@ -31,10 +31,12 @@ import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.FlashMap;
import org.springframework.web.servlet.FlashMapManager;
import org.springframework.web.util.UrlPathHelper;
import org.springframework.web.util.pattern.PathPatternParser;
/**
* A base class for {@link FlashMapManager} implementations.
@ -74,7 +76,11 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
/**
* Set the UrlPathHelper to use to match FlashMap instances to 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(UrlPathHelper urlPathHelper) {
Assert.notNull(urlPathHelper, "UrlPathHelper must not be null");
this.urlPathHelper = urlPathHelper;
@ -82,7 +88,11 @@ public abstract class AbstractFlashMapManager implements FlashMapManager {
/**
* Return the UrlPathHelper implementation to use.
* @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;
}

View File

@ -37,6 +37,7 @@ import org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext;
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
@ -49,6 +50,7 @@ import org.springframework.web.util.HtmlUtils;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.web.util.UrlPathHelper;
import org.springframework.web.util.WebUtils;
import org.springframework.web.util.pattern.PathPatternParser;
/**
* Context holder for request-specific state, like current web application context, current locale,
@ -499,7 +501,11 @@ public class RequestContext {
* Set the UrlPathHelper to use for context path and request URI decoding.
* Can be used to pass a shared UrlPathHelper instance in.
* <p>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 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.
* <p>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;
}

View File

@ -78,6 +78,7 @@ class AnnotationDrivenBeanDefinitionParserTests {
.asInstanceOf(BOOLEAN).isTrue();
}
@SuppressWarnings("removal")
@Test
public void testPathMatchingConfiguration() {
loadBeanDefinitions("mvc-config-path-matching.xml");

View File

@ -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");

View File

@ -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)

View File

@ -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)

View File

@ -120,6 +120,7 @@ public class InterceptorRegistryTests {
verifyWebInterceptor(interceptors.get(1), this.webInterceptor2);
}
@SuppressWarnings("removal")
@Test
void addInterceptorsWithCustomPathMatcher() {
PathMatcher pathMatcher = mock();

View File

@ -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/");

View File

@ -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());

View File

@ -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 {

View File

@ -138,6 +138,7 @@ class HandlerMappingIntrospectorTests {
assertThat(initIntrospector(context).allHandlerMappingsUsePathPatternParser()).isFalse();
}
@SuppressWarnings("removal")
@ParameterizedTest
@ValueSource(booleans = {true, false})
void getMatchable(boolean usePathPatterns) throws Exception {

View File

@ -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);

View File

@ -65,6 +65,7 @@ class SimpleUrlHandlerMappingTests {
.isInstanceOf(NoSuchBeanDefinitionException.class);
}
@SuppressWarnings("removal")
@Test
void newlineInRequestShouldMatch() throws Exception {
Object controller = new Object();

View File

@ -103,6 +103,7 @@ class WebContentInterceptorTests {
assertThat(cacheControlHeaders).isEmpty();
}
@SuppressWarnings("removal")
@Test
void throwsExceptionWithNullPathMatcher() {
assertThatIllegalArgumentException()

View File

@ -30,6 +30,7 @@ import static org.assertj.core.api.InstanceOfAssertFactories.STRING;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("removal")
class PatternsRequestConditionTests {
@Test

View File

@ -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) {

View File

@ -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();

View File

@ -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);

View File

@ -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) {

View File

@ -149,6 +149,7 @@ class PathResourceResolverTests {
assertThat(path).isNull();
}
@SuppressWarnings("removal")
@Test
void relativePathEncodedForUrlResource() throws Exception {
TestUrlResource location = new TestUrlResource("file:///tmp");

View File

@ -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();

View File

@ -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<String, Object> urlMap = new LinkedHashMap<>();
for (ServletWebSocketHandlerRegistration registration : this.registrations) {

View File

@ -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);
/**

View File

@ -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<String, Object> urlMap = new LinkedHashMap<>();
for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) {

View File

@ -69,6 +69,7 @@ class WebMvcStompEndpointRegistryTests {
assertThat(protocolHandlers.get("v12.stomp")).isNotNull();
}
@SuppressWarnings("removal")
@Test
void handlerMapping() {
SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) this.endpointRegistry.getHandlerMapping();