use of io.helidon.webclient.WebClient in project helidon by oracle.
the class LifeCycleExtension method shutdown.
/**
* Shutdown test application
*/
public void shutdown() {
WebClient testClient = WebClient.builder().baseUri(String.format("http://localhost:%d", HelidonProcessRunner.HTTP_PORT)).build();
WebClientResponse response = testClient.get().path("/Exit").submit().await(1, TimeUnit.MINUTES);
LOGGER.info(() -> String.format("Status: %s", response.status()));
LOGGER.info(() -> String.format("Response: %s", response.content().as(String.class).await(1, TimeUnit.MINUTES)));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class GreetService method basicAuthOutbound.
private void basicAuthOutbound(ServerRequest serverRequest, ServerResponse response) {
WebClient webClient = WebClient.builder().baseUri("http://localhost:" + Main.serverPort + "/greet/secure/basic").addService(WebClientSecurity.create()).build();
webClient.get().request().thenAccept(clientResponse -> {
response.status(clientResponse.status());
response.send(clientResponse.content());
}).exceptionally(throwable -> {
response.status(Http.Status.INTERNAL_SERVER_ERROR_500);
response.send();
return null;
});
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class ContextCheckTest method testContextCheck.
@Test
void testContextCheck() {
WebClient webClient = createNewClient();
WebClientResponse r = webClient.get().path("/contextCheck").property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, "jack").property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, "password").request().await();
assertThat(r.status().code(), is(Http.Status.OK_200.code()));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MediaContextTest method testWriterRegisteredOnClient.
@Test
public void testWriterRegisteredOnClient() throws Exception {
WebClient client = WebClient.builder().baseUri("http://localhost:" + webServer.port() + "/greet").addWriter(JsonpSupport.writer()).build();
client.put().path("/greeting").submit(JSON_NEW_GREETING).thenCompose(it -> client.get().request(JsonObject.class)).thenAccept(it -> fail("JsonReader should not be registered!")).exceptionally(ex -> {
assertThat(ex.getCause().getMessage(), is("No reader found for type: interface jakarta.json.JsonObject"));
return null;
}).thenCompose(// Cleanup
it -> client.put().path("/greeting").submit(JSON_OLD_GREETING)).toCompletableFuture().get();
}
use of io.helidon.webclient.WebClient 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);
}
}
Aggregations