Search in sources :

Example 1 with ClientRequestContext

use of com.linecorp.armeria.client.ClientRequestContext in project curiostack by curioswitch.

the class GoogleCredentialsDecoratingClient method execute.

@Override
@SuppressWarnings("FutureReturnValueIgnored")
public HttpResponse execute(ClientRequestContext ctx, HttpRequest req) {
    CompletableFuture<HttpResponse> resFuture = new CompletableFuture<>();
    credentials.getRequestMetadata(URI.create(req.path()), authExecutor, new RequestMetadataCallback() {

        @Override
        public void onSuccess(Map<String, List<String>> metadata) {
            metadata.forEach((key, values) -> {
                for (String value : values) {
                    req.headers().add(HttpHeaderNames.of(key), value);
                }
            });
            try {
                ctx.contextAwareEventLoop().submit(() -> resFuture.complete(delegate().execute(ctx, req)));
            } catch (Exception e) {
                resFuture.completeExceptionally(e);
            }
        }

        @Override
        public void onFailure(Throwable t) {
            resFuture.completeExceptionally(t);
        }
    });
    return HttpResponse.from(resFuture);
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) HttpResponse(com.linecorp.armeria.common.HttpResponse) Executor(java.util.concurrent.Executor) Credentials(com.google.auth.Credentials) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ClientRequestContext(com.linecorp.armeria.client.ClientRequestContext) HttpHeaderNames(com.linecorp.armeria.common.HttpHeaderNames) Executors(java.util.concurrent.Executors) RequestMetadataCallback(com.google.auth.RequestMetadataCallback) Inject(javax.inject.Inject) HttpRequest(com.linecorp.armeria.common.HttpRequest) List(java.util.List) Map(java.util.Map) Client(com.linecorp.armeria.client.Client) SimpleDecoratingClient(com.linecorp.armeria.client.SimpleDecoratingClient) URI(java.net.URI) CompletableFuture(java.util.concurrent.CompletableFuture) HttpResponse(com.linecorp.armeria.common.HttpResponse) List(java.util.List) RequestMetadataCallback(com.google.auth.RequestMetadataCallback)

Aggregations

Credentials (com.google.auth.Credentials)1 RequestMetadataCallback (com.google.auth.RequestMetadataCallback)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Client (com.linecorp.armeria.client.Client)1 ClientRequestContext (com.linecorp.armeria.client.ClientRequestContext)1 SimpleDecoratingClient (com.linecorp.armeria.client.SimpleDecoratingClient)1 HttpHeaderNames (com.linecorp.armeria.common.HttpHeaderNames)1 HttpRequest (com.linecorp.armeria.common.HttpRequest)1 HttpResponse (com.linecorp.armeria.common.HttpResponse)1 URI (java.net.URI)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Executor (java.util.concurrent.Executor)1 Executors (java.util.concurrent.Executors)1 Function (java.util.function.Function)1 Inject (javax.inject.Inject)1