Search in sources :

Example 1 with ExecutionInterceptorChain

use of software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain in project aws-sdk-java-v2 by aws.

the class AsyncHttpClientApiCallTimeoutTests method withInterceptors.

private ExecutionContext withInterceptors(ExecutionInterceptor... requestHandlers) {
    ExecutionInterceptorChain interceptors = new ExecutionInterceptorChain(Arrays.asList(requestHandlers));
    InterceptorContext incerceptorContext = InterceptorContext.builder().request(NoopTestRequest.builder().build()).httpRequest(generateRequest()).build();
    return ExecutionContext.builder().signer(new NoOpSigner()).interceptorChain(interceptors).executionAttributes(new ExecutionAttributes()).interceptorContext(incerceptorContext).metricCollector(MetricCollector.create("ApiCall")).build();
}
Also used : NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) ExecutionInterceptorChain(software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain) InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext)

Example 2 with ExecutionInterceptorChain

use of software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain in project aws-sdk-java-v2 by aws.

the class HttpClientApiCallAttemptTimeoutTest method withInterceptors.

private ExecutionContext withInterceptors(ExecutionInterceptor... requestHandlers) {
    ExecutionInterceptorChain interceptors = new ExecutionInterceptorChain(Arrays.asList(requestHandlers));
    InterceptorContext incerceptorContext = InterceptorContext.builder().request(NoopTestRequest.builder().build()).httpRequest(generateRequest()).build();
    return ExecutionContext.builder().signer(new NoOpSigner()).interceptorChain(interceptors).executionAttributes(new ExecutionAttributes()).interceptorContext(incerceptorContext).metricCollector(MetricCollector.create("ApiCall")).build();
}
Also used : NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) ExecutionInterceptorChain(software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain) InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext)

Example 3 with ExecutionInterceptorChain

use of software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain in project aws-sdk-java-v2 by aws.

the class ExceptionReportingUtilsTest method context.

public RequestExecutionContext context(ExecutionInterceptor... executionInterceptors) {
    List<ExecutionInterceptor> interceptors = Arrays.asList(executionInterceptors);
    ExecutionInterceptorChain executionInterceptorChain = new ExecutionInterceptorChain(interceptors);
    return RequestExecutionContext.builder().executionContext(ExecutionContext.builder().signer(new NoOpSigner()).executionAttributes(new ExecutionAttributes()).interceptorContext(InterceptorContext.builder().request(ValidSdkObjects.sdkRequest()).build()).interceptorChain(executionInterceptorChain).build()).originalRequest(ValidSdkObjects.sdkRequest()).build();
}
Also used : NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) ExecutionInterceptorChain(software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor)

Example 4 with ExecutionInterceptorChain

use of software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain in project aws-sdk-java-v2 by aws.

the class AwsExecutionContextBuilder method invokeInterceptorsAndCreateExecutionContext.

/**
 * Used by both sync and async clients to create the execution context, and run initial interceptors.
 */
public static <InputT extends SdkRequest, OutputT extends SdkResponse> ExecutionContext invokeInterceptorsAndCreateExecutionContext(ClientExecutionParams<InputT, OutputT> executionParams, SdkClientConfiguration clientConfig) {
    // Note: This is currently copied to DefaultS3Presigner and other presigners.
    // Don't edit this without considering those
    SdkRequest originalRequest = executionParams.getInput();
    MetricCollector metricCollector = resolveMetricCollector(executionParams);
    ExecutionAttributes executionAttributes = mergeExecutionAttributeOverrides(executionParams.executionAttributes(), clientConfig.option(SdkClientOption.EXECUTION_ATTRIBUTES), originalRequest.overrideConfiguration().map(c -> c.executionAttributes()).orElse(null));
    executionAttributes.putAttribute(InternalCoreExecutionAttribute.EXECUTION_ATTEMPT, 1).putAttribute(AwsSignerExecutionAttribute.SERVICE_CONFIG, clientConfig.option(SdkClientOption.SERVICE_CONFIGURATION)).putAttribute(AwsSignerExecutionAttribute.SERVICE_SIGNING_NAME, clientConfig.option(AwsClientOption.SERVICE_SIGNING_NAME)).putAttribute(AwsExecutionAttribute.AWS_REGION, clientConfig.option(AwsClientOption.AWS_REGION)).putAttribute(AwsExecutionAttribute.ENDPOINT_PREFIX, clientConfig.option(AwsClientOption.ENDPOINT_PREFIX)).putAttribute(AwsSignerExecutionAttribute.SIGNING_REGION, clientConfig.option(AwsClientOption.SIGNING_REGION)).putAttribute(SdkInternalExecutionAttribute.IS_FULL_DUPLEX, executionParams.isFullDuplex()).putAttribute(SdkInternalExecutionAttribute.HAS_INITIAL_REQUEST_EVENT, executionParams.hasInitialRequestEvent()).putAttribute(SdkExecutionAttribute.CLIENT_TYPE, clientConfig.option(SdkClientOption.CLIENT_TYPE)).putAttribute(SdkExecutionAttribute.SERVICE_NAME, clientConfig.option(SdkClientOption.SERVICE_NAME)).putAttribute(SdkExecutionAttribute.PROFILE_FILE, clientConfig.option(SdkClientOption.PROFILE_FILE)).putAttribute(SdkExecutionAttribute.PROFILE_NAME, clientConfig.option(SdkClientOption.PROFILE_NAME)).putAttribute(AwsExecutionAttribute.DUALSTACK_ENDPOINT_ENABLED, clientConfig.option(AwsClientOption.DUALSTACK_ENDPOINT_ENABLED)).putAttribute(AwsExecutionAttribute.FIPS_ENDPOINT_ENABLED, clientConfig.option(AwsClientOption.FIPS_ENDPOINT_ENABLED)).putAttribute(SdkExecutionAttribute.OPERATION_NAME, executionParams.getOperationName()).putAttribute(SdkExecutionAttribute.CLIENT_ENDPOINT, clientConfig.option(SdkClientOption.ENDPOINT)).putAttribute(SdkExecutionAttribute.ENDPOINT_OVERRIDDEN, clientConfig.option(SdkClientOption.ENDPOINT_OVERRIDDEN)).putAttribute(SdkInternalExecutionAttribute.DISABLE_HOST_PREFIX_INJECTION, clientConfig.option(SdkAdvancedClientOption.DISABLE_HOST_PREFIX_INJECTION)).putAttribute(SdkExecutionAttribute.SIGNER_OVERRIDDEN, clientConfig.option(SdkClientOption.SIGNER_OVERRIDDEN)).putAttribute(RESOLVED_CHECKSUM_SPECS, HttpChecksumResolver.getResolvedChecksumSpecs(executionAttributes));
    ExecutionInterceptorChain executionInterceptorChain = new ExecutionInterceptorChain(clientConfig.option(SdkClientOption.EXECUTION_INTERCEPTORS));
    InterceptorContext interceptorContext = InterceptorContext.builder().request(originalRequest).asyncRequestBody(executionParams.getAsyncRequestBody()).requestBody(executionParams.getRequestBody()).build();
    interceptorContext = runInitialInterceptors(interceptorContext, executionAttributes, executionInterceptorChain);
    Signer signer = resolveSigner(interceptorContext.request(), clientConfig.option(SdkAdvancedClientOption.SIGNER));
    // beforeExecution and modifyRequest interceptors should avoid dependency on credentials,
    // since they should be resolved after the interceptors run
    AwsCredentials credentials = resolveCredentials(clientConfig.option(AwsClientOption.CREDENTIALS_PROVIDER), originalRequest, metricCollector);
    executionAttributes.putAttribute(AwsSignerExecutionAttribute.AWS_CREDENTIALS, credentials);
    executionAttributes.putAttribute(HttpChecksumConstant.SIGNING_METHOD, resolveSigningMethodUsed(signer, executionAttributes, credentials));
    return ExecutionContext.builder().interceptorChain(executionInterceptorChain).interceptorContext(interceptorContext).executionAttributes(executionAttributes).signer(signer).metricCollector(metricCollector).build();
}
Also used : Signer(software.amazon.awssdk.core.signer.Signer) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkRequest(software.amazon.awssdk.core.SdkRequest) ExecutionInterceptorChain(software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain) InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 5 with ExecutionInterceptorChain

use of software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain in project aws-sdk-java-v2 by aws.

the class BaseClientHandler method invokeInterceptorsAndCreateExecutionContext.

// This method is only called from tests, since the subclasses in aws-core override it.
protected <InputT extends SdkRequest, OutputT extends SdkResponse> ExecutionContext invokeInterceptorsAndCreateExecutionContext(ClientExecutionParams<InputT, OutputT> params) {
    SdkRequest originalRequest = params.getInput();
    ExecutionAttributes executionAttributes = params.executionAttributes();
    executionAttributes.putAttribute(InternalCoreExecutionAttribute.EXECUTION_ATTEMPT, 1).putAttribute(SdkExecutionAttribute.SERVICE_CONFIG, clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION)).putAttribute(SdkExecutionAttribute.SERVICE_NAME, clientConfiguration.option(SdkClientOption.SERVICE_NAME)).putAttribute(SdkExecutionAttribute.PROFILE_FILE, clientConfiguration.option(SdkClientOption.PROFILE_FILE)).putAttribute(SdkExecutionAttribute.PROFILE_NAME, clientConfiguration.option(SdkClientOption.PROFILE_NAME));
    ExecutionInterceptorChain interceptorChain = new ExecutionInterceptorChain(clientConfiguration.option(SdkClientOption.EXECUTION_INTERCEPTORS));
    InterceptorContext interceptorContext = InterceptorContext.builder().request(originalRequest).build();
    interceptorChain.beforeExecution(interceptorContext, executionAttributes);
    interceptorContext = interceptorChain.modifyRequest(interceptorContext, executionAttributes);
    MetricCollector metricCollector = resolveMetricCollector(params);
    return ExecutionContext.builder().interceptorChain(interceptorChain).interceptorContext(interceptorContext).executionAttributes(executionAttributes).signer(clientConfiguration.option(SdkAdvancedClientOption.SIGNER)).metricCollector(metricCollector).build();
}
Also used : ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkRequest(software.amazon.awssdk.core.SdkRequest) ExecutionInterceptorChain(software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain) InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Aggregations

ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)8 ExecutionInterceptorChain (software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain)8 InterceptorContext (software.amazon.awssdk.core.interceptor.InterceptorContext)7 NoOpSigner (software.amazon.awssdk.core.signer.NoOpSigner)5 AwsCredentials (software.amazon.awssdk.auth.credentials.AwsCredentials)2 SdkRequest (software.amazon.awssdk.core.SdkRequest)2 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 Test (org.junit.Test)1 AwsCredentialsProvider (software.amazon.awssdk.auth.credentials.AwsCredentialsProvider)1 ExecutionContext (software.amazon.awssdk.core.http.ExecutionContext)1 ExecutionInterceptor (software.amazon.awssdk.core.interceptor.ExecutionInterceptor)1 SlowExecutionInterceptor (software.amazon.awssdk.core.internal.http.request.SlowExecutionInterceptor)1 Signer (software.amazon.awssdk.core.signer.Signer)1 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)1