use of com.linecorp.armeria.client.WebClient in project curiostack by curioswitch.
the class ComputeEngineAccessTokenProvider method fetchToken.
@Override
protected CompletableFuture<AggregatedHttpResponse> fetchToken(Type type) {
URI uri = URI.create(ComputeEngineCredentials.getTokenServerEncodedUrl());
// In practice, this URL shouldn't change at runtime but it's not infeasible, and since this
// shouldn't be executed often, just create a client every time.
WebClient client = WebClient.builder("h1c://" + uri.getAuthority() + "/").decorator(LoggingClient.builder().newDecorator()).build();
return client.execute(RequestHeaders.of(HttpMethod.GET, uri.getPath(), METADATA_FLAVOR_HEADER, "Google")).aggregate();
}
use of com.linecorp.armeria.client.WebClient in project scribejava by scribejava.
the class ArmeriaHttpClient method doExecuteAsync.
private <T> CompletableFuture<T> doExecuteAsync(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, Supplier<HttpData> contentSupplier, OAuthAsyncRequestCallback<T> callback, OAuthRequest.ResponseConverter<T> converter) {
// Get the URI and Path
final URI uri = URI.create(completeUrl);
final String path = getServicePath(uri);
// Fetch/Create WebClient instance for a given Endpoint
final WebClient client = getClient(uri);
// Build HTTP request
final RequestHeadersBuilder headersBuilder = RequestHeaders.of(getHttpMethod(httpVerb), path).toBuilder();
headersBuilder.add(headers.entrySet());
if (userAgent != null) {
headersBuilder.add(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent);
}
// Build the request body and execute HTTP request
final HttpResponse response;
if (httpVerb.isPermitBody()) {
// POST, PUT, PATCH and DELETE methods
final HttpData contents = contentSupplier.get();
if (httpVerb.isRequiresBody() && contents == null) {
// POST or PUT methods
throw new IllegalArgumentException("Contents missing for request method " + httpVerb.name());
}
if (headersBuilder.contentType() == null) {
headersBuilder.contentType(MediaType.FORM_DATA);
}
if (contents != null) {
response = client.execute(headersBuilder.build(), contents);
} else {
response = client.execute(headersBuilder.build());
}
} else {
response = client.execute(headersBuilder.build());
}
// Aggregate HTTP response (asynchronously) and return the result Future
return response.aggregate().thenApply(aggregatedResponse -> whenResponseComplete(callback, converter, aggregatedResponse)).exceptionally(throwable -> completeExceptionally(callback, throwable));
}
use of com.linecorp.armeria.client.WebClient in project curiostack by curioswitch.
the class RoutingService method serve.
@Override
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) {
RoutingContext mappingContext = ctx.routingContext();
final WebClient client;
if (pathClients != null && mappingContext.query() == null) {
client = pathClients.get(mappingContext);
} else {
client = find(mappingContext);
}
if (client == null) {
return HttpResponse.of(HttpStatus.NOT_FOUND);
}
// We don't want to pass the external domain name through to the backend server since this
// causes problems with the TLS handshake between this server and the backend (the external
// hostname does not match the names we use in our certs for server to server communication).
req = req.withHeaders(req.headers().toBuilder().authority("").build());
return client.execute(req);
}
use of com.linecorp.armeria.client.WebClient in project curiostack by curioswitch.
the class RoutingConfigLoader method load.
Map<Route, WebClient> load(Path configPath) {
final RoutingConfig config;
try {
config = OBJECT_MAPPER.readValue(configPath.toFile(), RoutingConfig.class);
} catch (IOException e) {
throw new UncheckedIOException("Could not read routing config.", e);
}
Map<String, WebClient> clients = config.getTargets().stream().collect(toImmutableMap(Target::getName, t -> clientBuilderFactory.create(t.getName(), addSerializationFormat(t.getUrl())).build(WebClient.class)));
return config.getRules().stream().collect(toImmutableMap(r -> Route.builder().path(r.getPathPattern()).build(), r -> clients.get(r.getTarget())));
}
use of com.linecorp.armeria.client.WebClient in project zipkin by openzipkin.
the class ZipkinElasticsearchStorageConfigurationTest method providesBasicAuthInterceptor_whenDynamicCredentialsConfigured.
@Test
public void providesBasicAuthInterceptor_whenDynamicCredentialsConfigured() {
String credentialsFile = pathOfResource("es-credentials");
TestPropertyValues.of("zipkin.storage.type:elasticsearch", "zipkin.storage.elasticsearch.hosts:127.0.0.1:1234", "zipkin.storage.elasticsearch.credentials-file:" + credentialsFile, "zipkin.storage.elasticsearch.credentials-refresh-interval:2").applyTo(context);
Access.registerElasticsearch(context);
context.refresh();
HttpClientFactory factory = context.getBean(HttpClientFactory.class);
WebClient client = WebClient.builder("http://127.0.0.1:1234").option(ClientOptions.DECORATION, factory.options.decoration()).build();
assertThat(client.as(BasicAuthInterceptor.class)).isNotNull();
BasicCredentials basicCredentials = Objects.requireNonNull(client.as(BasicAuthInterceptor.class)).basicCredentials;
String credentials = basicCredentials.getCredentials();
assertThat(credentials).isEqualTo("Basic Zm9vOmJhcg==");
}
Aggregations