Skip to content

Commit 7f954eb

Browse files
committed
Inject UriComponentsBuilder relative to webapp root
Issue: SPR-16813
1 parent 4da43de commit 7f954eb

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolver.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.web.reactive.result.method.annotation;
1818

19+
import java.net.URI;
1920
import java.time.ZoneId;
2021
import java.util.Locale;
2122
import java.util.TimeZone;
@@ -109,7 +110,8 @@ else if (ZoneId.class == paramType) {
109110
return timeZone != null ? timeZone.toZoneId() : ZoneId.systemDefault();
110111
}
111112
else if (UriBuilder.class == paramType || UriComponentsBuilder.class == paramType) {
112-
return UriComponentsBuilder.fromUri(exchange.getRequest().getURI());
113+
URI uri = exchange.getRequest().getURI();
114+
return UriComponentsBuilder.fromUri(uri).replacePath(null).replaceQuery(null);
113115
}
114116
else {
115117
// should never happen...

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeArgumentResolverTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Locale;
2121
import java.util.TimeZone;
2222

23+
import org.junit.Before;
2324
import org.junit.Test;
2425
import reactor.core.publisher.Mono;
2526

@@ -52,7 +53,8 @@ public class ServerWebExchangeArgumentResolverTests {
5253
private final ServerWebExchangeArgumentResolver resolver =
5354
new ServerWebExchangeArgumentResolver(ReactiveAdapterRegistry.getSharedInstance());
5455

55-
private final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
56+
private final MockServerWebExchange exchange = MockServerWebExchange.from(
57+
MockServerHttpRequest.get("http://example.org:9999/path?q=foo"));
5658

5759
private ResolvableMethod testMethod = ResolvableMethod.on(getClass()).named("handle").build();
5860

@@ -104,7 +106,7 @@ public void resolveUriComponentsBuilder() {
104106

105107
assertNotNull(value);
106108
assertEquals(UriComponentsBuilder.class, value.getClass());
107-
assertEquals("/path/next", ((UriComponentsBuilder) value).path("/next").build().toUriString());
109+
assertEquals("http://example.org:9999/next", ((UriComponentsBuilder) value).path("/next").toUriString());
108110
}
109111

110112

0 commit comments

Comments
 (0)