Search in sources :

Example 16 with ExecutionContext

use of software.amazon.awssdk.core.http.ExecutionContext in project aws-sdk-java-v2 by aws.

the class AwsExecutionContextBuilderTest method signing_ifNoOverrides_assignDefaultSigner.

@Test
public void signing_ifNoOverrides_assignDefaultSigner() {
    ExecutionContext executionContext = AwsExecutionContextBuilder.invokeInterceptorsAndCreateExecutionContext(clientExecutionParams(), testClientConfiguration().build());
    assertThat(executionContext.signer()).isEqualTo(defaultSigner);
}
Also used : ExecutionContext(software.amazon.awssdk.core.http.ExecutionContext) Test(org.junit.Test)

Example 17 with ExecutionContext

use of software.amazon.awssdk.core.http.ExecutionContext in project aws-sdk-java-v2 by aws.

the class DefaultS3Presigner method marshalRequestAndUpdateContext.

/**
 * Marshal the request and update the execution context with the result.
 */
private <T> void marshalRequestAndUpdateContext(ExecutionContext execCtx, Class<T> requestType, Function<T, SdkHttpFullRequest> requestMarshaller) {
    T sdkRequest = Validate.isInstanceOf(requestType, execCtx.interceptorContext().request(), "Interceptor generated unsupported type (%s) when %s was expected.", execCtx.interceptorContext().request().getClass(), requestType);
    SdkHttpFullRequest marshalledRequest = requestMarshaller.apply(sdkRequest);
    // TODO: The core SDK doesn't put the request body into the interceptor context. That should be fixed.
    Optional<RequestBody> requestBody = marshalledRequest.contentStreamProvider().map(ContentStreamProvider::newStream).map(is -> invokeSafely(() -> IoUtils.toByteArray(is))).map(RequestBody::fromBytes);
    execCtx.interceptorContext(execCtx.interceptorContext().copy(r -> r.httpRequest(marshalledRequest).requestBody(requestBody.orElse(null))));
}
Also used : InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext) PutObjectPresignRequest(software.amazon.awssdk.services.s3.presigner.model.PutObjectPresignRequest) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) SdkBytes(software.amazon.awssdk.core.SdkBytes) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) PresignedPutObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) URI(java.net.URI) Validate(software.amazon.awssdk.utils.Validate) PresignedGetObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest) PresignRequest(software.amazon.awssdk.awscore.presigner.PresignRequest) PresignedUploadPartRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedUploadPartRequest) PresignedRequest(software.amazon.awssdk.awscore.presigner.PresignedRequest) ExecutionInterceptor(software.amazon.awssdk.core.interceptor.ExecutionInterceptor) CompleteMultipartUploadRequest(software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest) PresignedCompleteMultipartUploadRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedCompleteMultipartUploadRequest) Instant(java.time.Instant) PutObjectRequestMarshaller(software.amazon.awssdk.services.s3.transform.PutObjectRequestMarshaller) UploadPartPresignRequest(software.amazon.awssdk.services.s3.presigner.model.UploadPartPresignRequest) List(java.util.List) Stream(java.util.stream.Stream) PresignedCreateMultipartUploadRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedCreateMultipartUploadRequest) Optional(java.util.Optional) S3Configuration(software.amazon.awssdk.services.s3.S3Configuration) SdkRequest(software.amazon.awssdk.core.SdkRequest) AbortMultipartUploadRequest(software.amazon.awssdk.services.s3.model.AbortMultipartUploadRequest) PRESIGNER_EXPIRATION(software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute.PRESIGNER_EXPIRATION) CollectionUtils.mergeLists(software.amazon.awssdk.utils.CollectionUtils.mergeLists) AbortMultipartUploadRequestMarshaller(software.amazon.awssdk.services.s3.transform.AbortMultipartUploadRequestMarshaller) ExecutionInterceptorChain(software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain) ClientType(software.amazon.awssdk.core.ClientType) ExecutionContext(software.amazon.awssdk.core.http.ExecutionContext) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) Function(java.util.function.Function) PresignedAbortMultipartUploadRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedAbortMultipartUploadRequest) FunctionalUtils.invokeSafely(software.amazon.awssdk.utils.FunctionalUtils.invokeSafely) ArrayList(java.util.ArrayList) S3Presigner(software.amazon.awssdk.services.s3.presigner.S3Presigner) Presigner(software.amazon.awssdk.core.signer.Presigner) ClasspathInterceptorChainFactory(software.amazon.awssdk.core.interceptor.ClasspathInterceptorChainFactory) GetObjectRequestMarshaller(software.amazon.awssdk.services.s3.transform.GetObjectRequestMarshaller) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) SdkDefaultClientBuilder(software.amazon.awssdk.core.client.builder.SdkDefaultClientBuilder) UploadPartRequestMarshaller(software.amazon.awssdk.services.s3.transform.UploadPartRequestMarshaller) CompleteMultipartUploadRequestMarshaller(software.amazon.awssdk.services.s3.transform.CompleteMultipartUploadRequestMarshaller) AwsSignerExecutionAttribute(software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute) UploadPartRequest(software.amazon.awssdk.services.s3.model.UploadPartRequest) SdkExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkExecutionAttribute) CreateMultipartUploadPresignRequest(software.amazon.awssdk.services.s3.presigner.model.CreateMultipartUploadPresignRequest) AwsExecutionContextBuilder(software.amazon.awssdk.awscore.internal.AwsExecutionContextBuilder) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) Logger(software.amazon.awssdk.utils.Logger) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) CompleteMultipartUploadPresignRequest(software.amazon.awssdk.services.s3.presigner.model.CompleteMultipartUploadPresignRequest) GetObjectPresignRequest(software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest) AwsExecutionAttribute(software.amazon.awssdk.awscore.AwsExecutionAttribute) ContentStreamProvider(software.amazon.awssdk.http.ContentStreamProvider) AwsS3ProtocolFactory(software.amazon.awssdk.protocols.xml.AwsS3ProtocolFactory) AwsS3V4Signer(software.amazon.awssdk.auth.signer.AwsS3V4Signer) AbortMultipartUploadPresignRequest(software.amazon.awssdk.services.s3.presigner.model.AbortMultipartUploadPresignRequest) CreateMultipartUploadRequestMarshaller(software.amazon.awssdk.services.s3.transform.CreateMultipartUploadRequestMarshaller) AwsDefaultClientBuilder(software.amazon.awssdk.awscore.client.builder.AwsDefaultClientBuilder) DefaultServiceEndpointBuilder(software.amazon.awssdk.awscore.endpoint.DefaultServiceEndpointBuilder) RequestBody(software.amazon.awssdk.core.sync.RequestBody) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) CreateMultipartUploadRequest(software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest) Collections(java.util.Collections) IoUtils(software.amazon.awssdk.utils.IoUtils) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) RequestBody(software.amazon.awssdk.core.sync.RequestBody) ContentStreamProvider(software.amazon.awssdk.http.ContentStreamProvider)

Example 18 with ExecutionContext

use of software.amazon.awssdk.core.http.ExecutionContext in project aws-sdk-java-v2 by aws.

the class DefaultS3Presigner method presign.

/**
 * Generate a {@link PresignedRequest} from a {@link PresignedRequest} and {@link SdkRequest}.
 */
private <T extends PresignedRequest.Builder, U> T presign(T presignedRequest, PresignRequest presignRequest, SdkRequest requestToPresign, Class<U> requestToPresignType, Function<U, SdkHttpFullRequest> requestMarshaller, String operationName) {
    ExecutionContext execCtx = invokeInterceptorsAndCreateExecutionContext(presignRequest, requestToPresign, operationName);
    callBeforeMarshallingHooks(execCtx);
    marshalRequestAndUpdateContext(execCtx, requestToPresignType, requestMarshaller);
    callAfterMarshallingHooks(execCtx);
    addRequestLevelHeadersAndQueryParameters(execCtx);
    callModifyHttpRequestHooksAndUpdateContext(execCtx);
    SdkHttpFullRequest httpRequest = getHttpFullRequest(execCtx);
    SdkHttpFullRequest signedHttpRequest = presignRequest(execCtx, httpRequest);
    initializePresignedRequest(presignedRequest, execCtx, signedHttpRequest);
    return presignedRequest;
}
Also used : ExecutionContext(software.amazon.awssdk.core.http.ExecutionContext) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest)

Aggregations

ExecutionContext (software.amazon.awssdk.core.http.ExecutionContext)18 Test (org.junit.Test)9 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)9 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)8 Optional (java.util.Optional)6 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)5 ExecutionInterceptorChain (software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain)5 InterceptorContext (software.amazon.awssdk.core.interceptor.InterceptorContext)5 URI (java.net.URI)4 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)4 SdkRequest (software.amazon.awssdk.core.SdkRequest)4 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)4 Instant (java.time.Instant)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Function (java.util.function.Function)3 Collectors.toMap (java.util.stream.Collectors.toMap)3 Stream (java.util.stream.Stream)3