Search in sources :

Example 31 with ExecutionInterceptor

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();
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) SdkAdvancedClientOption(software.amazon.awssdk.core.client.config.SdkAdvancedClientOption) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) ConcurrentMap(java.util.concurrent.ConcurrentMap) Context(software.amazon.awssdk.core.interceptor.Context) Mockito.doThrow(org.mockito.Mockito.doThrow) Rule(org.junit.Rule) ArgumentCaptor(org.mockito.ArgumentCaptor) ExecutionAttribute(software.amazon.awssdk.core.interceptor.ExecutionAttribute) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) ExpectedException(org.junit.rules.ExpectedException) ProtocolRestJsonAsyncClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient) Mockito.mock(org.mockito.Mockito.mock) AllTypesRequest(software.amazon.awssdk.services.protocolrestjson.model.AllTypesRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) ExecutionAttribute(software.amazon.awssdk.core.interceptor.ExecutionAttribute) AllTypesRequest(software.amazon.awssdk.services.protocolrestjson.model.AllTypesRequest) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) ProtocolRestJsonClient(software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient) Test(org.junit.Test)

Example 32 with ExecutionInterceptor

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();
}
Also used : QueryParametersToBodyInterceptor(software.amazon.awssdk.protocols.query.interceptor.QueryParametersToBodyInterceptor) ClasspathInterceptorChainFactory(software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor)

Example 33 with ExecutionInterceptor

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();
}
Also used : ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Aggregations

ExecutionInterceptor (software.amazon.awssdk.core.interceptor.ExecutionInterceptor)33 Test (org.junit.Test)25 Context (software.amazon.awssdk.core.interceptor.Context)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)12 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)12 ProtocolRestJsonAsyncClient (software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient)12 ProtocolRestJsonClient (software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient)12 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)11 ArgumentCaptor (org.mockito.ArgumentCaptor)10 Region (software.amazon.awssdk.regions.Region)10 Mockito.mock (org.mockito.Mockito.mock)9 SdkAdvancedClientOption (software.amazon.awssdk.core.client.config.SdkAdvancedClientOption)9 ExecutionAttribute (software.amazon.awssdk.core.interceptor.ExecutionAttribute)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 CompletionException (java.util.concurrent.CompletionException)7 ConcurrentMap (java.util.concurrent.ConcurrentMap)7 Rule (org.junit.Rule)7 ExpectedException (org.junit.rules.ExpectedException)7 Mockito.doThrow (org.mockito.Mockito.doThrow)7 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)7