Search in sources :

Example 6 with HttpRequest

use of com.linecorp.armeria.common.HttpRequest 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

HttpRequest (com.linecorp.armeria.common.HttpRequest)6 HttpResponse (com.linecorp.armeria.common.HttpResponse)5 HttpData (com.linecorp.armeria.common.HttpData)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 WebClient (com.linecorp.armeria.client.WebClient)3 HttpHeaderNames (com.linecorp.armeria.common.HttpHeaderNames)3 RequestHeaders (com.linecorp.armeria.common.RequestHeaders)3 List (java.util.List)3 AggregatedHttpRequest (com.linecorp.armeria.common.AggregatedHttpRequest)2 HttpHeaders (com.linecorp.armeria.common.HttpHeaders)2 HttpStatus (com.linecorp.armeria.common.HttpStatus)2 ResponseHeaders (com.linecorp.armeria.common.ResponseHeaders)2 SafeCloseable (com.linecorp.armeria.common.util.SafeCloseable)2 Unpooled (io.netty.buffer.Unpooled)2 ByteBuffer (java.nio.ByteBuffer)2 Map (java.util.Map)2 Publisher (org.reactivestreams.Publisher)2 Subscriber (org.reactivestreams.Subscriber)2 Subscription (org.reactivestreams.Subscription)2 SdkHttpMethod (software.amazon.awssdk.http.SdkHttpMethod)2