Search in sources :

Example 11 with WebClient

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

the class MutualTlsTest method testClientAndServerUpdateTls.

@Test
public void testClientAndServerUpdateTls() {
    int portSecured = webServer.port("secured");
    int portDefault = webServer.port();
    WebClient webClientFirst = createWebClient(CONFIG.get("success"));
    WebClient webClientSecond = createWebClient(CONFIG.get("client-second-valid"));
    assertThat(executeRequest(webClientFirst, "https", portSecured), is("Hello Helidon-client!"));
    CompletionException exception = assertThrows(CompletionException.class, () -> executeRequest(webClientSecond, "https", portSecured));
    assertThat(exception.getCause().getMessage(), endsWith("unable to find valid certification path to requested target"));
    String response = webClientFirst.get().uri("http://localhost:" + portDefault + "/reload").request(String.class).await();
    assertThat(response, is("SslContext reloaded. Affected named socket: secured"));
    assertThat(executeRequest(webClientSecond, "https", portSecured), is("Hello Oracle-client!"));
    exception = assertThrows(CompletionException.class, () -> executeRequest(webClientFirst, "https", portSecured));
    assertThat(exception.getCause().getMessage(), endsWith("unable to find valid certification path to requested target"));
    response = webClientFirst.get().uri("http://localhost:" + portDefault + "/reload").request(String.class).await();
    assertThat(response, is("SslContext reloaded. Affected named socket: secured"));
    assertThat(executeRequest(webClientFirst, "https", portSecured), is("Hello Helidon-client!"));
    exception = assertThrows(CompletionException.class, () -> executeRequest(webClientSecond, "https", portSecured));
    assertThat(exception.getCause().getMessage(), endsWith("unable to find valid certification path to requested target"));
}
Also used : CompletionException(java.util.concurrent.CompletionException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 12 with WebClient

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

the class MutualTlsTest method testClientNoCa.

@Test
public void testClientNoCa() {
    int port = webServer.port("client-no-ca");
    WebClient webClientOne = createWebClient(CONFIG.get("client-no-ca"));
    CompletionException exception = assertThrows(CompletionException.class, () -> executeRequest(webClientOne, "https", port));
    assertThat(exception.getCause().getMessage(), endsWith("unable to find valid certification path to requested target"));
    WebClient webClientTwo = createWebClient(CONFIG.get("client-trust-all"));
    assertThat(executeRequest(webClientTwo, "https", port), is("Hello Helidon-client!"));
}
Also used : CompletionException(java.util.concurrent.CompletionException) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 13 with WebClient

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

the class MutualTlsTest method testAccessSuccessful.

@Test
public void testAccessSuccessful() {
    WebClient webClient = createWebClient(CONFIG.get("success"));
    String result = webClient.get().uri("http://localhost:" + webServer.port()).request(String.class).await();
    assertThat(result, is("Hello world unsecured!"));
    assertThat(executeRequest(webClient, "https", webServer.port("secured")), is("Hello Helidon-client!"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WebClient(io.helidon.webclient.WebClient) Test(org.junit.jupiter.api.Test)

Example 14 with WebClient

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

the class TestParent method createNewClient.

protected static WebClient createNewClient(WebClientService... clientServices) {
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.builder().build()).build();
    SecurityContext securityContext = security.createContext("unit-test");
    Context context = Context.builder().id("unit-test").build();
    context.register(securityContext);
    WebClient.Builder builder = WebClient.builder().baseUri("http://localhost:" + webServer.port() + "/greet").config(CONFIG.get("client")).context(context).addMediaSupport(JsonpSupport.create());
    Stream.of(clientServices).forEach(builder::addService);
    return builder.build();
}
Also used : Context(io.helidon.common.context.Context) SecurityContext(io.helidon.security.SecurityContext) SecurityContext(io.helidon.security.SecurityContext) Security(io.helidon.security.Security) WebClient(io.helidon.webclient.WebClient)

Example 15 with WebClient

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

the class UriPartTest method testQueryNotDoubleEncoded.

@Test
public void testQueryNotDoubleEncoded() {
    WebClient webClient = createNewClient(request -> {
        assertThat(request.query(), is("first%26second%26=val%26ue%26"));
        return Single.just(request);
    });
    String response = webClient.get().queryParam("first&second%26", "val&ue%26").request(String.class).await();
    assertThat(response.trim(), is("{\"message\":\"Hello World!\"}"));
}
Also used : WebClient(io.helidon.webclient.WebClient) 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