software.amazon.awssdk.core.SdkRequest Java Examples

The following examples show how to use software.amazon.awssdk.core.SdkRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChecksumsEnabledValidator.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that checksums should be enabled based on {@link ClientType} and the presence
 * or S3 specific headers.
 *
 * @param expectedClientType - The expected client type for enabling checksums
 * @param executionAttributes - {@link ExecutionAttributes} to determine the actual client type
 * @return If trailing checksums should be enabled for this request.
 */
public static boolean shouldRecordChecksum(SdkRequest sdkRequest,
                                           ClientType expectedClientType,
                                           ExecutionAttributes executionAttributes,
                                           SdkHttpRequest httpRequest) {
    if (!(sdkRequest instanceof PutObjectRequest)) {
        return false;
    }

    ClientType actualClientType = executionAttributes.getAttribute(SdkExecutionAttribute.CLIENT_TYPE);

    if (!expectedClientType.equals(actualClientType)) {
        return false;
    }


    if (hasServerSideEncryptionHeader(httpRequest)) {
        return false;
    }

    return checksumEnabledPerConfig(executionAttributes);
}
 
Example #2
Source File: CreateBucketInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * For us-east-1 there must not be a location constraint (or containing CreateBucketConfiguration) sent.
 */
@Test
public void modifyRequest_UsEast1_UsesNullBucketConfiguration() {
    CreateBucketRequest request = CreateBucketRequest.builder()
                                                     .bucket("test-bucket")
                                                     .createBucketConfiguration(CreateBucketConfiguration.builder()
                                                                                                         .build())
                                                     .build();

    Context.ModifyRequest context = () -> request;

    ExecutionAttributes attributes = new ExecutionAttributes()
            .putAttribute(AwsExecutionAttribute.AWS_REGION, Region.US_EAST_1);

    SdkRequest modifiedRequest = new CreateBucketInterceptor().modifyRequest(context, attributes);
    assertThat(((CreateBucketRequest) modifiedRequest).createBucketConfiguration()).isNull();
}
 
Example #3
Source File: EnableChunkedEncodingInterceptor.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) {
    SdkRequest sdkRequest = context.request();

    if (sdkRequest instanceof PutObjectRequest || sdkRequest instanceof UploadPartRequest) {
        S3Configuration serviceConfiguration =
                (S3Configuration) executionAttributes.getAttribute(AwsSignerExecutionAttribute.SERVICE_CONFIG);

        boolean enableChunkedEncoding;
        if (serviceConfiguration != null) {
            enableChunkedEncoding = serviceConfiguration.chunkedEncodingEnabled();
        } else {
            enableChunkedEncoding = true;
        }

        executionAttributes.putAttributeIfAbsent(S3SignerExecutionAttribute.ENABLE_CHUNKED_ENCODING, enableChunkedEncoding);
    }

    return sdkRequest;
}
 
Example #4
Source File: ApplyUserAgentInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void otherRequest_shouldNotModifyRequest() {
    SdkRequest someOtherRequest = new SdkRequest() {
        @Override
        public List<SdkField<?>> sdkFields() {
            return null;
        }

        @Override
        public Optional<? extends RequestOverrideConfiguration> overrideConfiguration() {
            return Optional.empty();
        }

        @Override
        public Builder toBuilder() {
            return null;
        }
    };
    SdkRequest sdkRequest = interceptor.modifyRequest(() -> someOtherRequest, new ExecutionAttributes());

    assertThat(sdkRequest).isEqualTo(someOtherRequest);
}
 
Example #5
Source File: InterceptorTestUtils.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
public static Context.ModifyHttpRequest modifyHttpRequestContext(SdkRequest request, SdkHttpRequest sdkHttpRequest) {
    Optional<RequestBody> requestBody = Optional.of(RequestBody.fromString("helloworld"));
    Optional<AsyncRequestBody> asyncRequestBody = Optional.of(AsyncRequestBody.fromString("helloworld"));

    return new Context.ModifyHttpRequest() {
        @Override
        public SdkHttpRequest httpRequest() {
            return sdkHttpRequest;
        }

        @Override
        public Optional<RequestBody> requestBody() {
            return requestBody;
        }

        @Override
        public Optional<AsyncRequestBody> asyncRequestBody() {
            return asyncRequestBody;
        }

        @Override
        public SdkRequest request() {
            return request;
        }
    };
}
 
Example #6
Source File: S3EndpointUtils.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Determine which endpoint to use based on region and {@link S3Configuration}. Will either be a traditional
 * S3 endpoint (i.e. s3.us-east-1.amazonaws.com), the global S3 accelerate endpoint (i.e. s3-accelerate.amazonaws.com) or
 * a regional dualstack endpoint for IPV6 (i.e. s3.dualstack.us-east-1.amazonaws.com).
 */
private static URI resolveEndpoint(SdkHttpRequest request,
                                   SdkRequest originalRequest,
                                   Region region,
                                   S3Configuration serviceConfiguration) {

    String protocol = request.protocol();

    RegionMetadata regionMetadata = RegionMetadata.of(region);

    if (isAccelerateEnabled(serviceConfiguration) && isAccelerateSupported(originalRequest)) {
        return accelerateEndpoint(serviceConfiguration, regionMetadata, protocol);
    }

    if (serviceConfiguration != null && serviceConfiguration.dualstackEnabled()) {
        return dualstackEndpoint(regionMetadata, protocol);
    }

    return invokeSafely(() -> new URI(request.protocol(), null, request.host(), request.port(), null, null, null));
}
 
Example #7
Source File: CreateBucketInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyRequest_UpdatesLocationConstraint_When_NullLocationConstraint() {
    CreateBucketRequest request = CreateBucketRequest.builder()
                                                     .bucket("test-bucket")
                                                     .createBucketConfiguration(CreateBucketConfiguration.builder()
                                                                                                         .build())
                                                     .build();

    Context.ModifyRequest context = () -> request;

    ExecutionAttributes attributes = new ExecutionAttributes()
            .putAttribute(AwsExecutionAttribute.AWS_REGION, Region.US_WEST_2);

    SdkRequest modifiedRequest = new CreateBucketInterceptor().modifyRequest(context, attributes);
    String locationConstraint = ((CreateBucketRequest) modifiedRequest).createBucketConfiguration().locationConstraintAsString();

    assertThat(locationConstraint).isEqualToIgnoringCase("us-west-2");
}
 
Example #8
Source File: ApiCallAttemptTimeoutTrackingStageTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private RequestExecutionContext requestContext(long timeout) {
    SdkRequestOverrideConfiguration.Builder configBuilder = SdkRequestOverrideConfiguration.builder();

    if (timeout > 0) {
        configBuilder.apiCallAttemptTimeout(Duration.ofMillis(timeout));
    }

    SdkRequest originalRequest =
        NoopTestRequest.builder()
                       .overrideConfiguration(configBuilder
                                                  .build())
                       .build();
    return RequestExecutionContext.builder()
                                  .executionContext(ClientExecutionAndRequestTimerTestUtils.executionContext(null))
                                  .originalRequest(originalRequest)
                                  .build();
}
 
Example #9
Source File: ValidSdkObjects.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
public static SdkRequest sdkRequest() {
    return new SdkRequest() {
        @Override
        public Optional<? extends RequestOverrideConfiguration> overrideConfiguration() {
            return Optional.empty();
        }

        @Override
        public Builder toBuilder() {
            return null;
        }

        @Override
        public List<SdkField<?>> sdkFields() {
            return null;
        }
    };
}
 
Example #10
Source File: AsyncClientHandlerTransformerVerificationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Before
public void testSetup() throws Exception {
    mockClient = mock(SdkAsyncHttpClient.class);

    executionParams = new ClientExecutionParams<SdkRequest, SdkResponse>()
            .withInput(request)
            .withMarshaller(marshaller)
            .withResponseHandler(responseHandler)
            .withErrorResponseHandler(errorResponseHandler);

    SdkClientConfiguration config = HttpTestUtils.testClientConfiguration().toBuilder()
            .option(SdkClientOption.ASYNC_HTTP_CLIENT, mockClient)
            .option(SdkClientOption.RETRY_POLICY, RETRY_POLICY)
            .option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR, Runnable::run)
            .build();

    clientHandler = new SdkAsyncClientHandler(config);

    when(request.overrideConfiguration()).thenReturn(Optional.empty());

    when(marshaller.marshall(eq(request))).thenReturn(ValidSdkObjects.sdkHttpFullRequest().build());

    when(responseHandler.handle(any(SdkHttpFullResponse.class), any(ExecutionAttributes.class)))
            .thenReturn(VoidSdkResponse.builder().build());
}
 
Example #11
Source File: DefaultS3Presigner.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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 = createExecutionContext(presignRequest, requestToPresign, operationName);

    callBeforeExecutionHooks(execCtx);
    callModifyRequestHooksAndUpdateContext(execCtx);
    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;
}
 
Example #12
Source File: BaseSyncClientHandler.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public <InputT extends SdkRequest, OutputT extends SdkResponse> OutputT execute(
    ClientExecutionParams<InputT, OutputT> executionParams) {

    validateExecutionParams(executionParams);
    ExecutionContext executionContext = createExecutionContext(executionParams, createInitialExecutionAttributes());
    HttpResponseHandler<Response<OutputT>> combinedResponseHandler;

    if (executionParams.getCombinedResponseHandler() != null) {
        combinedResponseHandler = decorateSuccessResponseHandlers(executionParams.getCombinedResponseHandler(),
                                                                  executionContext);
    } else {
        HttpResponseHandler<OutputT> decoratedResponseHandlers =
            decorateResponseHandlers(executionParams.getResponseHandler(), executionContext);

        combinedResponseHandler = new CombinedResponseHandler<>(decoratedResponseHandlers,
                                                                executionParams.getErrorResponseHandler());
    }

    return doExecute(executionParams, executionContext, combinedResponseHandler);
}
 
Example #13
Source File: EnableChunkedEncodingInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private Context.ModifyHttpRequest context(SdkRequest request) {
    return new Context.ModifyHttpRequest() {
        @Override
        public SdkHttpRequest httpRequest() {
            return null;
        }

        @Override
        public Optional<RequestBody> requestBody() {
            return null;
        }

        @Override
        public Optional<AsyncRequestBody> asyncRequestBody() {
            return null;
        }

        @Override
        public SdkRequest request() {
            return request;
        }
    };
}
 
Example #14
Source File: ApiCallTimeoutTrackingStageTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private RequestExecutionContext requestContext(long timeout) {
    SdkRequestOverrideConfiguration.Builder configBuilder = SdkRequestOverrideConfiguration.builder();

    if (timeout > 0) {
        configBuilder.apiCallTimeout(Duration.ofMillis(timeout));
    }

    SdkRequest originalRequest =
        NoopTestRequest.builder()
                       .overrideConfiguration(configBuilder
                                                  .build())
                       .build();
    return RequestExecutionContext.builder()
                                  .executionContext(ClientExecutionAndRequestTimerTestUtils.executionContext(null))
                                  .originalRequest(originalRequest)
                                  .build();
}
 
Example #15
Source File: MessageMD5ChecksumInterceptor.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public void afterExecution(Context.AfterExecution context, ExecutionAttributes executionAttributes) {
    SdkResponse response = context.response();
    SdkRequest originalRequest = context.request();
    if (response != null) {
        if (originalRequest instanceof SendMessageRequest) {
            SendMessageRequest sendMessageRequest = (SendMessageRequest) originalRequest;
            SendMessageResponse sendMessageResult = (SendMessageResponse) response;
            sendMessageOperationMd5Check(sendMessageRequest, sendMessageResult);

        } else if (originalRequest instanceof ReceiveMessageRequest) {
            ReceiveMessageResponse receiveMessageResult = (ReceiveMessageResponse) response;
            receiveMessageResultMd5Check(receiveMessageResult);

        } else if (originalRequest instanceof SendMessageBatchRequest) {
            SendMessageBatchRequest sendMessageBatchRequest = (SendMessageBatchRequest) originalRequest;
            SendMessageBatchResponse sendMessageBatchResult = (SendMessageBatchResponse) response;
            sendMessageBatchOperationMd5Check(sendMessageBatchRequest, sendMessageBatchResult);
        }
    }
}
 
Example #16
Source File: BaseAsyncClientHandler.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public <InputT extends SdkRequest, OutputT extends SdkResponse> CompletableFuture<OutputT> execute(
    ClientExecutionParams<InputT, OutputT> executionParams) {

    validateExecutionParams(executionParams);
    ExecutionContext executionContext = createExecutionContext(executionParams, createInitialExecutionAttributes());
    TransformingAsyncResponseHandler<Response<OutputT>> combinedResponseHandler;

    /* Decorate and combine provided response handlers into a single decorated response handler */
    if (executionParams.getCombinedResponseHandler() == null) {
        combinedResponseHandler = createDecoratedHandler(executionParams.getResponseHandler(),
                                                         executionParams.getErrorResponseHandler(),
                                                         executionContext);
    } else {
        combinedResponseHandler = createDecoratedHandler(executionParams.getCombinedResponseHandler(),
                                                         executionContext);
    }

    return doExecute(executionParams, executionContext, combinedResponseHandler);
}
 
Example #17
Source File: BaseClientHandler.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
protected <InputT extends SdkRequest, OutputT extends SdkResponse> ExecutionContext createExecutionContext(
    ClientExecutionParams<InputT, OutputT> params, ExecutionAttributes executionAttributes) {

    SdkRequest originalRequest = params.getInput();

    executionAttributes
        .putAttribute(SdkExecutionAttribute.SERVICE_CONFIG,
                      clientConfiguration.option(SdkClientOption.SERVICE_CONFIGURATION))
        .putAttribute(SdkExecutionAttribute.SERVICE_NAME, clientConfiguration.option(SdkClientOption.SERVICE_NAME));

    ExecutionInterceptorChain interceptorChain =
            new ExecutionInterceptorChain(clientConfiguration.option(SdkClientOption.EXECUTION_INTERCEPTORS));

    return ExecutionContext.builder()
                           .interceptorChain(interceptorChain)
                           .interceptorContext(InterceptorContext.builder()
                                                                 .request(originalRequest)
                                                                 .build())
                           .executionAttributes(executionAttributes)
                           .signer(clientConfiguration.option(SdkAdvancedClientOption.SIGNER))
                           .build();
}
 
Example #18
Source File: ExecutionInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) {
    MembersInHeadersRequest request = (MembersInHeadersRequest) context.request();
    return request.toBuilder()
            .stringMember("1")
            .build();
}
 
Example #19
Source File: InterruptFlagAlwaysClearsTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private void executeRequestIgnoreErrors(SdkSyncClientHandler syncHttpClient) {
    try {
        syncHttpClient.execute(new ClientExecutionParams<SdkRequest, SdkResponse>()
                .withOperationName("SomeOperation")
                .withResponseHandler(responseHandler)
                .withErrorResponseHandler(errorResponseHandler)
                .withInput(NoopTestRequest.builder().build())
                .withMarshaller(marshaller));
        Assert.fail();
    } catch (AbortedException | ApiCallAttemptTimeoutException | SdkServiceException e) {
        // Ignored
    }
}
 
Example #20
Source File: DefaultS3Presigner.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private void addRequestLevelHeaders(SdkHttpRequest.Builder builder, SdkRequest request) {
    request.overrideConfiguration().ifPresent(overrideConfig -> {
        if (!overrideConfig.headers().isEmpty()) {
            overrideConfig.headers().forEach(builder::putHeader);
        }
    });
}
 
Example #21
Source File: DefaultS3Presigner.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Update the provided HTTP request by adding any HTTP headers or query parameters specified as part of the
 * {@link SdkRequest}.
 */
private void addRequestLevelHeadersAndQueryParameters(ExecutionContext execCtx) {
    SdkHttpRequest httpRequest = execCtx.interceptorContext().httpRequest();
    SdkRequest sdkRequest = execCtx.interceptorContext().request();
    SdkHttpRequest updatedHttpRequest =
        httpRequest.toBuilder()
                   .applyMutation(b -> addRequestLevelHeaders(b, sdkRequest))
                   .applyMutation(b -> addRequestLeveQueryParameters(b, sdkRequest))
                   .build();
    execCtx.interceptorContext(execCtx.interceptorContext().copy(c -> c.httpRequest(updatedHttpRequest)));
}
 
Example #22
Source File: ApplyUserAgentInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void ddbRequest_shouldModifyRequest() {
    GetItemRequest getItemRequest = GetItemRequest.builder().build();
    SdkRequest sdkRequest = interceptor.modifyRequest(() -> getItemRequest, new ExecutionAttributes());

    RequestOverrideConfiguration requestOverrideConfiguration = sdkRequest.overrideConfiguration().get();
    assertThat(requestOverrideConfiguration.apiNames()
                                           .stream()
                                           .filter(a -> a.name()
                                                         .equals("hll") &&
                                                        a.version().equals("ddb-enh")).findAny())
        .isPresent();
}
 
Example #23
Source File: AwsSyncClientHandler.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private <InputT extends SdkRequest, OutputT> ClientExecutionParams<InputT, OutputT> addCrc32Validation(
    ClientExecutionParams<InputT, OutputT> executionParams) {
    if (executionParams.getCombinedResponseHandler() != null) {
        return executionParams.withCombinedResponseHandler(
            new Crc32ValidationResponseHandler<>(executionParams.getCombinedResponseHandler()));
    } else {
        return executionParams.withResponseHandler(
            new Crc32ValidationResponseHandler<>(executionParams.getResponseHandler()));
    }
}
 
Example #24
Source File: HelpfulUnknownHostExceptionInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private Throwable modifyException(Throwable throwable, Region clientRegion, String serviceEndpointPrefix) {
    SdkRequest sdkRequest = Mockito.mock(SdkRequest.class);

    DefaultFailedExecutionContext context =
        DefaultFailedExecutionContext.builder()
                                     .interceptorContext(InterceptorContext.builder().request(sdkRequest).build())
                                     .exception(throwable)
                                     .build();

    ExecutionAttributes executionAttributes =
        new ExecutionAttributes().putAttribute(AwsExecutionAttribute.AWS_REGION, clientRegion)
                                 .putAttribute(AwsExecutionAttribute.ENDPOINT_PREFIX, serviceEndpointPrefix);

    return INTERCEPTOR.modifyException(context, executionAttributes);
}
 
Example #25
Source File: BaseSyncClientHandler.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private <InputT extends SdkRequest, OutputT, ReturnT> ReturnT doExecute(
    ClientExecutionParams<InputT, OutputT> executionParams,
    ExecutionContext executionContext,
    HttpResponseHandler<Response<ReturnT>> responseHandler) {

    InputT inputT = (InputT) finalizeSdkRequest(executionContext).request();

    InterceptorContext sdkHttpFullRequestContext = finalizeSdkHttpFullRequest(executionParams,
                                                                              executionContext,
                                                                              inputT,
                                                                              clientConfiguration);

    SdkHttpFullRequest marshalled = (SdkHttpFullRequest) sdkHttpFullRequestContext.httpRequest();

    // TODO Pass requestBody as separate arg to invoke
    Optional<RequestBody> requestBody = sdkHttpFullRequestContext.requestBody();

    if (requestBody.isPresent()) {
        marshalled = marshalled.toBuilder()
                               .contentStreamProvider(requestBody.get().contentStreamProvider())
                               .build();
    }

    return invoke(marshalled,
                  inputT,
                  executionContext,
                  responseHandler);
}
 
Example #26
Source File: BaseSyncClientHandler.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke the request using the http client. Assumes credentials (or lack thereof) have been
 * configured in the OldExecutionContext beforehand.
 **/
private <OutputT> OutputT invoke(SdkHttpFullRequest request,
                                   SdkRequest originalRequest,
                                   ExecutionContext executionContext,
                                   HttpResponseHandler<Response<OutputT>> responseHandler) {
    return client.requestExecutionBuilder()
                 .request(request)
                 .originalRequest(originalRequest)
                 .executionContext(executionContext)
                 .execute(responseHandler);
}
 
Example #27
Source File: BaseSyncClientHandler.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public <InputT extends SdkRequest, OutputT extends SdkResponse, ReturnT> ReturnT execute(
    ClientExecutionParams<InputT, OutputT> executionParams,
    ResponseTransformer<OutputT, ReturnT> responseTransformer) {

    validateExecutionParams(executionParams);

    if (executionParams.getCombinedResponseHandler() != null) {
        // There is no support for catching errors in a body for streaming responses
        throw new IllegalArgumentException("A streaming 'responseTransformer' may not be used when a "
                                           + "'combinedResponseHandler' has been specified in a "
                                           + "ClientExecutionParams object.");
    }

    ExecutionContext executionContext = createExecutionContext(executionParams, createInitialExecutionAttributes());

    HttpResponseHandler<OutputT> decoratedResponseHandlers =
        decorateResponseHandlers(executionParams.getResponseHandler(), executionContext);

    HttpResponseHandler<ReturnT> httpResponseHandler =
        new HttpResponseHandlerAdapter<>(decoratedResponseHandlers, responseTransformer);

    return doExecute(
        executionParams,
        executionContext,
        new CombinedResponseHandler<>(httpResponseHandler, executionParams.getErrorResponseHandler()));
}
 
Example #28
Source File: BaseAsyncClientHandler.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke the request using the http client. Assumes credentials (or lack thereof) have been
 * configured in the ExecutionContext beforehand.
 **/
private <InputT extends SdkRequest, OutputT> CompletableFuture<OutputT> invoke(
    SdkHttpFullRequest request,
    AsyncRequestBody requestProvider,
    InputT originalRequest,
    ExecutionContext executionContext,
    TransformingAsyncResponseHandler<Response<OutputT>> responseHandler) {
    return client.requestExecutionBuilder()
                 .requestProvider(requestProvider)
                 .request(request)
                 .originalRequest(originalRequest)
                 .executionContext(executionContext)
                 .execute(responseHandler);
}
 
Example #29
Source File: ExecutionInterceptorChain.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
public InterceptorContext modifyRequest(InterceptorContext context, ExecutionAttributes executionAttributes) {
    InterceptorContext result = context;
    for (ExecutionInterceptor interceptor : interceptors) {
        SdkRequest interceptorResult = interceptor.modifyRequest(result, executionAttributes);
        validateInterceptorResult(result.request(), interceptorResult, interceptor, "modifyRequest");

        result = result.copy(b -> b.request(interceptorResult));
    }
    return result;
}
 
Example #30
Source File: BaseClientHandler.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Finalize {@link SdkHttpFullRequest} by running beforeMarshalling, afterMarshalling,
 * modifyHttpRequest, modifyHttpContent and modifyAsyncHttpContent interceptors
 */
static <InputT extends SdkRequest, OutputT> InterceptorContext finalizeSdkHttpFullRequest(
    ClientExecutionParams<InputT, OutputT> executionParams,
    ExecutionContext executionContext, InputT inputT,
    SdkClientConfiguration clientConfiguration) {

    runBeforeMarshallingInterceptors(executionContext);
    SdkHttpFullRequest request = executionParams.getMarshaller().marshall(inputT);
    request = modifyEndpointHostIfNeeded(request, clientConfiguration, executionParams);

    addHttpRequest(executionContext, request);
    runAfterMarshallingInterceptors(executionContext);
    return runModifyHttpRequestAndHttpContentInterceptors(executionContext);
}