|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2021 the original author or authors. |
|
|
|
* Copyright 2002-2022 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -23,7 +23,6 @@ import java.util.function.Predicate; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.util.AntPathMatcher; |
|
|
|
import org.springframework.util.AntPathMatcher; |
|
|
|
import org.springframework.util.PathMatcher; |
|
|
|
import org.springframework.util.PathMatcher; |
|
|
|
import org.springframework.web.servlet.handler.AbstractHandlerMapping; |
|
|
|
|
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
|
|
|
import org.springframework.web.util.UrlPathHelper; |
|
|
|
import org.springframework.web.util.UrlPathHelper; |
|
|
|
import org.springframework.web.util.pattern.PathPattern; |
|
|
|
import org.springframework.web.util.pattern.PathPattern; |
|
|
|
@ -34,14 +33,19 @@ import org.springframework.web.util.pattern.PathPatternParser; |
|
|
|
* <ul> |
|
|
|
* <ul> |
|
|
|
* <li>{@link WebMvcConfigurationSupport#requestMappingHandlerMapping}</li> |
|
|
|
* <li>{@link WebMvcConfigurationSupport#requestMappingHandlerMapping}</li> |
|
|
|
* <li>{@link WebMvcConfigurationSupport#viewControllerHandlerMapping}</li> |
|
|
|
* <li>{@link WebMvcConfigurationSupport#viewControllerHandlerMapping}</li> |
|
|
|
|
|
|
|
* <li>{@link WebMvcConfigurationSupport#beanNameHandlerMapping}</li> |
|
|
|
|
|
|
|
* <li>{@link WebMvcConfigurationSupport#routerFunctionMapping}</li> |
|
|
|
* <li>{@link WebMvcConfigurationSupport#resourceHandlerMapping}</li> |
|
|
|
* <li>{@link WebMvcConfigurationSupport#resourceHandlerMapping}</li> |
|
|
|
* </ul> |
|
|
|
* </ul> |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Brian Clozel |
|
|
|
* @author Brian Clozel |
|
|
|
|
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @since 4.0.3 |
|
|
|
* @since 4.0.3 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class PathMatchConfigurer { |
|
|
|
public class PathMatchConfigurer { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean preferPathMatcher = false; |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private PathPatternParser patternParser; |
|
|
|
private PathPatternParser patternParser; |
|
|
|
|
|
|
|
|
|
|
|
@ -74,17 +78,28 @@ public class PathMatchConfigurer { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Enable use of parsed {@link PathPattern}s as described in |
|
|
|
* Set the {@link PathPatternParser} to parse {@link PathPattern patterns} |
|
|
|
* {@link AbstractHandlerMapping#setPatternParser(PathPatternParser)}. |
|
|
|
* with for URL path matching. Parsed patterns provide a more modern and |
|
|
|
* <p><strong>Note:</strong> This is mutually exclusive with use of |
|
|
|
* efficient alternative to String path matching via {@link AntPathMatcher}. |
|
|
|
* {@link #setUrlPathHelper(UrlPathHelper)} and |
|
|
|
* <p><strong>Note:</strong> This property is mutually exclusive with the |
|
|
|
* {@link #setPathMatcher(PathMatcher)}. |
|
|
|
* following other, {@code AntPathMatcher} related properties: |
|
|
|
* <p>By default this is not enabled. |
|
|
|
* <ul> |
|
|
|
|
|
|
|
* <li>{@link #setUseSuffixPatternMatch(Boolean)} |
|
|
|
|
|
|
|
* <li>{@link #setUseRegisteredSuffixPatternMatch(Boolean)} |
|
|
|
|
|
|
|
* <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 |
|
|
|
|
|
|
|
* {@link AntPathMatcher} instead, or alternatively, setting one of the above |
|
|
|
|
|
|
|
* listed {@code AntPathMatcher} related properties has the same effect. |
|
|
|
* @param patternParser the parser to pre-parse patterns with |
|
|
|
* @param patternParser the parser to pre-parse patterns with |
|
|
|
* @since 5.3 |
|
|
|
* @since 5.3 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public PathMatchConfigurer setPatternParser(PathPatternParser patternParser) { |
|
|
|
public PathMatchConfigurer setPatternParser(@Nullable PathPatternParser patternParser) { |
|
|
|
this.patternParser = patternParser; |
|
|
|
this.patternParser = patternParser; |
|
|
|
|
|
|
|
this.preferPathMatcher = (patternParser == null); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -120,9 +135,11 @@ public class PathMatchConfigurer { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Whether to use suffix pattern match (".*") when matching patterns to |
|
|
|
* Whether to use suffix pattern match (".*") when matching patterns to |
|
|
|
* requests. If enabled a method mapped to "/users" also matches to "/users.*". |
|
|
|
* requests. If enabled a method mapped to "/users" also matches to "/users.*". |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This property is mutually exclusive with |
|
|
|
|
|
|
|
* {@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 set to {@code false}. |
|
|
|
* <p>By default this is set to {@code false}. |
|
|
|
* <p><strong>Note:</strong> This property is mutually exclusive with and |
|
|
|
|
|
|
|
* ignored when {@link #setPatternParser(PathPatternParser)} is set. |
|
|
|
|
|
|
|
* @deprecated as of 5.2.4. See class-level note in |
|
|
|
* @deprecated as of 5.2.4. See class-level note in |
|
|
|
* {@link RequestMappingHandlerMapping} on the deprecation of path extension |
|
|
|
* {@link RequestMappingHandlerMapping} on the deprecation of path extension |
|
|
|
* config options. As there is no replacement for this method, in 5.2.x it is |
|
|
|
* config options. As there is no replacement for this method, in 5.2.x it is |
|
|
|
@ -132,6 +149,7 @@ public class PathMatchConfigurer { |
|
|
|
@Deprecated |
|
|
|
@Deprecated |
|
|
|
public PathMatchConfigurer setUseSuffixPatternMatch(Boolean suffixPatternMatch) { |
|
|
|
public PathMatchConfigurer setUseSuffixPatternMatch(Boolean suffixPatternMatch) { |
|
|
|
this.suffixPatternMatch = suffixPatternMatch; |
|
|
|
this.suffixPatternMatch = suffixPatternMatch; |
|
|
|
|
|
|
|
this.preferPathMatcher |= suffixPatternMatch; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -141,9 +159,11 @@ public class PathMatchConfigurer { |
|
|
|
* {@link WebMvcConfigurer#configureContentNegotiation configure content |
|
|
|
* {@link WebMvcConfigurer#configureContentNegotiation configure content |
|
|
|
* negotiation}. This is generally recommended to reduce ambiguity and to |
|
|
|
* negotiation}. This is generally recommended to reduce ambiguity and to |
|
|
|
* avoid issues such as when a "." appears in the path for other reasons. |
|
|
|
* avoid issues such as when a "." appears in the path for other reasons. |
|
|
|
|
|
|
|
* <p><strong>Note:</strong> This property is mutually exclusive with |
|
|
|
|
|
|
|
* {@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 set to "false". |
|
|
|
* <p>By default this is set to "false". |
|
|
|
* <p><strong>Note:</strong> This property is mutually exclusive with and |
|
|
|
|
|
|
|
* ignored when {@link #setPatternParser(PathPatternParser)} is set. |
|
|
|
|
|
|
|
* @deprecated as of 5.2.4. See class-level note in |
|
|
|
* @deprecated as of 5.2.4. See class-level note in |
|
|
|
* {@link RequestMappingHandlerMapping} on the deprecation of path extension |
|
|
|
* {@link RequestMappingHandlerMapping} on the deprecation of path extension |
|
|
|
* config options. |
|
|
|
* config options. |
|
|
|
@ -151,31 +171,54 @@ public class PathMatchConfigurer { |
|
|
|
@Deprecated |
|
|
|
@Deprecated |
|
|
|
public PathMatchConfigurer setUseRegisteredSuffixPatternMatch(Boolean registeredSuffixPatternMatch) { |
|
|
|
public PathMatchConfigurer setUseRegisteredSuffixPatternMatch(Boolean registeredSuffixPatternMatch) { |
|
|
|
this.registeredSuffixPatternMatch = registeredSuffixPatternMatch; |
|
|
|
this.registeredSuffixPatternMatch = registeredSuffixPatternMatch; |
|
|
|
|
|
|
|
this.preferPathMatcher |= registeredSuffixPatternMatch; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the UrlPathHelper to use to resolve the mapping path for the application. |
|
|
|
* Set the UrlPathHelper to use to resolve the mapping path for the application. |
|
|
|
* <p><strong>Note:</strong> This property is mutually exclusive with and |
|
|
|
* <p><strong>Note:</strong> This property is mutually exclusive with |
|
|
|
* ignored when {@link #setPatternParser(PathPatternParser)} is set. |
|
|
|
* {@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 |
|
|
|
|
|
|
|
* settings. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public PathMatchConfigurer setUrlPathHelper(UrlPathHelper urlPathHelper) { |
|
|
|
public PathMatchConfigurer setUrlPathHelper(UrlPathHelper urlPathHelper) { |
|
|
|
this.urlPathHelper = urlPathHelper; |
|
|
|
this.urlPathHelper = urlPathHelper; |
|
|
|
|
|
|
|
this.preferPathMatcher = true; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the PathMatcher to use for String pattern matching. |
|
|
|
* Set the PathMatcher to use for String pattern matching. |
|
|
|
* <p>By default this is {@link AntPathMatcher}. |
|
|
|
* <p><strong>Note:</strong> This property is mutually exclusive with |
|
|
|
* <p><strong>Note:</strong> This property is mutually exclusive with and |
|
|
|
* {@link #setPatternParser(PathPatternParser)}. If set, it enables use of |
|
|
|
* ignored when {@link #setPatternParser(PathPatternParser)} is set. |
|
|
|
* 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 |
|
|
|
|
|
|
|
* settings. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public PathMatchConfigurer setPathMatcher(PathMatcher pathMatcher) { |
|
|
|
public PathMatchConfigurer setPathMatcher(PathMatcher pathMatcher) { |
|
|
|
this.pathMatcher = pathMatcher; |
|
|
|
this.pathMatcher = pathMatcher; |
|
|
|
|
|
|
|
this.preferPathMatcher = true; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Whether to prefer {@link PathMatcher}. This is the case when either is true: |
|
|
|
|
|
|
|
* <ul> |
|
|
|
|
|
|
|
* <li>{@link PathPatternParser} is explicitly set to {@code null}. |
|
|
|
|
|
|
|
* <li>{@link PathPatternParser} is not explicitly set, and a |
|
|
|
|
|
|
|
* {@link PathMatcher} related option is explicitly set. |
|
|
|
|
|
|
|
* </ul> |
|
|
|
|
|
|
|
* @since 6.0 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected boolean preferPathMatcher() { |
|
|
|
|
|
|
|
return (this.patternParser == null && this.preferPathMatcher); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the {@link PathPatternParser} to use, if configured. |
|
|
|
* Return the {@link PathPatternParser} to use, if configured. |
|
|
|
* @since 5.3 |
|
|
|
* @since 5.3 |
|
|
|
|