1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
46
46
import org .springframework .web .server .NotAcceptableStatusException ;
47
47
import org .springframework .web .server .ServerWebExchange ;
48
48
import org .springframework .web .server .ServerWebInputException ;
49
+ import org .springframework .web .server .UnsatisfiedRequestParameterException ;
49
50
import org .springframework .web .server .UnsupportedMediaTypeStatusException ;
50
51
import org .springframework .web .util .pattern .PathPattern ;
51
52
@@ -190,7 +191,8 @@ protected HandlerMethod handleNoMatch(Set<RequestMappingInfo> infos,
190
191
catch (InvalidMediaTypeException ex ) {
191
192
throw new UnsupportedMediaTypeStatusException (ex .getMessage ());
192
193
}
193
- throw new UnsupportedMediaTypeStatusException (contentType , new ArrayList <>(mediaTypes ), exchange .getRequest ().getMethod ());
194
+ throw new UnsupportedMediaTypeStatusException (
195
+ contentType , new ArrayList <>(mediaTypes ), exchange .getRequest ().getMethod ());
194
196
}
195
197
196
198
if (helper .hasProducesMismatch ()) {
@@ -199,9 +201,9 @@ protected HandlerMethod handleNoMatch(Set<RequestMappingInfo> infos,
199
201
}
200
202
201
203
if (helper .hasParamsMismatch ()) {
202
- throw new ServerWebInputException (
203
- "Expected parameters: " + helper .getParamConditions () +
204
- ", actual query parameters: " + request .getQueryParams ());
204
+ throw new UnsatisfiedRequestParameterException (
205
+ helper .getParamConditions (). stream (). map ( Object :: toString ). toList (),
206
+ request .getQueryParams ());
205
207
}
206
208
207
209
return null ;
@@ -217,10 +219,9 @@ private static class PartialMatchHelper {
217
219
218
220
219
221
public PartialMatchHelper (Set <RequestMappingInfo > infos , ServerWebExchange exchange ) {
220
- this .partialMatches .addAll (infos .stream ().
221
- filter (info -> info .getPatternsCondition ().getMatchingCondition (exchange ) != null ).
222
- map (info -> new PartialMatch (info , exchange )).
223
- collect (Collectors .toList ()));
222
+ this .partialMatches .addAll (infos .stream ()
223
+ .filter (info -> info .getPatternsCondition ().getMatchingCondition (exchange ) != null )
224
+ .map (info -> new PartialMatch (info , exchange )).toList ());
224
225
}
225
226
226
227
@@ -235,72 +236,71 @@ public boolean isEmpty() {
235
236
* Any partial matches for "methods"?
236
237
*/
237
238
public boolean hasMethodsMismatch () {
238
- return this .partialMatches .stream ().
239
- noneMatch (PartialMatch ::hasMethodsMatch );
239
+ return this .partialMatches .stream ().noneMatch (PartialMatch ::hasMethodsMatch );
240
240
}
241
241
242
242
/**
243
243
* Any partial matches for "methods" and "consumes"?
244
244
*/
245
245
public boolean hasConsumesMismatch () {
246
- return this .partialMatches .stream ().
247
- noneMatch (PartialMatch ::hasConsumesMatch );
246
+ return this .partialMatches .stream ().noneMatch (PartialMatch ::hasConsumesMatch );
248
247
}
249
248
250
249
/**
251
250
* Any partial matches for "methods", "consumes", and "produces"?
252
251
*/
253
252
public boolean hasProducesMismatch () {
254
- return this .partialMatches .stream ().
255
- noneMatch (PartialMatch ::hasProducesMatch );
253
+ return this .partialMatches .stream ().noneMatch (PartialMatch ::hasProducesMatch );
256
254
}
257
255
258
256
/**
259
257
* Any partial matches for "methods", "consumes", "produces", and "params"?
260
258
*/
261
259
public boolean hasParamsMismatch () {
262
- return this .partialMatches .stream ().
263
- noneMatch (PartialMatch ::hasParamsMatch );
260
+ return this .partialMatches .stream ().noneMatch (PartialMatch ::hasParamsMatch );
264
261
}
265
262
266
263
/**
267
264
* Return declared HTTP methods.
268
265
*/
269
266
public Set <HttpMethod > getAllowedMethods () {
270
- return this .partialMatches .stream ().
271
- flatMap (m -> m .getInfo ().getMethodsCondition ().getMethods ().stream ()).
272
- map (requestMethod -> HttpMethod .valueOf (requestMethod .name ())).
273
- collect (Collectors .toSet ());
267
+ return this .partialMatches .stream ()
268
+ . flatMap (m -> m .getInfo ().getMethodsCondition ().getMethods ().stream ())
269
+ . map (requestMethod -> HttpMethod .valueOf (requestMethod .name ()))
270
+ . collect (Collectors .toSet ());
274
271
}
275
272
276
273
/**
277
274
* Return declared "consumable" types but only among those that also
278
275
* match the "methods" condition.
279
276
*/
280
277
public Set <MediaType > getConsumableMediaTypes () {
281
- return this .partialMatches .stream ().filter (PartialMatch ::hasMethodsMatch ).
282
- flatMap (m -> m .getInfo ().getConsumesCondition ().getConsumableMediaTypes ().stream ()).
283
- collect (Collectors .toCollection (LinkedHashSet ::new ));
278
+ return this .partialMatches .stream ()
279
+ .filter (PartialMatch ::hasMethodsMatch )
280
+ .flatMap (m -> m .getInfo ().getConsumesCondition ().getConsumableMediaTypes ().stream ())
281
+ .collect (Collectors .toCollection (LinkedHashSet ::new ));
284
282
}
285
283
286
284
/**
287
285
* Return declared "producible" types but only among those that also
288
286
* match the "methods" and "consumes" conditions.
289
287
*/
290
288
public Set <MediaType > getProducibleMediaTypes () {
291
- return this .partialMatches .stream ().filter (PartialMatch ::hasConsumesMatch ).
292
- flatMap (m -> m .getInfo ().getProducesCondition ().getProducibleMediaTypes ().stream ()).
293
- collect (Collectors .toCollection (LinkedHashSet ::new ));
289
+ return this .partialMatches .stream ()
290
+ .filter (PartialMatch ::hasConsumesMatch )
291
+ .flatMap (m -> m .getInfo ().getProducesCondition ().getProducibleMediaTypes ().stream ())
292
+ .collect (Collectors .toCollection (LinkedHashSet ::new ));
294
293
}
295
294
296
295
/**
297
296
* Return declared "params" conditions but only among those that also
298
297
* match the "methods", "consumes", and "params" conditions.
299
298
*/
300
299
public List <Set <NameValueExpression <String >>> getParamConditions () {
301
- return this .partialMatches .stream ().filter (PartialMatch ::hasProducesMatch ).
302
- map (match -> match .getInfo ().getParamsCondition ().getExpressions ()).
303
- collect (Collectors .toList ());
300
+ return this .partialMatches .stream ()
301
+ .filter (PartialMatch ::hasProducesMatch )
302
+ .map (match -> match .getInfo ().getParamsCondition ().getExpressions ())
303
+ .collect (Collectors .toList ());
304
304
}
305
305
306
306
/**
0 commit comments