Search in sources :

Example 1 with RequestHeadersBuilder

use of com.linecorp.armeria.common.RequestHeadersBuilder in project curiostack by curioswitch.

the class ArmeriaSdkHttpClient method execute.

@Override
public CompletableFuture<Void> execute(AsyncExecuteRequest executeRequest) {
    SdkHttpRequest httpRequest = executeRequest.request();
    SdkAsyncHttpResponseHandler handler = executeRequest.responseHandler();
    RequestHeadersBuilder headersBuilder = RequestHeaders.builder(convert(httpRequest.method()), httpRequest.getUri().toString());
    executeRequest.requestContentPublisher().contentLength().ifPresent(contentLength -> headersBuilder.add(HttpHeaderNames.CONTENT_LENGTH, contentLength.toString()));
    for (Map.Entry<String, List<String>> header : httpRequest.headers().entrySet()) {
        headersBuilder.add(header.getKey(), header.getValue());
    }
    Publisher<HttpData> requestStream = delegate -> executeRequest.requestContentPublisher().subscribe(new SdkToHttpDataSubscriber(delegate));
    HttpRequest request = HttpRequest.of(headersBuilder.build(), requestStream);
    HttpResponse response = client.execute(request);
    response.subscribe(new ResponseSubscriber(handler));
    CompletableFuture<Void> completionFuture = response.whenComplete();
    completionFuture.whenComplete((unused, t) -> {
        if (t != null) {
            // Subscriber.onError, SdkAsyncHttpResponseHandler.onError, the returned future, and any
            // thrown exception are all ways of communicating errors to the SDK. This seems like two
            // too many but cover all the bases just in case.
            handler.onError(t);
        }
    });
    return completionFuture;
}
Also used : RequestHeaders(com.linecorp.armeria.common.RequestHeaders) DelegatingSubscriber(software.amazon.awssdk.utils.async.DelegatingSubscriber) CompletableFuture(java.util.concurrent.CompletableFuture) AttributeMap(software.amazon.awssdk.utils.AttributeMap) HttpHeaderNames(com.linecorp.armeria.common.HttpHeaderNames) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) RequestHeadersBuilder(com.linecorp.armeria.common.RequestHeadersBuilder) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) HttpObject(com.linecorp.armeria.common.HttpObject) WebClient(com.linecorp.armeria.client.WebClient) Map(java.util.Map) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) Subscriber(org.reactivestreams.Subscriber) Nullable(javax.annotation.Nullable) HttpData(com.linecorp.armeria.common.HttpData) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) HttpResponse(com.linecorp.armeria.common.HttpResponse) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) Publisher(org.reactivestreams.Publisher) ClientOptions(com.linecorp.armeria.client.ClientOptions) HttpMethod(com.linecorp.armeria.common.HttpMethod) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) HttpRequest(com.linecorp.armeria.common.HttpRequest) List(java.util.List) HttpHeaders(com.linecorp.armeria.common.HttpHeaders) ResponseHeaders(com.linecorp.armeria.common.ResponseHeaders) Subscription(org.reactivestreams.Subscription) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) HttpRequest(com.linecorp.armeria.common.HttpRequest) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) HttpResponse(com.linecorp.armeria.common.HttpResponse) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) HttpData(com.linecorp.armeria.common.HttpData) List(java.util.List) RequestHeadersBuilder(com.linecorp.armeria.common.RequestHeadersBuilder) AttributeMap(software.amazon.awssdk.utils.AttributeMap) Map(java.util.Map)

Aggregations

ClientOptions (com.linecorp.armeria.client.ClientOptions)1 WebClient (com.linecorp.armeria.client.WebClient)1 HttpData (com.linecorp.armeria.common.HttpData)1 HttpHeaderNames (com.linecorp.armeria.common.HttpHeaderNames)1 HttpHeaders (com.linecorp.armeria.common.HttpHeaders)1 HttpMethod (com.linecorp.armeria.common.HttpMethod)1 HttpObject (com.linecorp.armeria.common.HttpObject)1 HttpRequest (com.linecorp.armeria.common.HttpRequest)1 HttpResponse (com.linecorp.armeria.common.HttpResponse)1 RequestHeaders (com.linecorp.armeria.common.RequestHeaders)1 RequestHeadersBuilder (com.linecorp.armeria.common.RequestHeadersBuilder)1 ResponseHeaders (com.linecorp.armeria.common.ResponseHeaders)1 Unpooled (io.netty.buffer.Unpooled)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Nullable (javax.annotation.Nullable)1 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)1 Publisher (org.reactivestreams.Publisher)1