This commit is contained in:
Spencer Gibb
2017-10-09 16:00:55 -04:00
parent b4ad42a83a
commit d2c5ee0439
3 changed files with 13 additions and 13 deletions

View File

@@ -67,9 +67,11 @@ public class LoadBalancerClientFilter implements GlobalFilter, Ordered {
final ServiceInstance instance = loadBalancer.choose(url.getHost());
if (instance == null) {
throw new NotFoundException("");
throw new NotFoundException("Unable to find instance for " + url.getHost());
}
/*URI uri = exchange.getRequest().getURI();
URI requestUrl = loadBalancer.reconstructURI(instance, uri);*/
URI requestUrl = UriComponentsBuilder.fromUri(url)
.scheme(instance.isSecure()? "https" : "http") //TODO: support websockets
.host(instance.getHost())

View File

@@ -39,6 +39,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.codec.multipart.Part;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -67,6 +68,7 @@ public class BaseWebClientTests {
@LocalServerPort
protected int port = 0;
protected WebTestClient testClient;
protected WebClient webClient;
protected String baseUri;
@@ -75,6 +77,7 @@ public class BaseWebClientTests {
//TODO: how to set new ReactorClientHttpConnector()
baseUri = "http://localhost:" + port;
this.webClient = WebClient.create(baseUri);
this.testClient = WebTestClient.bindToServer().baseUrl(baseUri).build();
}
@RestController

View File

@@ -45,7 +45,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.cloud.gateway.test.TestUtils.assertStatus;
import static org.springframework.cloud.gateway.test.TestUtils.getMap;
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -61,22 +60,18 @@ public class GatewayIntegrationTests extends BaseWebClientTests {
@Test
public void complexContentTypeWorks() {
Mono<Map> result = webClient.post()
testClient.post()
.uri("/headers")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.syncBody("testdata")
.header("Host", "www.complexcontenttype.org")
.exchange()
.flatMap(response -> response.body(toMono(Map.class)));
StepVerifier.create(result)
.consumeNextWith(
response -> {
Map<String, Object> headers = getMap(response, "headers");
assertThat(headers).containsEntry(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE);
})
.expectComplete()
.verify(DURATION);
.expectStatus().isOk()
.expectBody(Map.class)
.consumeWith(result -> {
Map<String, Object> headers = getMap(result.getResponseBody(), "headers");
assertThat(headers).containsEntry(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE);
});
}
@Test