@@ -165,20 +165,23 @@ public List<HandlerMapping> getHandlerMappings() {
165
165
@ Nullable
166
166
public MatchableHandlerMapping getMatchableHandlerMapping (HttpServletRequest request ) throws Exception {
167
167
HttpServletRequest requestToUse = new AttributesPreservingRequest (request );
168
- return doWithHandlerMapping (requestToUse , false , (mapping , executionChain ) -> {
169
- if (mapping instanceof MatchableHandlerMapping ) {
170
- PathPatternMatchableHandlerMapping pathPatternMapping = this .pathPatternMappings .get (mapping );
171
- if (pathPatternMapping != null ) {
172
- RequestPath requestPath = ServletRequestPathUtils .getParsedRequestPath (requestToUse );
173
- return new LookupPathMatchableHandlerMapping (pathPatternMapping , requestPath );
174
- }
175
- else {
176
- String lookupPath = (String ) requestToUse .getAttribute (UrlPathHelper .PATH_ATTRIBUTE );
177
- return new LookupPathMatchableHandlerMapping ((MatchableHandlerMapping ) mapping , lookupPath );
178
- }
168
+ return doWithHandlerMapping (requestToUse , false ,
169
+ (mapping , executionChain ) -> createMatchableHandlerMapping (mapping , requestToUse ));
170
+ }
171
+
172
+ private MatchableHandlerMapping createMatchableHandlerMapping (HandlerMapping mapping , HttpServletRequest request ) {
173
+ if (mapping instanceof MatchableHandlerMapping ) {
174
+ PathPatternMatchableHandlerMapping pathPatternMapping = this .pathPatternMappings .get (mapping );
175
+ if (pathPatternMapping != null ) {
176
+ RequestPath requestPath = ServletRequestPathUtils .getParsedRequestPath (request );
177
+ return new LookupPathMatchableHandlerMapping (pathPatternMapping , requestPath );
179
178
}
180
- throw new IllegalStateException ("HandlerMapping is not a MatchableHandlerMapping" );
181
- });
179
+ else {
180
+ String lookupPath = (String ) request .getAttribute (UrlPathHelper .PATH_ATTRIBUTE );
181
+ return new LookupPathMatchableHandlerMapping ((MatchableHandlerMapping ) mapping , lookupPath );
182
+ }
183
+ }
184
+ throw new IllegalStateException ("HandlerMapping is not a MatchableHandlerMapping" );
182
185
}
183
186
184
187
@ Override
@@ -187,24 +190,28 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
187
190
try {
188
191
boolean ignoreException = true ;
189
192
AttributesPreservingRequest requestToUse = new AttributesPreservingRequest (request );
190
- return doWithHandlerMapping (requestToUse , ignoreException , (handlerMapping , executionChain ) -> {
191
- for (HandlerInterceptor interceptor : executionChain .getInterceptorList ()) {
192
- if (interceptor instanceof CorsConfigurationSource source ) {
193
- return source .getCorsConfiguration (requestToUse );
194
- }
195
- }
196
- if (executionChain .getHandler () instanceof CorsConfigurationSource source ) {
197
- return source .getCorsConfiguration (requestToUse );
198
- }
199
- return null ;
200
- });
193
+ return doWithHandlerMapping (requestToUse , ignoreException ,
194
+ (handlerMapping , executionChain ) -> getCorsConfiguration (requestToUse , executionChain ));
201
195
}
202
196
catch (Exception ex ) {
203
197
// HandlerMapping exceptions have been ignored. Some more basic error perhaps like request parsing
204
198
throw new IllegalStateException (ex );
205
199
}
206
200
}
207
201
202
+ @ Nullable
203
+ private static CorsConfiguration getCorsConfiguration (HttpServletRequest request , HandlerExecutionChain chain ) {
204
+ for (HandlerInterceptor interceptor : chain .getInterceptorList ()) {
205
+ if (interceptor instanceof CorsConfigurationSource source ) {
206
+ return source .getCorsConfiguration (request );
207
+ }
208
+ }
209
+ if (chain .getHandler () instanceof CorsConfigurationSource source ) {
210
+ return source .getCorsConfiguration (request );
211
+ }
212
+ return null ;
213
+ }
214
+
208
215
@ Nullable
209
216
private <T > T doWithHandlerMapping (
210
217
HttpServletRequest request , boolean ignoreException ,
0 commit comments