@@ -164,17 +164,16 @@ public List<HandlerMapping> getHandlerMappings() {
164
164
*/
165
165
@ Nullable
166
166
public MatchableHandlerMapping getMatchableHandlerMapping (HttpServletRequest request ) throws Exception {
167
- HttpServletRequest wrappedRequest = new AttributesPreservingRequest (request );
168
-
169
- return doWithHandlerMapping (wrappedRequest , false , (mapping , executionChain ) -> {
167
+ HttpServletRequest requestToUse = new AttributesPreservingRequest (request );
168
+ return doWithHandlerMapping (requestToUse , false , (mapping , executionChain ) -> {
170
169
if (mapping instanceof MatchableHandlerMapping ) {
171
170
PathPatternMatchableHandlerMapping pathPatternMapping = this .pathPatternMappings .get (mapping );
172
171
if (pathPatternMapping != null ) {
173
- RequestPath requestPath = ServletRequestPathUtils .getParsedRequestPath (wrappedRequest );
172
+ RequestPath requestPath = ServletRequestPathUtils .getParsedRequestPath (requestToUse );
174
173
return new LookupPathMatchableHandlerMapping (pathPatternMapping , requestPath );
175
174
}
176
175
else {
177
- String lookupPath = (String ) wrappedRequest .getAttribute (UrlPathHelper .PATH_ATTRIBUTE );
176
+ String lookupPath = (String ) requestToUse .getAttribute (UrlPathHelper .PATH_ATTRIBUTE );
178
177
return new LookupPathMatchableHandlerMapping ((MatchableHandlerMapping ) mapping , lookupPath );
179
178
}
180
179
}
@@ -185,18 +184,25 @@ public MatchableHandlerMapping getMatchableHandlerMapping(HttpServletRequest req
185
184
@ Override
186
185
@ Nullable
187
186
public CorsConfiguration getCorsConfiguration (HttpServletRequest request ) {
188
- AttributesPreservingRequest wrappedRequest = new AttributesPreservingRequest (request );
189
- return doWithHandlerMappingIgnoringException (wrappedRequest , (handlerMapping , executionChain ) -> {
190
- for (HandlerInterceptor interceptor : executionChain .getInterceptorList ()) {
191
- if (interceptor instanceof CorsConfigurationSource ccs ) {
192
- return ccs .getCorsConfiguration (wrappedRequest );
187
+ try {
188
+ boolean ignoreException = true ;
189
+ 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
+ }
193
195
}
194
- }
195
- if (executionChain .getHandler () instanceof CorsConfigurationSource ccs ) {
196
- return ccs .getCorsConfiguration (wrappedRequest );
197
- }
198
- return null ;
199
- });
196
+ if (executionChain .getHandler () instanceof CorsConfigurationSource source ) {
197
+ return source .getCorsConfiguration (requestToUse );
198
+ }
199
+ return null ;
200
+ });
201
+ }
202
+ catch (Exception ex ) {
203
+ // HandlerMapping exceptions have been ignored. Some more basic error perhaps like request parsing
204
+ throw new IllegalStateException (ex );
205
+ }
200
206
}
201
207
202
208
@ Nullable
@@ -237,18 +243,6 @@ private <T> T doWithHandlerMapping(
237
243
return null ;
238
244
}
239
245
240
- @ Nullable
241
- private <T > T doWithHandlerMappingIgnoringException (
242
- HttpServletRequest request , BiFunction <HandlerMapping , HandlerExecutionChain , T > matchHandler ) {
243
-
244
- try {
245
- return doWithHandlerMapping (request , true , matchHandler );
246
- }
247
- catch (Exception ex ) {
248
- throw new IllegalStateException ("HandlerMapping exception not suppressed" , ex );
249
- }
250
- }
251
-
252
246
253
247
/**
254
248
* Request wrapper that buffers request attributes in order protect the
0 commit comments