Search in sources :

Example 21 with WebClientRequestBuilder

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

the class AbstractCorsTest method test1ActualAllowedOrigin.

@Test
void test1ActualAllowedOrigin() throws ExecutionException, InterruptedException {
    WebClientRequestBuilder reqBuilder = client().put().path(path(SERVICE_1)).contentType(MediaType.TEXT_PLAIN);
    Headers headers = reqBuilder.headers();
    headers.add(ORIGIN, "http://foo.bar");
    headers.add(ACCESS_CONTROL_REQUEST_METHOD, "PUT");
    WebClientResponse res = reqBuilder.submit("").toCompletableFuture().get();
    assertThat(res.status(), is(Http.Status.OK_200));
    assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_ORIGIN), present(is("*")));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) Headers(io.helidon.common.http.Headers) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 22 with WebClientRequestBuilder

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

the class MaxPayloadSizeTest method testContentLengthExceeded.

/**
 * If content length is greater than max, a 413 must be returned. No actual
 * payload in this case.
 */
@Test
public void testContentLengthExceeded() {
    WebClientRequestBuilder builder = webClient.post();
    // over max
    builder.headers().add("Content-Length", "512");
    WebClientResponse response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).request().await(5, TimeUnit.SECONDS);
    assertThat(response.status().code(), is(Http.Status.REQUEST_ENTITY_TOO_LARGE_413.code()));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 23 with WebClientRequestBuilder

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

the class MaxPayloadSizeTest method testActualLengthExceededWithPayload.

/**
 * If actual payload length is greater than max when using chunked encoding, a 413
 * must be returned. Given that this publisher can write up to 3 chunks (using chunked
 * encoding), we also check for a connection reset exception condition.
 */
@Test
public void testActualLengthExceededWithPayload() {
    try {
        WebClientRequestBuilder builder = webClient.post();
        WebClientResponse response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).submit(new PayloadPublisher(PAYLOAD, 3)).await(5, TimeUnit.SECONDS);
        assertThat(response.status().code(), is(Http.Status.REQUEST_ENTITY_TOO_LARGE_413.code()));
    } catch (CompletionException e) {
        assertTrue(isConnectionReset(e));
    }
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) CompletionException(java.util.concurrent.CompletionException) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 24 with WebClientRequestBuilder

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

the class MaxPayloadSizeTest method testMixedGoodAndBadPayloads.

/**
 * Tests mixed requests, some that exceed limits, others that do not.
 */
@Test
public void testMixedGoodAndBadPayloads() {
    WebClientRequestBuilder builder = webClient.post();
    WebClientResponse response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).submit(PAYLOAD.substring(0, 100)).await(5, TimeUnit.SECONDS);
    assertThat(response.status().code(), is(Http.Status.OK_200.code()));
    builder = webClient.post();
    response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).submit(new PayloadPublisher(PAYLOAD, 1)).await(5, TimeUnit.SECONDS);
    assertThat(response.status().code(), is(Http.Status.REQUEST_ENTITY_TOO_LARGE_413.code()));
    builder = webClient.post();
    response = builder.path("/maxpayload").contentType(MediaType.APPLICATION_OCTET_STREAM).submit(PAYLOAD.substring(0, (int) MAX_PAYLOAD_SIZE)).await(5, TimeUnit.SECONDS);
    assertThat(response.status().code(), is(Http.Status.OK_200.code()));
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 25 with WebClientRequestBuilder

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

the class TestHttpParseFineTuning method testHeaderName.

private void testHeaderName(WebClient client, String headerName, boolean success) {
    WebClientRequestBuilder builder = client.get();
    builder.headers().add(headerName, "some random value");
    WebClientResponse response = builder.path("/static/static-content.txt").request().await(10, TimeUnit.SECONDS);
    if (success) {
        assertThat("Header '" + headerName + "' should have passed", response.status(), is(Http.Status.OK_200));
        assertThat("This request should return content of static-content.txt", response.content().as(String.class).await(10, TimeUnit.SECONDS), is("Hi"));
    } else {
        assertThat("Header '" + headerName + "' should have failed", response.status(), is(Http.Status.BAD_REQUEST_400));
    }
}
Also used : WebClientResponse(io.helidon.webclient.WebClientResponse) WebClientRequestBuilder(io.helidon.webclient.WebClientRequestBuilder)

Aggregations

WebClientRequestBuilder (io.helidon.webclient.WebClientRequestBuilder)50 WebClientResponse (io.helidon.webclient.WebClientResponse)37 Test (org.junit.jupiter.api.Test)34 Headers (io.helidon.common.http.Headers)24 Http (io.helidon.common.http.Http)9 WebClient (io.helidon.webclient.WebClient)9 JsonObject (jakarta.json.JsonObject)8 Order (org.junit.jupiter.api.Order)8 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)8 Single (io.helidon.common.reactive.Single)7 Logger (java.util.logging.Logger)7 Optional (java.util.Optional)6 JsonBuilderFactory (jakarta.json.JsonBuilderFactory)5 Contexts (io.helidon.common.context.Contexts)4 Config (io.helidon.config.Config)4 URI (java.net.URI)4 DataChunk (io.helidon.common.http.DataChunk)3 MediaType (io.helidon.common.http.MediaType)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Flow (java.util.concurrent.Flow)3