diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java index 5ab9d2cc5d3..d7a69747684 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java @@ -42,7 +42,6 @@ import org.springframework.web.server.WebSession; import org.springframework.web.util.UriUtils; import org.springframework.web.util.patterns.PathPattern; import org.springframework.web.util.patterns.PathPatternParser; -import org.springframework.web.util.patterns.PathRemainingMatchInfo; /** * Implementations of {@link RequestPredicate} that implement various useful @@ -344,7 +343,7 @@ public abstract class RequestPredicates { boolean match = this.pattern.matches(path); traceMatch("Pattern", this.pattern.getPatternString(), path, match); if (match) { - mergeTemplateVariables(request); + mergeTemplateVariables(request, this.pattern.matchAndExtract(request.path())); return true; } else { @@ -354,25 +353,24 @@ public abstract class RequestPredicates { @Override public Optional nest(ServerRequest request) { - PathRemainingMatchInfo info = this.pattern.getPathRemaining(request.path()); - String remainingPath = (info == null ? null : info.getPathRemaining()); - return Optional.ofNullable(remainingPath) - .map(path -> !path.startsWith("/") ? "/" + path : path) - .map(path -> { - // TODO: re-enable when SPR-15419 has been fixed. - // mergeTemplateVariables(request); + return Optional.ofNullable(this.pattern.getPathRemaining(request.path())) + .map(info -> { + mergeTemplateVariables(request, info.getMatchingVariables()); + String path = info.getPathRemaining(); + if (!path.startsWith("/")) { + path = "/" + path; + } return new SubPathServerRequestWrapper(request, path); }); } - private void mergeTemplateVariables(ServerRequest request) { - Map newVariables = this.pattern.matchAndExtract(request.path()); - if (!newVariables.isEmpty()) { + private void mergeTemplateVariables(ServerRequest request, Map variables) { + if (!variables.isEmpty()) { Map oldVariables = request.pathVariables(); - Map variables = new LinkedHashMap<>(oldVariables); - variables.putAll(newVariables); + Map mergedVariables = new LinkedHashMap<>(oldVariables); + mergedVariables.putAll(variables); request.attributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, - Collections.unmodifiableMap(variables)); + Collections.unmodifiableMap(mergedVariables)); } } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java index b11d465e1b1..ae5a3d4affb 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java @@ -16,7 +16,6 @@ package org.springframework.web.reactive.function.server; -import org.junit.Ignore; import org.junit.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -71,7 +70,6 @@ public class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrati } @Test - @Ignore("SPR-15419") public void variables() throws Exception { ResponseEntity result = restTemplate.getForEntity("http://localhost:" + port + "/1/2/3", String.class);