use of software.amazon.awssdk.core.http.ExecutionContext in project aws-sdk-java-v2 by aws.
the class AsyncHttpClientApiCallTimeoutTests method errorResponse_SlowErrorResponseHandler_ThrowsApiCallTimeoutException.
@Test
public void errorResponse_SlowErrorResponseHandler_ThrowsApiCallTimeoutException() {
stubFor(get(anyUrl()).willReturn(aResponse().withStatus(500).withBody("{}")));
ExecutionContext executionContext = ClientExecutionAndRequestTimerTestUtils.executionContext(null);
CompletableFuture future = httpClient.requestExecutionBuilder().originalRequest(NoopTestRequest.builder().build()).executionContext(executionContext).request(generateRequest()).execute(combinedAsyncResponseHandler(noOpResponseHandler(), superSlowResponseHandler(API_CALL_TIMEOUT.toMillis())));
assertThatThrownBy(future::join).hasCauseInstanceOf(ApiCallTimeoutException.class);
}
use of software.amazon.awssdk.core.http.ExecutionContext in project aws-sdk-java-v2 by aws.
the class HttpClientApiCallAttemptTimeoutTest method errorResponse_SlowErrorResponseHandler_ThrowsApiCallTimeoutException.
@Test
public void errorResponse_SlowErrorResponseHandler_ThrowsApiCallTimeoutException() {
stubFor(get(anyUrl()).willReturn(aResponse().withStatus(500).withBody("{}")));
ExecutionContext executionContext = ClientExecutionAndRequestTimerTestUtils.executionContext(null);
assertThatThrownBy(() -> httpClient.requestExecutionBuilder().originalRequest(NoopTestRequest.builder().build()).executionContext(executionContext).request(generateRequest()).execute(combinedSyncResponseHandler(null, superSlowResponseHandler(API_CALL_TIMEOUT.toMillis())))).isInstanceOf(ApiCallAttemptTimeoutException.class);
}
use of software.amazon.awssdk.core.http.ExecutionContext in project aws-sdk-java-v2 by aws.
the class DefaultS3Presigner method initializePresignedRequest.
/**
* Initialize the provided presigned request.
*/
private void initializePresignedRequest(PresignedRequest.Builder presignedRequest, ExecutionContext execCtx, SdkHttpFullRequest signedHttpRequest) {
SdkBytes signedPayload = signedHttpRequest.contentStreamProvider().map(p -> SdkBytes.fromInputStream(p.newStream())).orElse(null);
List<String> signedHeadersQueryParam = signedHttpRequest.rawQueryParameters().get("X-Amz-SignedHeaders");
Validate.validState(signedHeadersQueryParam != null, "Only SigV4 presigners are supported at this time, but the configured " + "presigner (%s) did not seem to generate a SigV4 signature.", execCtx.signer());
Map<String, List<String>> signedHeaders = signedHeadersQueryParam.stream().flatMap(h -> Stream.of(h.split(";"))).collect(toMap(h -> h, h -> signedHttpRequest.firstMatchingHeader(h).map(Collections::singletonList).orElseGet(ArrayList::new)));
boolean isBrowserExecutable = signedHttpRequest.method() == SdkHttpMethod.GET && signedPayload == null && (signedHeaders.isEmpty() || (signedHeaders.size() == 1 && signedHeaders.containsKey("host")));
presignedRequest.expiration(execCtx.executionAttributes().getAttribute(PRESIGNER_EXPIRATION)).isBrowserExecutable(isBrowserExecutable).httpRequest(signedHttpRequest).signedHeaders(signedHeaders).signedPayload(signedPayload);
}
use of software.amazon.awssdk.core.http.ExecutionContext in project aws-sdk-java-v2 by aws.
the class DefaultS3Presigner method addRequestLevelHeadersAndQueryParameters.
/**
* Update the provided HTTP request by adding any HTTP headers or query parameters specified as part of the
* {@link SdkRequest}.
*/
private void addRequestLevelHeadersAndQueryParameters(ExecutionContext execCtx) {
SdkHttpRequest httpRequest = execCtx.interceptorContext().httpRequest();
SdkRequest sdkRequest = execCtx.interceptorContext().request();
SdkHttpRequest updatedHttpRequest = httpRequest.toBuilder().applyMutation(b -> addRequestLevelHeaders(b, sdkRequest)).applyMutation(b -> addRequestLeveQueryParameters(b, sdkRequest)).build();
execCtx.interceptorContext(execCtx.interceptorContext().copy(c -> c.httpRequest(updatedHttpRequest)));
}
use of software.amazon.awssdk.core.http.ExecutionContext in project aws-sdk-java-v2 by aws.
the class AwsExecutionContextBuilderTest method verifyCoreExecutionAttributesTakePrecedence.
@Test
public void verifyCoreExecutionAttributesTakePrecedence() {
ExecutionAttributes requestOverrides = ExecutionAttributes.builder().put(SdkExecutionAttribute.SERVICE_NAME, "RequestOverrideServiceName").build();
Optional requestOverrideConfiguration = Optional.of(AwsRequestOverrideConfiguration.builder().executionAttributes(requestOverrides).build());
when(sdkRequest.overrideConfiguration()).thenReturn(requestOverrideConfiguration);
ExecutionAttributes clientConfigOverrides = ExecutionAttributes.builder().put(SdkExecutionAttribute.SERVICE_NAME, "ClientConfigServiceName").build();
SdkClientConfiguration testClientConfiguration = testClientConfiguration().option(SdkClientOption.SERVICE_NAME, "DoNotOverrideService").option(SdkClientOption.EXECUTION_ATTRIBUTES, clientConfigOverrides).build();
ExecutionContext executionContext = AwsExecutionContextBuilder.invokeInterceptorsAndCreateExecutionContext(clientExecutionParams(), testClientConfiguration);
assertThat(executionContext.executionAttributes().getAttribute(SdkExecutionAttribute.SERVICE_NAME)).isEqualTo("DoNotOverrideService");
}
Aggregations