use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class SslTest method multipleSslRequestsKeepAlive.
@Test
public void multipleSslRequestsKeepAlive() throws Exception {
WebClientRequestBuilder requestBuilder = client.get().uri("https://localhost:" + webServer.port());
// send an entity that won't be consumed, as such a new connection will be created by the server
requestBuilder.request(String.class).thenAccept(it -> assertThat(it, is("It works!"))).thenCompose(it -> requestBuilder.request(String.class)).thenAccept(it -> assertThat(it, is("It works!"))).toCompletableFuture().get();
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class TestHttpParseFineTuning method testHeader.
private void testHeader(WebClient client, int size, boolean success) {
String headerValue = longString(size);
WebClientRequestBuilder builder = client.get();
builder.headers().add("X_HEADER", headerValue);
WebClientResponse response = builder.path("/static/static-content.txt").request().await(10, TimeUnit.SECONDS);
if (success) {
assertThat("Header of size " + size + " 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 of size " + size + " should have failed", response.status(), is(Http.Status.BAD_REQUEST_400));
}
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class OidcSupport method processCode.
private void processCode(String code, ServerRequest req, ServerResponse res) {
WebClient webClient = oidcConfig.appWebClient();
FormParams.Builder form = FormParams.builder().add("grant_type", "authorization_code").add("code", code).add("redirect_uri", redirectUri(req));
WebClientRequestBuilder post = webClient.post().uri(oidcConfig.tokenEndpointUri()).accept(io.helidon.common.http.MediaType.APPLICATION_JSON);
oidcConfig.updateRequest(OidcConfig.RequestType.CODE_TO_TOKEN, post, form);
OidcConfig.postJsonResponse(post, form.build(), json -> processJsonResponse(req, res, json), (status, errorEntity) -> processError(res, status, errorEntity), (t, message) -> processError(res, t, message)).ignoreElement();
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class IdcsRoleMapperRxProvider method getGrantsFromServer.
/**
* Retrieves grants from IDCS server.
*
* @param subject to get grants for
* @return optional list of grants to be added
*/
protected Single<List<? extends Grant>> getGrantsFromServer(Subject subject) {
String subjectName = subject.principal().getName();
String subjectType = (String) subject.principal().abacAttribute("sub_type").orElse(defaultIdcsSubjectType());
RoleMapTracing tracing = SecurityTracing.get().roleMapTracing("idcs");
return Single.create(appToken.getToken(tracing)).flatMapSingle(maybeAppToken -> {
if (maybeAppToken.isEmpty()) {
return Single.error(new SecurityException("Application token not available"));
}
String appToken = maybeAppToken.get();
JsonObjectBuilder requestBuilder = JSON.createObjectBuilder().add("mappingAttributeValue", subjectName).add("subjectType", subjectType).add("includeMemberships", true);
JsonArrayBuilder arrayBuilder = JSON.createArrayBuilder();
arrayBuilder.add("urn:ietf:params:scim:schemas:oracle:idcs:Asserter");
requestBuilder.add("schemas", arrayBuilder);
// use current span context as a parent for client outbound
// using a custom child context, so we do not replace the parent in the current context
Context parentContext = Contexts.context().orElseGet(Contexts::globalContext);
Context childContext = Context.builder().parent(parentContext).build();
tracing.findParent().ifPresent(childContext::register);
WebClientRequestBuilder request = oidcConfig().generalWebClient().post().uri(asserterUri).context(childContext).headers(it -> {
it.add(Http.Header.AUTHORIZATION, "Bearer " + appToken);
return it;
});
return processRoleRequest(request, requestBuilder.build(), subjectName);
}).peek(ignored -> tracing.finish()).onError(tracing::error);
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class TestHandlerRegistration method test4PreFlightAllowedHeaders2.
@Test
void test4PreFlightAllowedHeaders2() throws ExecutionException, InterruptedException {
WebClientRequestBuilder reqBuilder = client.options().path(CORS4_CONTEXT_ROOT);
Headers headers = reqBuilder.headers();
headers.add(ORIGIN, "http://foo.bar");
headers.add(ACCESS_CONTROL_REQUEST_METHOD, "PUT");
headers.add(ACCESS_CONTROL_REQUEST_HEADERS, "X-foo, X-bar");
WebClientResponse res = reqBuilder.request().toCompletableFuture().get();
assertThat(res.status(), is(Http.Status.OK_200));
assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_ORIGIN), present(is("http://foo.bar")));
assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_METHODS), present(is("PUT")));
assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_HEADERS), present(containsString("X-foo")));
assertThat(res.headers().first(ACCESS_CONTROL_ALLOW_HEADERS), present(containsString("X-bar")));
}
Aggregations