use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ProfileDisableMultiRegionProviderTest method specifiedInOverrideConfig_shouldUse.
@Test
public void specifiedInOverrideConfig_shouldUse() {
ExecutionInterceptor interceptor = Mockito.spy(AbstractExecutionInterceptor.class);
String profileFileContent = "[default]\n" + "s3_disable_multiregion_access_points = true\n";
ProfileFile profileFile = ProfileFile.builder().type(ProfileFile.Type.CONFIGURATION).content(new StringInputStream(profileFileContent)).build();
S3Client s3 = S3Client.builder().region(Region.US_WEST_2).credentialsProvider(AnonymousCredentialsProvider.create()).overrideConfiguration(c -> c.defaultProfileFile(profileFile).defaultProfileName("default").addExecutionInterceptor(interceptor).retryPolicy(r -> r.numRetries(0))).serviceConfiguration(s -> s.useArnRegionEnabled(true)).build();
String arn = "arn:aws:s3:us-banana-46:12345567890:accesspoint:foo";
assertThatThrownBy(() -> s3.getObject(r -> r.bucket(arn).key("bar"))).isInstanceOf(SdkException.class);
ArgumentCaptor<Context.BeforeTransmission> context = ArgumentCaptor.forClass(Context.BeforeTransmission.class);
Mockito.verify(interceptor).beforeTransmission(context.capture(), any());
String host = context.getValue().httpRequest().host();
assertThat(host).contains("us-banana-46");
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class DefaultJsonBaseClientBuilder method finalizeServiceConfiguration.
@Override
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();
List<ExecutionInterceptor> interceptors = interceptorFactory.getInterceptors("software/amazon/awssdk/services/json/execution.interceptors");
interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS));
return config.toBuilder().option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors).build();
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionInterceptorTest method async_success_allInterceptorMethodsCalled.
@Test
public void async_success_allInterceptorMethodsCalled() throws Exception {
// Given
ExecutionInterceptor interceptor = mock(MessageUpdatingInterceptor.class, CALLS_REAL_METHODS);
ProtocolRestJsonAsyncClient client = asyncClient(interceptor);
MembersInHeadersRequest request = MembersInHeadersRequest.builder().build();
stubFor(post(urlPathEqualTo(MEMBERS_IN_HEADERS_PATH)).willReturn(aResponse().withStatus(200).withBody("")));
// When
MembersInHeadersResponse result = client.membersInHeaders(request).get(10, TimeUnit.SECONDS);
// Expect
expectAllMethodsCalled(interceptor, request, null, true);
validateRequestResponse(result);
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionInterceptorTest method async_streamingInput_success_allInterceptorMethodsCalled.
@Test
public void async_streamingInput_success_allInterceptorMethodsCalled() throws Exception {
// Given
ExecutionInterceptor interceptor = mock(NoOpInterceptor.class, CALLS_REAL_METHODS);
ProtocolRestJsonAsyncClient client = asyncClient(interceptor);
StreamingInputOperationRequest request = StreamingInputOperationRequest.builder().build();
stubFor(post(urlPathEqualTo(STREAMING_INPUT_PATH)).willReturn(aResponse().withStatus(200).withBody("")));
// When
client.streamingInputOperation(request, new NoOpAsyncRequestBody()).get(10, TimeUnit.SECONDS);
// Expect
Context.BeforeTransmission beforeTransmissionArg = captureBeforeTransmissionArg(interceptor, true);
// TODO: The content should actually be empty to match responses. We can fix this by updating the StructuredJsonGenerator
// to use null for NO-OP marshalling of payloads. This will break streaming POST operations for JSON because of a hack in
// the MoveParametersToBodyStage, but we can move the logic from there into the query marshallers (why the hack exists)
// and then everything should be good for JSON.
assertThat(beforeTransmissionArg.requestBody().get().contentStreamProvider().newStream().read()).isEqualTo(-1);
assertThat(beforeTransmissionArg.httpRequest().firstMatchingHeader(Header.CONTENT_LENGTH).get()).contains(Long.toString(0L));
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionInterceptorTest method sync_interceptorException_failureInterceptorMethodsCalled.
@Test
public void sync_interceptorException_failureInterceptorMethodsCalled() {
// Given
ExecutionInterceptor interceptor = mock(MessageUpdatingInterceptor.class, CALLS_REAL_METHODS);
RuntimeException exception = new RuntimeException("Uh oh!");
doThrow(exception).when(interceptor).afterExecution(any(), any());
ProtocolRestJsonClient client = client(interceptor);
MembersInHeadersRequest request = MembersInHeadersRequest.builder().build();
stubFor(post(urlPathEqualTo(MEMBERS_IN_HEADERS_PATH)).willReturn(aResponse().withStatus(200).withBody("")));
// When
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> client.membersInHeaders(request));
// Expect
expectAllMethodsCalled(interceptor, request, exception, false);
}
Aggregations