use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class MetricsTest method testErrorHandling.
@Test
public void testErrorHandling() {
WebClientService errorAll = WebClientMetrics.counter().success(false).nameFormat("counter.all.errors.%2$s").build();
WebClientService errorGet = WebClientMetrics.counter().methods(Http.Method.GET).success(false).nameFormat("counter.errors.%1$s.%2$s").build();
WebClientService errorPut = WebClientMetrics.counter().methods(Http.Method.PUT).success(false).nameFormat("counter.errors.%1$s.%2$s").build();
WebClient webClient = createNewClient(errorAll, errorGet, errorPut);
Counter counterAll = FACTORY.counter("counter.all.errors.localhost");
Counter counterGet = FACTORY.counter("counter.errors.GET.localhost");
Counter counterPut = FACTORY.counter("counter.errors.PUT.localhost");
assertThat(counterAll.getCount(), is(0L));
assertThat(counterGet.getCount(), is(0L));
assertThat(counterPut.getCount(), is(0L));
try {
webClient.get().path("/invalid").request().thenCompose(WebClientResponse::close).toCompletableFuture().get();
assertThat(counterAll.getCount(), is(1L));
assertThat(counterGet.getCount(), is(1L));
assertThat(counterPut.getCount(), is(0L));
webClient.put().path("/invalid").submit().thenCompose(WebClientResponse::close).toCompletableFuture().get();
assertThat(counterAll.getCount(), is(2L));
assertThat(counterGet.getCount(), is(1L));
assertThat(counterPut.getCount(), is(1L));
} catch (Exception e) {
fail(e);
}
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class RequestTest method testFollowRedirect.
@Test
public void testFollowRedirect() throws ExecutionException, InterruptedException {
webClient.get().path("/redirect").request(JsonObject.class).thenAccept(jsonObject -> Assertions.assertEquals("Hello World!", jsonObject.getString("message"))).toCompletableFuture().get();
WebClientResponse response = webClient.get().path("/redirect").followRedirects(false).request().toCompletableFuture().get();
assertThat(response.status(), is(Http.Status.MOVED_PERMANENTLY_301));
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class Gh2631Test method testFileNoFallbackMissing.
@Test
void testFileNoFallbackMissing() {
WebClientResponse response = getResponse("/simpleFile/second/");
assertThat(response.status(), is(Http.Status.NOT_FOUND_404));
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class TestDefaultCorsSupport method testOptionsWithCors.
@Test
void testOptionsWithCors() throws ExecutionException, InterruptedException {
WebServer server = null;
WebClient client;
try {
server = WebServer.create(prepRouting(true)).start().toCompletableFuture().get();
client = WebClient.builder().baseUri("http://localhost:" + server.port()).get();
WebClientRequestBuilder reqBuilder = client.options().path("/greet");
Headers h = reqBuilder.headers();
h.add("Origin", "http://foo.com");
h.add("Host", "bar.com");
WebClientResponse response = reqBuilder.submit().toCompletableFuture().get();
WebClientResponseHeaders headers = response.headers();
List<String> allowOrigins = headers.values(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
assertThat(allowOrigins, contains("*"));
} finally {
if (server != null) {
server.shutdown();
}
}
}
use of io.helidon.webclient.WebClientResponse in project helidon by oracle.
the class TestDefaultCorsSupport method testOptionsWithoutCors.
@Test
void testOptionsWithoutCors() throws ExecutionException, InterruptedException {
WebServer server = null;
WebClient client;
try {
server = WebServer.create(prepRouting(false)).start().toCompletableFuture().get();
client = WebClient.builder().baseUri("http://localhost:" + server.port()).get();
WebClientRequestBuilder reqBuilder = client.options().path("/greet");
Headers h = reqBuilder.headers();
h.add("Origin", "http://foo.com");
h.add("Host", "bar.com");
WebClientResponse response = reqBuilder.submit().toCompletableFuture().get();
WebClientResponseHeaders headers = response.headers();
List<String> allowOrigins = headers.values(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
assertThat(allowOrigins.size(), is(0));
} finally {
if (server != null) {
server.shutdown();
}
}
}
Aggregations