use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class HttpClientApiCallAttemptTimeoutTest method successfulResponse_SlowAfterResponseExecutionInterceptor_ThrowsApiCallTimeoutException.
@Test
public void successfulResponse_SlowAfterResponseExecutionInterceptor_ThrowsApiCallTimeoutException() {
stubFor(get(anyUrl()).willReturn(aResponse().withStatus(200).withBody("{}")));
ExecutionInterceptor interceptor = new SlowExecutionInterceptor().afterTransmissionWaitInSeconds(SLOW_REQUEST_HANDLER_TIMEOUT);
assertThatThrownBy(() -> requestBuilder().executionContext(withInterceptors(interceptor)).execute(noOpSyncResponseHandler())).isInstanceOf(ApiCallAttemptTimeoutException.class);
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class DefaultS3Presigner method initializeInterceptors.
/**
* Copied from {@code DefaultS3BaseClientBuilder} and {@link SdkDefaultClientBuilder}.
*/
private List<ExecutionInterceptor> initializeInterceptors() {
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();
List<ExecutionInterceptor> s3Interceptors = interceptorFactory.getInterceptors("software/amazon/awssdk/services/s3/execution.interceptors");
return mergeLists(interceptorFactory.getGlobalInterceptors(), s3Interceptors);
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class EndpointDiscoveryTest method canBeEnabledViaProfileOnOverrideConfiguration.
@Test(timeout = 10_000)
public void canBeEnabledViaProfileOnOverrideConfiguration() throws InterruptedException {
ExecutionInterceptor interceptor = Mockito.spy(AbstractExecutionInterceptor.class);
String profileFileContent = "[default]\n" + "aws_endpoint_discovery_enabled = true";
ProfileFile profileFile = ProfileFile.builder().type(ProfileFile.Type.CONFIGURATION).content(new StringInputStream(profileFileContent)).build();
DynamoDbClient dynamoDb = DynamoDbClient.builder().region(Region.US_WEST_2).credentialsProvider(AnonymousCredentialsProvider.create()).overrideConfiguration(c -> c.defaultProfileFile(profileFile).defaultProfileName("default").addExecutionInterceptor(interceptor).retryPolicy(r -> r.numRetries(0))).build();
assertThatThrownBy(dynamoDb::listTables).isInstanceOf(SdkException.class);
ArgumentCaptor<Context.BeforeTransmission> context;
do {
Thread.sleep(1);
context = ArgumentCaptor.forClass(Context.BeforeTransmission.class);
Mockito.verify(interceptor, atLeastOnce()).beforeTransmission(context.capture(), any());
} while (context.getAllValues().size() < 2);
assertThat(context.getAllValues().stream().anyMatch(v -> v.httpRequest().firstMatchingHeader("X-Amz-Target").map(h -> h.equals("DynamoDB_20120810.DescribeEndpoints")).orElse(false))).isTrue();
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionAttributesTest method syncClient_disableHostPrefixInjection_isPresent.
@Test
public void syncClient_disableHostPrefixInjection_isPresent() {
ExecutionInterceptor interceptor = mock(ExecutionInterceptor.class);
ArgumentCaptor<ExecutionAttributes> attributesCaptor = ArgumentCaptor.forClass(ExecutionAttributes.class);
doThrow(new RuntimeException("BOOM")).when(interceptor).beforeExecution(any(Context.BeforeExecution.class), attributesCaptor.capture());
ProtocolRestJsonClient sync = ProtocolRestJsonClient.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("foo", "bar"))).region(Region.US_WEST_2).overrideConfiguration(c -> c.addExecutionInterceptor(interceptor).putAdvancedOption(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION, true)).build();
thrown.expect(RuntimeException.class);
try {
sync.allTypes();
} finally {
ExecutionAttributes attributes = attributesCaptor.getValue();
assertThat(attributes.getAttribute(SdkInternalExecutionAttribute.DISABLE_HOST_PREFIX_INJECTION)).isTrue();
sync.close();
}
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionAttributesTest method asyncClient_disableHostPrefixInjection_isPresent.
@Test
public void asyncClient_disableHostPrefixInjection_isPresent() {
ExecutionInterceptor interceptor = mock(ExecutionInterceptor.class);
ArgumentCaptor<ExecutionAttributes> attributesCaptor = ArgumentCaptor.forClass(ExecutionAttributes.class);
doThrow(new RuntimeException("BOOM")).when(interceptor).beforeExecution(any(Context.BeforeExecution.class), attributesCaptor.capture());
ProtocolRestJsonAsyncClient async = ProtocolRestJsonAsyncClient.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("foo", "bar"))).region(Region.US_WEST_2).overrideConfiguration(c -> c.addExecutionInterceptor(interceptor).putAdvancedOption(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION, true)).build();
thrown.expect(CompletionException.class);
try {
async.allTypes().join();
} finally {
ExecutionAttributes attributes = attributesCaptor.getValue();
assertThat(attributes.getAttribute(SdkInternalExecutionAttribute.DISABLE_HOST_PREFIX_INJECTION)).isTrue();
async.close();
}
}
Aggregations