use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionAttributesTest method syncClient_requestOverrideExecutionAttribute.
@Test
public void syncClient_requestOverrideExecutionAttribute() {
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());
ExecutionAttribute testAttribute = attr("TestAttribute");
String testValue = "TestValue";
ProtocolRestJsonClient sync = ProtocolRestJsonClient.builder().credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("foo", "bar"))).region(Region.US_WEST_2).overrideConfiguration(c -> c.addExecutionInterceptor(interceptor)).build();
AllTypesRequest request = AllTypesRequest.builder().overrideConfiguration(c -> c.putExecutionAttribute(testAttribute, testValue)).build();
thrown.expect(RuntimeException.class);
try {
sync.allTypes(request);
} finally {
ExecutionAttributes attributes = attributesCaptor.getValue();
assertThat(attributes.getAttribute(testAttribute)).isEqualTo(testValue);
sync.close();
}
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class DefaultQueryBaseClientBuilder method finalizeServiceConfiguration.
@Override
protected final SdkClientConfiguration finalizeServiceConfiguration(SdkClientConfiguration config) {
ClasspathInterceptorChainFactory interceptorFactory = new ClasspathInterceptorChainFactory();
List<ExecutionInterceptor> interceptors = interceptorFactory.getInterceptors("software/amazon/awssdk/services/query/execution.interceptors");
interceptors = CollectionUtils.mergeLists(interceptors, config.option(SdkClientOption.EXECUTION_INTERCEPTORS));
List<ExecutionInterceptor> protocolInterceptors = Collections.singletonList(new QueryParametersToBodyInterceptor());
interceptors = CollectionUtils.mergeLists(interceptors, protocolInterceptors);
return config.toBuilder().option(SdkClientOption.EXECUTION_INTERCEPTORS, interceptors).build();
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project hedera-mirror-node by hashgraph.
the class CloudStorageConfiguration method gcpCloudStorageClient.
@Bean
@ConditionalOnProperty(prefix = "hedera.mirror.importer.downloader", name = "cloudProvider", havingValue = "GCP")
S3AsyncClient gcpCloudStorageClient() {
log.info("Configured to download from GCP with bucket name '{}'", downloaderProperties.getBucketName());
// Any valid region for aws client. Ignored by GCP.
S3AsyncClientBuilder clientBuilder = asyncClientBuilder("us-east-1").endpointOverride(URI.create(downloaderProperties.getCloudProvider().getEndpoint()));
String projectId = downloaderProperties.getGcpProjectId();
if (StringUtils.isNotBlank(projectId)) {
clientBuilder.overrideConfiguration(builder -> builder.addExecutionInterceptor(new ExecutionInterceptor() {
@Override
public SdkHttpRequest modifyHttpRequest(Context.ModifyHttpRequest context, ExecutionAttributes executionAttributes) {
return context.httpRequest().toBuilder().appendRawQueryParameter("userProject", projectId).build();
}
}));
}
return clientBuilder.build();
}
Aggregations