diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java index a5df857b40..d14adf878d 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMappingIntegrationTests.java @@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.util.DefaultUriBuilderFactory; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @@ -56,8 +57,10 @@ public static void afterClass() { @Test public void requestsToManagementPortReturn404() { + String baseUrl = "http://localhost:" + managementPort; testClient.mutate() - .baseUrl("http://localhost:" + managementPort) + .uriBuilderFactory(new DefaultUriBuilderFactory(baseUrl)) + .baseUrl(baseUrl) .build() .get() .uri("/get") @@ -69,8 +72,10 @@ public void requestsToManagementPortReturn404() { @Test public void requestsToManagementPortAndHostHeaderReturn404() { String host = "example.com:8888"; + String baseUrl = "http://localhost:" + managementPort; testClient.mutate() - .baseUrl("http://localhost:" + managementPort) + .uriBuilderFactory(new DefaultUriBuilderFactory(baseUrl)) + .baseUrl(baseUrl) .build() .get() .uri("/get") diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java index e078d923c6..20f94b9a07 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/test/BaseWebClientTests.java @@ -42,6 +42,8 @@ import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.server.ServerWebExchange; +import org.springframework.web.util.DefaultUriBuilderFactory; +import org.springframework.web.util.UriComponentsBuilder; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_HANDLER_MAPPER_ATTR; import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_ROUTE_ATTR; @@ -76,7 +78,12 @@ public void setup() throws Exception { protected void setup(ClientHttpConnector httpConnector, String baseUri) { this.baseUri = baseUri; this.webClient = WebClient.builder().clientConnector(httpConnector).baseUrl(this.baseUri).build(); - this.testClient = WebTestClient.bindToServer(httpConnector).baseUrl(this.baseUri).build(); + DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory(this.baseUri); + uriBuilderFactory.setParserType(UriComponentsBuilder.ParserType.WHAT_WG); + this.testClient = WebTestClient.bindToServer(httpConnector) + .uriBuilderFactory(uriBuilderFactory) + .baseUrl(this.baseUri) + .build(); } @Configuration(proxyBeanMethods = false)