use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class HelidonConnector method applyInternal.
private CompletionStage<ClientResponse> applyInternal(ClientRequest request) {
final WebClientRequestBuilder webClientRequestBuilder = webClient.method(request.getMethod());
webClientRequestBuilder.uri(request.getUri());
webClientRequestBuilder.headers(HelidonStructures.createHeaders(request.getRequestHeaders()));
for (String propertyName : request.getConfiguration().getPropertyNames()) {
Object property = request.getConfiguration().getProperty(propertyName);
if (!propertyName.startsWith("jersey") && String.class.isInstance(property)) {
webClientRequestBuilder.property(propertyName, (String) property);
}
}
for (String propertyName : request.getPropertyNames()) {
Object property = request.resolveProperty(propertyName, Object.class);
if (!propertyName.startsWith("jersey") && String.class.isInstance(property)) {
webClientRequestBuilder.property(propertyName, (String) property);
}
}
// TODO
// HelidonStructures.createProxy(request).ifPresent(webClientRequestBuilder::proxy);
webClientRequestBuilder.followRedirects(request.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true));
webClientRequestBuilder.readTimeout(request.resolveProperty(ClientProperties.READ_TIMEOUT, 10000), TimeUnit.MILLISECONDS);
CompletionStage<WebClientResponse> responseStage = null;
if (request.hasEntity()) {
responseStage = HelidonEntity.submit(entityType, request, webClientRequestBuilder, executorServiceKeeper.getExecutorService(request));
} else {
responseStage = webClientRequestBuilder.submit();
}
return responseStage.thenCompose((a) -> convertResponse(request, a));
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class IdcsMtRoleMapperRxProvider method getGrantsFromServer.
/**
* Get grants from IDCS server. The result is cached.
*
* @param idcsTenantId ID of the IDCS tenant
* @param idcsAppName Name of IDCS application
* @param subject subject to get grants for
* @return optional list of grants from server
*/
protected Single<List<? extends Grant>> getGrantsFromServer(String idcsTenantId, String idcsAppName, 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(getAppToken(idcsTenantId, tracing)).flatMapSingle(maybeAppToken -> {
if (maybeAppToken.isEmpty()) {
return Single.error(new SecurityException("Application token not available"));
}
return Single.just(maybeAppToken.get());
}).flatMapSingle(appToken -> {
JsonObjectBuilder requestBuilder = JSON.createObjectBuilder().add("mappingAttributeValue", subjectName).add("subjectType", subjectType).add("appName", idcsAppName).add("includeMemberships", true);
JsonArrayBuilder arrayBuilder = JSON.createArrayBuilder();
arrayBuilder.add("urn:ietf:params:scim:schemas:oracle:idcs:Asserter");
requestBuilder.add("schemas", arrayBuilder);
Context parentContext = Contexts.context().orElseGet(Contexts::globalContext);
Context childContext = Context.builder().parent(parentContext).build();
tracing.findParent().ifPresent(childContext::register);
WebClientRequestBuilder post = oidcConfig().generalWebClient().post().context(childContext).uri(multitenantEndpoints.assertEndpoint(idcsTenantId)).headers(it -> {
it.add(Http.Header.AUTHORIZATION, "Bearer " + appToken);
return it;
});
return processRoleRequest(post, requestBuilder.build(), subjectName);
});
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class TestClient method callServiceAndGetString.
/**
* Call remote service method and return its raw data as JSON object.
* No response content check is done. No query parameters are passed.
*
* @param service remote service name
* @param method remote test method name
* @return data returned by remote service
*/
public String callServiceAndGetString(final String service, final String method) {
WebClientRequestBuilder rb = clientGetBuilderWithPath(service, method);
final MessageBodyReadableContent content = rb.submit().await(1, TimeUnit.MINUTES).content();
return content.as(String.class).await(1, TimeUnit.MINUTES);
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class RequestTest method reuseRequestBuilder.
@Test
public void reuseRequestBuilder() {
WebClientRequestBuilder requestBuilder = webClient.get();
JsonObject response = requestBuilder.request(JsonObject.class).await();
assertThat(response, notNullValue());
assertThat(response.getString("message"), is("Hello World!"));
response = requestBuilder.request(JsonObject.class).await();
assertThat(response, notNullValue());
assertThat(response.getString("message"), is("Hello World!"));
}
use of io.helidon.webclient.WebClientRequestBuilder in project helidon by oracle.
the class TestDefaultCorsSupport method testOptionsWithCors.
@Test
void testOptionsWithCors() throws ExecutionException, InterruptedException {
WebServer server = null;
WebClient client;
try {
server = WebServer.create(prepRouting(true)).start().toCompletableFuture().get();
client = WebClient.builder().baseUri("http://localhost:" + server.port()).get();
WebClientRequestBuilder reqBuilder = client.options().path("/greet");
Headers h = reqBuilder.headers();
h.add("Origin", "http://foo.com");
h.add("Host", "bar.com");
WebClientResponse response = reqBuilder.submit().toCompletableFuture().get();
WebClientResponseHeaders headers = response.headers();
List<String> allowOrigins = headers.values(CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN);
assertThat(allowOrigins, contains("*"));
} finally {
if (server != null) {
server.shutdown();
}
}
}
Aggregations