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();
}
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;
}
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());
}
Aggregations