Search in sources :

Example 1 with SdkHttpRequest

use of software.amazon.awssdk.http.SdkHttpRequest in project aws-xray-sdk-java by aws.

the class TracingInterceptor method modifyHttpRequest.

@Override
public SdkHttpRequest modifyHttpRequest(Context.ModifyHttpRequest context, ExecutionAttributes executionAttributes) {
    SdkHttpRequest httpRequest = context.httpRequest();
    Subsegment subsegment = executionAttributes.getAttribute(entityKey);
    if (!subsegment.shouldPropagate()) {
        return httpRequest;
    }
    boolean isSampled = subsegment.getParentSegment().isSampled();
    TraceHeader header = new TraceHeader(subsegment.getParentSegment().getTraceId(), isSampled ? subsegment.getId() : null, isSampled ? TraceHeader.SampleDecision.SAMPLED : TraceHeader.SampleDecision.NOT_SAMPLED);
    return httpRequest.toBuilder().appendHeader(TraceHeader.HEADER_KEY, header.toString()).build();
}
Also used : TraceHeader(com.amazonaws.xray.entities.TraceHeader) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) Subsegment(com.amazonaws.xray.entities.Subsegment)

Example 2 with SdkHttpRequest

use of software.amazon.awssdk.http.SdkHttpRequest 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)

Example 3 with SdkHttpRequest

use of software.amazon.awssdk.http.SdkHttpRequest in project aws-xray-sdk-java by aws.

the class TracingInterceptorTest method testNoHeaderAddedWhenPropagationOff.

@Test
public void testNoHeaderAddedWhenPropagationOff() {
    Subsegment subsegment = Subsegment.noOp(AWSXRay.getGlobalRecorder(), false);
    TracingInterceptor interceptor = new TracingInterceptor();
    Context.ModifyHttpRequest context = Mockito.mock(Context.ModifyHttpRequest.class);
    SdkHttpRequest mockRequest = Mockito.mock(SdkHttpRequest.class);
    SdkHttpRequest.Builder mockRequestBuilder = Mockito.mock(SdkHttpRequest.Builder.class);
    when(context.httpRequest()).thenReturn(mockRequest);
    Mockito.lenient().when(context.httpRequest().toBuilder()).thenReturn(mockRequestBuilder);
    ExecutionAttributes attributes = new ExecutionAttributes();
    attributes.putAttribute(TracingInterceptor.entityKey, subsegment);
    interceptor.modifyHttpRequest(context, attributes);
    verify(mockRequest.toBuilder(), never()).appendHeader(anyString(), anyString());
}
Also used : Context(software.amazon.awssdk.core.interceptor.Context) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) Subsegment(com.amazonaws.xray.entities.Subsegment) Test(org.junit.Test)

Aggregations

SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)3 Subsegment (com.amazonaws.xray.entities.Subsegment)2 TraceHeader (com.amazonaws.xray.entities.TraceHeader)1 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