use of io.helidon.webclient.WebClient in project helidon by oracle.
the class HeaderTest method userAgentNotOverridden.
@Test
public void userAgentNotOverridden() {
WebClient webClient = createNewClient(new HeaderTestService(TEST_USER));
webClient.get().headers(headers -> {
headers.add(Http.Header.USER_AGENT, TEST_USER);
return headers;
}).request(JsonObject.class).await();
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class HeaderTest method contentLengthSet.
@Test
public void contentLengthSet() {
WebClient webClient = createNewClient();
String contentLength = webClient.post().path("contentLength").submit().flatMapSingle(response -> response.content().as(String.class)).await();
assertThat(contentLength, is(Http.Header.CONTENT_LENGTH + " is 0"));
contentLength = webClient.put().path("contentLength").submit().flatMapSingle(response -> response.content().as(String.class)).await();
assertThat(contentLength, is(Http.Header.CONTENT_LENGTH + " is 0"));
contentLength = webClient.get().path("contentLength").request().flatMapSingle(response -> response.content().as(String.class)).await();
assertThat(contentLength, is("No " + Http.Header.CONTENT_LENGTH + " has been set"));
String sampleSmallEntity = "Hi there";
contentLength = webClient.post().path("contentLength").submit(sampleSmallEntity).flatMapSingle(response -> response.content().as(String.class)).await();
assertThat(contentLength, is(Http.Header.CONTENT_LENGTH + " is " + sampleSmallEntity.length()));
contentLength = webClient.post().headers(headers -> {
headers.contentLength(0);
return headers;
}).path("contentLength").submit(sampleSmallEntity).flatMapSingle(response -> response.content().as(String.class)).await();
assertThat(contentLength, is(Http.Header.CONTENT_LENGTH + " is " + sampleSmallEntity.length()));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MediaContextTest method testMediaSupportWithoutDefaults.
@Test
public void testMediaSupportWithoutDefaults() throws Exception {
WebClient client = WebClient.builder().baseUri("http://localhost:" + webServer.port() + "/greet").mediaContext(MediaContext.empty()).build();
client.get().request(String.class).thenAccept(it -> fail("No reader for String should be registered!")).exceptionally(ex -> {
assertThat(ex.getCause().getMessage(), is("No reader found for type: class java.lang.String"));
return null;
}).toCompletableFuture().get();
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MediaContextTest method testRequestSpecificReader.
@Test
public void testRequestSpecificReader() throws Exception {
WebClient client = WebClient.builder().baseUri("http://localhost:" + webServer.port() + "/greet").build();
client.get().request(JsonObject.class).thenAccept(it -> fail("JsonObject should not have been handled.")).thenCompose(it -> {
WebClientRequestBuilder requestBuilder = client.get();
requestBuilder.readerContext().registerReader(JsonpSupport.reader());
return requestBuilder.request(JsonObject.class);
}).thenAccept(jsonObject -> assertThat(jsonObject.getString("message"), is(DEFAULT_GREETING + " World!"))).thenCompose(it -> client.get().request(JsonObject.class)).thenAccept(it -> fail("JsonObject should not have been handled.")).exceptionally(throwable -> {
assertThat(throwable.getCause().getMessage(), is("No reader found for type: interface jakarta.json.JsonObject"));
return null;
}).toCompletableFuture().get();
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MediaContextTest method testReaderRegisteredOnClient.
@Test
public void testReaderRegisteredOnClient() throws Exception {
WebClient client = WebClient.builder().baseUri("http://localhost:" + webServer.port() + "/greet").addReader(JsonpSupport.reader()).build();
client.get().request(JsonObject.class).thenAccept(it -> assertThat(it, is(JSON_GREETING))).thenCompose(it -> client.put().path("/greeting").submit(JSON_NEW_GREETING)).thenAccept(it -> fail("No writer for String should be registered!")).exceptionally(ex -> {
assertThat(ex.getCause().getMessage(), is("Transformation failed!"));
return null;
}).toCompletableFuture().get();
}
Aggregations