@@ -68,66 +68,69 @@ public final class MappedInterceptor implements HandlerInterceptor {
6868
6969 private final PatternAdapter @ Nullable [] excludePatterns ;
7070
71- private final MethodAdapter @ Nullable [] includeHttpMethods ;
71+ private final HttpMethod @ Nullable [] includeHttpMethods ;
7272
73- private final MethodAdapter @ Nullable [] excludeHttpMethods ;
73+ private final HttpMethod @ Nullable [] excludeHttpMethods ;
7474
7575 private PathMatcher pathMatcher = defaultPathMatcher ;
7676
7777 private final HandlerInterceptor interceptor ;
7878
7979
8080 /**
81- * Create an instance with the given include and exclude patterns along with
82- * the target interceptor for the mappings.
83- * @param includePatterns patterns to which requests must match, or null to
84- * match all paths
85- * @param excludePatterns patterns to which requests must not match
86- * @param includeHttpMethods http methods to which request must match, or null to match all paths
87- * @param excludeHttpMethods http methods to which request must not match
81+ * Create an instance with the given include and exclude patterns and HTTP methods.
82+ * @param includePatterns patterns to match, or null to match all paths
83+ * @param excludePatterns patterns for which requests must not match
84+ * @param includeHttpMethods the HTTP methods to match, or null for all methods
85+ * @param excludeHttpMethods the ßHTTP methods to which requests must not match
8886 * @param interceptor the target interceptor
8987 * @param parser a parser to use to pre-parse patterns into {@link PathPattern};
9088 * when not provided, {@link PathPatternParser#defaultInstance} is used.
91- * @since 5.3
89+ * @since 7.0
9290 */
93- public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns , HttpMethod @ Nullable [] includeHttpMethods , HttpMethod @ Nullable [] excludeHttpMethods ,
91+ public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns ,
92+ HttpMethod @ Nullable [] includeHttpMethods , HttpMethod @ Nullable [] excludeHttpMethods ,
9493 HandlerInterceptor interceptor , @ Nullable PathPatternParser parser ) {
9594
9695 this .includePatterns = PatternAdapter .initPatterns (includePatterns , parser );
9796 this .excludePatterns = PatternAdapter .initPatterns (excludePatterns , parser );
98- this .includeHttpMethods = MethodAdapter . initHttpMethods ( includeHttpMethods ) ;
99- this .excludeHttpMethods = MethodAdapter . initHttpMethods ( excludeHttpMethods ) ;
97+ this .includeHttpMethods = includeHttpMethods ;
98+ this .excludeHttpMethods = excludeHttpMethods ;
10099 this .interceptor = interceptor ;
101100 }
102101
103-
104102 /**
105- * Variant of
103+ * Variation of
106104 * {@link #MappedInterceptor(String[], String[], HttpMethod[], HttpMethod[], HandlerInterceptor, PathPatternParser)}
107- * with include patterns only.
105+ * without HTTP methods.
106+ * @since 5.3
107+ * @deprecated in favor of the constructor variant with HTTP methods
108108 */
109- public MappedInterceptor (String @ Nullable [] includePatterns , HandlerInterceptor interceptor ) {
110- this (includePatterns , null , null , null , interceptor );
109+ @ Deprecated (since = "7.0" , forRemoval = true )
110+ public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns ,
111+ HandlerInterceptor interceptor , @ Nullable PathPatternParser parser ) {
112+
113+ this (includePatterns , excludePatterns , null , null , interceptor , parser );
111114 }
112115
113116 /**
114117 * Variant of
115118 * {@link #MappedInterceptor(String[], String[], HttpMethod[], HttpMethod[], HandlerInterceptor, PathPatternParser)}
116- * with include methods only.
119+ * with include patterns only.
117120 */
118- public MappedInterceptor (HttpMethod @ Nullable [] includeHttpMethods , HandlerInterceptor interceptor ) {
119- this (null , null , includeHttpMethods , null , interceptor );
121+ public MappedInterceptor (String @ Nullable [] includePatterns , HandlerInterceptor interceptor ) {
122+ this (includePatterns , null , null , null , interceptor , null );
120123 }
121124
122125 /**
123126 * Variant of
124127 * {@link #MappedInterceptor(String[], String[], HttpMethod[], HttpMethod[], HandlerInterceptor, PathPatternParser)}
125128 * without a provided parser.
126129 */
127- public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns , HttpMethod @ Nullable [] includeHttpMethods , HttpMethod @ Nullable [] excludeHttpMethods ,
130+ public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns ,
128131 HandlerInterceptor interceptor ) {
129132
130- this (includePatterns , excludePatterns ,includeHttpMethods , excludeHttpMethods , interceptor , null );
133+ this (includePatterns , excludePatterns , null , null , interceptor , null );
131134 }
132135
133136 /**
@@ -136,26 +139,18 @@ public MappedInterceptor(String @Nullable [] includePatterns, String @Nullable [
136139 * with a {@link WebRequestInterceptor} as the target.
137140 */
138141 public MappedInterceptor (String @ Nullable [] includePatterns , WebRequestInterceptor interceptor ) {
139- this (includePatterns , null ,null ,null , interceptor );
140- }
141- /**
142- * Variant of
143- * {@link #MappedInterceptor(String[], String[], HttpMethod[], HttpMethod[], HandlerInterceptor, PathPatternParser)}
144- * with a {@link WebRequestInterceptor} as the target.
145- */
146- public MappedInterceptor (HttpMethod @ Nullable [] includeHttpMethods , WebRequestInterceptor interceptor ) {
147- this (null , null ,includeHttpMethods ,null , interceptor );
142+ this (includePatterns , null , interceptor );
148143 }
149144
150145 /**
151146 * Variant of
152- * {@link #MappedInterceptor(String[], String[], HttpMethod[], HttpMethod[] , HandlerInterceptor, PathPatternParser)}
147+ * {@link #MappedInterceptor(String[], String[], HttpMethod[], HttpMethod[], HandlerInterceptor, PathPatternParser)}
153148 * with a {@link WebRequestInterceptor} as the target.
154149 */
155- public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns , HttpMethod @ Nullable [] includeHttpMethods , HttpMethod @ Nullable [] excludeHttpMethods ,
150+ public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns ,
156151 WebRequestInterceptor interceptor ) {
157152
158- this (includePatterns , excludePatterns ,includeHttpMethods , excludeHttpMethods , new WebRequestHandlerInterceptorAdapter (interceptor ));
153+ this (includePatterns , excludePatterns , null , null , new WebRequestHandlerInterceptorAdapter (interceptor ), null );
159154 }
160155
161156
@@ -228,7 +223,7 @@ public PathMatcher getPathMatcher() {
228223 */
229224 public boolean matches (HttpServletRequest request ) {
230225 Object path = ServletRequestPathUtils .getCachedPath (request );
231- HttpMethod method = HttpMethod .valueOf (request .getMethod ());
226+ HttpMethod httpMethod = HttpMethod .valueOf (request .getMethod ());
232227 if (this .pathMatcher != defaultPathMatcher ) {
233228 path = path .toString ();
234229 }
@@ -241,47 +236,37 @@ public boolean matches(HttpServletRequest request) {
241236 }
242237 }
243238 if (!ObjectUtils .isEmpty (this .excludeHttpMethods )) {
244- for (MethodAdapter adapter : this .excludeHttpMethods ) {
245- if (adapter . match ( method )) {
239+ for (HttpMethod excluded : this .excludeHttpMethods ) {
240+ if (excluded == httpMethod ) {
246241 return false ;
247242 }
248243 }
249244 }
250- if (ObjectUtils .isEmpty (this .includePatterns ) && ObjectUtils .isEmpty (this .includeHttpMethods )) {
251- return true ;
252- }
253- if (!ObjectUtils .isEmpty (this .includePatterns ) && ObjectUtils .isEmpty (this .includeHttpMethods )) {
245+ if (!ObjectUtils .isEmpty (this .includePatterns )) {
246+ boolean match = false ;
254247 for (PatternAdapter adapter : this .includePatterns ) {
255248 if (adapter .match (path , isPathContainer , this .pathMatcher )) {
256- return true ;
249+ match = true ;
250+ break ;
257251 }
258252 }
259- }
260- if (!ObjectUtils .isEmpty (this .includeHttpMethods ) && ObjectUtils .isEmpty (this .includePatterns )) {
261- for (MethodAdapter adapter : this .includeHttpMethods ) {
262- if (adapter .match (method )) {
263- return true ;
264- }
253+ if (!match ) {
254+ return false ;
265255 }
266256 }
267- if (!ObjectUtils .isEmpty (this .includePatterns ) && ! ObjectUtils . isEmpty ( this . includeHttpMethods )) {
257+ if (!ObjectUtils .isEmpty (this .includeHttpMethods )) {
268258 boolean match = false ;
269- for (MethodAdapter methodAdapter : this .includeHttpMethods ) {
270- if (methodAdapter . match ( method ) ) {
259+ for (HttpMethod included : this .includeHttpMethods ) {
260+ if (included == httpMethod ) {
271261 match = true ;
272262 break ;
273263 }
274264 }
275265 if (!match ) {
276266 return false ;
277267 }
278- for (PatternAdapter pathAdapter : this .includePatterns ) {
279- if (pathAdapter .match (path , isPathContainer , pathMatcher )) {
280- return true ;
281- }
282- }
283268 }
284- return false ;
269+ return true ;
285270 }
286271
287272
@@ -365,40 +350,4 @@ public boolean match(Object path, boolean isPathContainer, PathMatcher pathMatch
365350 }
366351 }
367352
368- /**
369- * Adapts {@link HttpMethod} instances for internal matching purposes.
370- *
371- * <p>Encapsulates an {@link HttpMethod} and provides matching functionality.
372- * Also provides a utility method to initialize arrays of {@code MethodAdapter}
373- * instances from arrays of {@link HttpMethod}.</p>
374- *
375- * @since 7.0.x
376- */
377- private static class MethodAdapter {
378-
379- private final @ Nullable HttpMethod httpMethod ;
380-
381- public MethodAdapter (@ Nullable HttpMethod httpMethod ) {
382- this .httpMethod = httpMethod ;
383- }
384-
385- public boolean match (HttpMethod method ) {
386- return this .httpMethod == method ;
387- }
388-
389- public @ Nullable HttpMethod getHttpMethod () {
390- return this .httpMethod ;
391- }
392-
393- private static MethodAdapter @ Nullable [] initHttpMethods (HttpMethod @ Nullable [] methods ) {
394- if (ObjectUtils .isEmpty (methods )) {
395- return null ;
396- }
397- return Arrays .stream (methods )
398- .map (MethodAdapter ::new )
399- .toArray (MethodAdapter []::new );
400- }
401-
402- }
403-
404353}
0 commit comments