@@ -68,66 +68,69 @@ public final class MappedInterceptor implements HandlerInterceptor {
68
68
69
69
private final PatternAdapter @ Nullable [] excludePatterns ;
70
70
71
- private final MethodAdapter @ Nullable [] includeHttpMethods ;
71
+ private final HttpMethod @ Nullable [] includeHttpMethods ;
72
72
73
- private final MethodAdapter @ Nullable [] excludeHttpMethods ;
73
+ private final HttpMethod @ Nullable [] excludeHttpMethods ;
74
74
75
75
private PathMatcher pathMatcher = defaultPathMatcher ;
76
76
77
77
private final HandlerInterceptor interceptor ;
78
78
79
79
80
80
/**
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
88
86
* @param interceptor the target interceptor
89
87
* @param parser a parser to use to pre-parse patterns into {@link PathPattern};
90
88
* when not provided, {@link PathPatternParser#defaultInstance} is used.
91
- * @since 5.3
89
+ * @since 7.0
92
90
*/
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 ,
94
93
HandlerInterceptor interceptor , @ Nullable PathPatternParser parser ) {
95
94
96
95
this .includePatterns = PatternAdapter .initPatterns (includePatterns , parser );
97
96
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 ;
100
99
this .interceptor = interceptor ;
101
100
}
102
101
103
-
104
102
/**
105
- * Variant of
103
+ * Variation of
106
104
* {@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
108
108
*/
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 );
111
114
}
112
115
113
116
/**
114
117
* Variant of
115
118
* {@link #MappedInterceptor(String[], String[], HttpMethod[], HttpMethod[], HandlerInterceptor, PathPatternParser)}
116
- * with include methods only.
119
+ * with include patterns only.
117
120
*/
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 );
120
123
}
121
124
122
125
/**
123
126
* Variant of
124
127
* {@link #MappedInterceptor(String[], String[], HttpMethod[], HttpMethod[], HandlerInterceptor, PathPatternParser)}
125
128
* without a provided parser.
126
129
*/
127
- public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns , HttpMethod @ Nullable [] includeHttpMethods , HttpMethod @ Nullable [] excludeHttpMethods ,
130
+ public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns ,
128
131
HandlerInterceptor interceptor ) {
129
132
130
- this (includePatterns , excludePatterns ,includeHttpMethods , excludeHttpMethods , interceptor , null );
133
+ this (includePatterns , excludePatterns , null , null , interceptor , null );
131
134
}
132
135
133
136
/**
@@ -136,26 +139,18 @@ public MappedInterceptor(String @Nullable [] includePatterns, String @Nullable [
136
139
* with a {@link WebRequestInterceptor} as the target.
137
140
*/
138
141
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 );
148
143
}
149
144
150
145
/**
151
146
* Variant of
152
- * {@link #MappedInterceptor(String[], String[], HttpMethod[], HttpMethod[] , HandlerInterceptor, PathPatternParser)}
147
+ * {@link #MappedInterceptor(String[], String[], HttpMethod[], HttpMethod[], HandlerInterceptor, PathPatternParser)}
153
148
* with a {@link WebRequestInterceptor} as the target.
154
149
*/
155
- public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns , HttpMethod @ Nullable [] includeHttpMethods , HttpMethod @ Nullable [] excludeHttpMethods ,
150
+ public MappedInterceptor (String @ Nullable [] includePatterns , String @ Nullable [] excludePatterns ,
156
151
WebRequestInterceptor interceptor ) {
157
152
158
- this (includePatterns , excludePatterns ,includeHttpMethods , excludeHttpMethods , new WebRequestHandlerInterceptorAdapter (interceptor ));
153
+ this (includePatterns , excludePatterns , null , null , new WebRequestHandlerInterceptorAdapter (interceptor ), null );
159
154
}
160
155
161
156
@@ -228,7 +223,7 @@ public PathMatcher getPathMatcher() {
228
223
*/
229
224
public boolean matches (HttpServletRequest request ) {
230
225
Object path = ServletRequestPathUtils .getCachedPath (request );
231
- HttpMethod method = HttpMethod .valueOf (request .getMethod ());
226
+ HttpMethod httpMethod = HttpMethod .valueOf (request .getMethod ());
232
227
if (this .pathMatcher != defaultPathMatcher ) {
233
228
path = path .toString ();
234
229
}
@@ -241,47 +236,37 @@ public boolean matches(HttpServletRequest request) {
241
236
}
242
237
}
243
238
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 ) {
246
241
return false ;
247
242
}
248
243
}
249
244
}
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 ;
254
247
for (PatternAdapter adapter : this .includePatterns ) {
255
248
if (adapter .match (path , isPathContainer , this .pathMatcher )) {
256
- return true ;
249
+ match = true ;
250
+ break ;
257
251
}
258
252
}
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 ;
265
255
}
266
256
}
267
- if (!ObjectUtils .isEmpty (this .includePatterns ) && ! ObjectUtils . isEmpty ( this . includeHttpMethods )) {
257
+ if (!ObjectUtils .isEmpty (this .includeHttpMethods )) {
268
258
boolean match = false ;
269
- for (MethodAdapter methodAdapter : this .includeHttpMethods ) {
270
- if (methodAdapter . match ( method ) ) {
259
+ for (HttpMethod included : this .includeHttpMethods ) {
260
+ if (included == httpMethod ) {
271
261
match = true ;
272
262
break ;
273
263
}
274
264
}
275
265
if (!match ) {
276
266
return false ;
277
267
}
278
- for (PatternAdapter pathAdapter : this .includePatterns ) {
279
- if (pathAdapter .match (path , isPathContainer , pathMatcher )) {
280
- return true ;
281
- }
282
- }
283
268
}
284
- return false ;
269
+ return true ;
285
270
}
286
271
287
272
@@ -365,40 +350,4 @@ public boolean match(Object path, boolean isPathContainer, PathMatcher pathMatch
365
350
}
366
351
}
367
352
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
-
404
353
}
0 commit comments