diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java index fb99f6dec1..14f9232ca1 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java @@ -39,7 +39,6 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.method.HandlerMethod; import org.springframework.web.reactive.HandlerMapping; -import org.springframework.web.reactive.result.condition.NameValueExpression; import org.springframework.web.reactive.result.condition.ParamsRequestCondition; import org.springframework.web.server.BadRequestStatusException; import org.springframework.web.server.MethodNotAllowedException; @@ -214,7 +213,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe Set consumableMediaTypes; Set producibleMediaTypes; - List paramConditions; + List> paramConditions; if (patternAndMethodMatches.isEmpty()) { consumableMediaTypes = getConsumableMediaTypes(exchange, patternMatches); @@ -247,7 +246,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe entry -> entry.getValue().toArray(new String[entry.getValue().size()])) ); throw new BadRequestStatusException("Unsatisfied query parameter conditions: " + - paramConditions + ", actual: " + params); + paramConditions + ", actual parameters: " + params); } else { return null; @@ -279,23 +278,15 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe return result; } - private List getRequestParams(ServerWebExchange exchange, + private List> getRequestParams(ServerWebExchange exchange, Set partialMatches) { - List result = new ArrayList<>(); - for (RequestMappingInfo partialMatch : partialMatches) { - ParamsRequestCondition condition = partialMatch.getParamsCondition(); - Set> expressions = condition.getExpressions(); - if (!CollectionUtils.isEmpty(expressions) && condition.getMatchingCondition(exchange) == null) { - int i = 0; - String[] array = new String[expressions.size()]; - for (NameValueExpression expression : expressions) { - array[i++] = expression.toString(); - } - result.add(array); - } - } - return result; + return partialMatches.stream() + .map(RequestMappingInfo::getParamsCondition) + .filter(condition -> condition.getMatchingCondition(exchange) == null) + .map(ParamsRequestCondition::getExpressions) + .map(expressions -> expressions.stream().map(Object::toString).collect(Collectors.toList())) + .collect(Collectors.toList()); } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java index 7239f8ed8b..174e99458c 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java @@ -27,7 +27,6 @@ import java.util.Optional; import java.util.Set; import java.util.function.Consumer; -import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; import reactor.core.publisher.Mono; @@ -60,7 +59,6 @@ import org.springframework.web.server.adapter.DefaultServerWebExchange; import org.springframework.web.server.session.WebSessionManager; import org.springframework.web.util.HttpRequestPathHelper; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -211,7 +209,8 @@ public class RequestMappingInfoHandlerMappingTests { ServerWebExchange exchange = createExchange(HttpMethod.GET, "/params"); Mono mono = this.handlerMapping.getHandler(exchange); assertError(mono, BadRequestStatusException.class, ex -> { - assertThat(ex.getReason(), Matchers.startsWith("Unsatisfied query parameter conditions:")); + assertEquals(ex.getReason(), "Unsatisfied query parameter conditions: " + + "[[bar=baz], [foo=bar]], actual parameters: {}"); }); }