Search in sources :

Example 21 with WebClient

use of io.helidon.webclient.WebClient in project helidon by oracle.

the class Status204Test method callPutAndGet.

@Test
void callPutAndGet() throws Exception {
    WebClient webClient = WebClient.builder().baseUri("http://localhost:" + server.port()).build();
    webClient.put().submit("test call").thenAccept(it -> assertThat(it.status(), is(Http.Status.NO_CONTENT_204))).thenCompose(it -> webClient.get().request(String.class)).thenAccept(it -> assertThat(it, is("test"))).toCompletableFuture().get();
}
Also used : Test(org.junit.jupiter.api.Test) CoreMatchers.is(org.hamcrest.CoreMatchers.is) BeforeEach(org.junit.jupiter.api.BeforeEach) AfterEach(org.junit.jupiter.api.AfterEach) WebClient(io.helidon.webclient.WebClient) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Http(io.helidon.common.http.Http) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 22 with WebClient

use of io.helidon.webclient.WebClient in project helidon by oracle.

the class TestHttpParseFineTuning method testDefaults.

@Test
void testDefaults() {
    // default is 8Kb for headers
    // and 4096 for initial line
    WebServer ws = WebServer.builder().host("localhost").routing(Routing.builder().register("/static", StaticContentSupport.create("/static")).any((req, res) -> res.send("any")).build()).build().start().await(10, TimeUnit.SECONDS);
    WebClient client = WebClient.builder().baseUri("http://localhost:" + ws.port()).validateHeaders(false).build();
    testHeader(client, 8000, true);
    testInitialLine(client, 10, true);
    testHeader(client, 8900, false);
    testHeader(client, 8900, false);
    // now test with big initial line
    testInitialLine(client, 5000, false);
    testHeaderName(client, "X_HEADER", true);
    testHeaderName(client, "X\tHEADER", false);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CoreMatchers.is(org.hamcrest.CoreMatchers.is) WebClient(io.helidon.webclient.WebClient) Config(io.helidon.config.Config) WebClientResponse(io.helidon.webclient.WebClientResponse) Map(java.util.Map) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Http(io.helidon.common.http.Http) ConfigSources(io.helidon.config.ConfigSources) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 23 with WebClient

use of io.helidon.webclient.WebClient in project helidon by oracle.

the class TestHttpParseFineTuning method testCustom.

@Test
void testCustom() {
    Config config = Config.create(ConfigSources.create(Map.of("validate-headers", "false")));
    WebServer ws = WebServer.builder().host("localhost").routing(Routing.builder().register("/static", StaticContentSupport.create("/static")).any((req, res) -> res.send("any")).build()).config(config).maxHeaderSize(9100).maxInitialLineLength(5100).build().start().await(10, TimeUnit.SECONDS);
    WebClient client = WebClient.builder().baseUri("http://localhost:" + ws.port()).validateHeaders(false).build();
    testHeader(client, 8000, true);
    testInitialLine(client, 10, true);
    testHeader(client, 8900, true);
    testHeader(client, 8900, true);
    // now test with big initial line
    testInitialLine(client, 5000, true);
    testHeaderName(client, "X_HEADER", true);
    testHeaderName(client, "X\tHEADER", true);
}
Also used : Config(io.helidon.config.Config) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 24 with WebClient

use of io.helidon.webclient.WebClient in project helidon by oracle.

the class ResponseOrderingTest method testOrdering.

@Test
public void testOrdering() throws Exception {
    WebClient webClient = WebClient.builder().baseUri("http://0.0.0.0:" + webServer.port()).build();
    ArrayList<Long> returnedIds = new ArrayList<>();
    int i1 = Optional.ofNullable(System.getenv("REQUESTS_COUNT")).map(Integer::valueOf).orElse(10);
    for (int i = 0; i < i1; i++) {
        webClient.get().path("multi").request(String.class).thenAccept(it -> returnedIds.add(Long.valueOf(it))).toCompletableFuture().get();
    }
    assertThat(returnedIds.toArray(), allOf(arrayWithSize(i1), is(queue.toArray())));
    assertThat("No exceptions expected: " + exceptions(), errorQueue, hasSize(0));
}
Also used : ArrayList(java.util.ArrayList) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 25 with WebClient

use of io.helidon.webclient.WebClient in project helidon by oracle.

the class GraphQlSupportTest method testHelloWorld.

@SuppressWarnings("unchecked")
@Test
void testHelloWorld() {
    WebServer server = WebServer.builder().host("localhost").routing(Routing.builder().register(GraphQlSupport.create(buildSchema())).build()).build().start().await(10, TimeUnit.SECONDS);
    try {
        WebClient webClient = WebClient.builder().addMediaSupport(JsonbSupport.create()).build();
        LinkedHashMap<String, Object> response = webClient.post().uri("http://localhost:" + server.port() + "/graphql").submit("{\"query\": \"{hello}\"}", LinkedHashMap.class).await(10, TimeUnit.SECONDS);
        Map<String, Object> data = (Map<String, Object>) response.get("data");
        assertThat("POST errors: " + response.get("errors"), data, notNullValue());
        assertThat("POST", data.get("hello"), is("world"));
        response = webClient.get().uri("http://localhost:" + server.port() + "/graphql").queryParam("query", "{hello}").request(LinkedHashMap.class).await(10, TimeUnit.SECONDS);
        data = (Map<String, Object>) response.get("data");
        assertThat("GET errors: " + response.get("errors"), data, notNullValue());
        assertThat("GET", data.get("hello"), is("world"));
    } finally {
        server.shutdown();
    }
}
Also used : WebServer(io.helidon.webserver.WebServer) WebClient(io.helidon.webclient.WebClient) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Aggregations

WebClient (io.helidon.webclient.WebClient)58 Test (org.junit.jupiter.api.Test)42 WebClientResponse (io.helidon.webclient.WebClientResponse)21 JsonObject (jakarta.json.JsonObject)15 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)13 Http (io.helidon.common.http.Http)11 Config (io.helidon.config.Config)11 Collections (java.util.Collections)10 WebClientRequestBuilder (io.helidon.webclient.WebClientRequestBuilder)9 WebClientService (io.helidon.webclient.spi.WebClientService)9 Json (jakarta.json.Json)9 JsonBuilderFactory (jakarta.json.JsonBuilderFactory)8 IOException (java.io.IOException)8 DataChunk (io.helidon.common.http.DataChunk)7 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)7 CompletionException (java.util.concurrent.CompletionException)7 Context (io.helidon.common.context.Context)6 List (java.util.List)6 TimeUnit (java.util.concurrent.TimeUnit)6 Counter (org.eclipse.microprofile.metrics.Counter)6