Search in sources :

Example 16 with AwsRequestOverrideConfiguration

use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.

the class DefaultQueryAsyncClient method applySignerOverride.

private <T extends QueryRequest> T applySignerOverride(T request, Signer signer) {
    if (request.overrideConfiguration().flatMap(c -> c.signer()).isPresent()) {
        return request;
    }
    Consumer<AwsRequestOverrideConfiguration.Builder> signerOverride = b -> b.signer(signer).build();
    AwsRequestOverrideConfiguration overrideConfiguration = request.overrideConfiguration().map(c -> c.toBuilder().applyMutation(signerOverride).build()).orElse((AwsRequestOverrideConfiguration.builder().applyMutation(signerOverride).build()));
    return (T) request.toBuilder().overrideConfiguration(overrideConfiguration).build();
}
Also used : ExceptionMetadata(software.amazon.awssdk.protocols.core.ExceptionMetadata) StreamingInputOperationRequestMarshaller(software.amazon.awssdk.services.query.transform.StreamingInputOperationRequestMarshaller) AwsAsyncClientHandler(software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler) LoggerFactory(org.slf4j.LoggerFactory) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) QueryException(software.amazon.awssdk.services.query.model.QueryException) AsyncStreamingRequestMarshaller(software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller) AsyncResponseTransformer(software.amazon.awssdk.core.async.AsyncResponseTransformer) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) OperationWithChecksumRequiredResponse(software.amazon.awssdk.services.query.model.OperationWithChecksumRequiredResponse) AsyncClientHandler(software.amazon.awssdk.core.client.handler.AsyncClientHandler) APostOperationRequestMarshaller(software.amazon.awssdk.services.query.transform.APostOperationRequestMarshaller) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) StreamingOutputOperationResponse(software.amazon.awssdk.services.query.model.StreamingOutputOperationResponse) StreamingOutputOperationRequest(software.amazon.awssdk.services.query.model.StreamingOutputOperationRequest) List(java.util.List) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) OperationWithChecksumRequiredRequest(software.amazon.awssdk.services.query.model.OperationWithChecksumRequiredRequest) AsyncAws4Signer(software.amazon.awssdk.auth.signer.AsyncAws4Signer) HttpResponseHandler(software.amazon.awssdk.core.http.HttpResponseHandler) PutOperationWithChecksumResponse(software.amazon.awssdk.services.query.model.PutOperationWithChecksumResponse) Generated(software.amazon.awssdk.annotations.Generated) AsyncResponseTransformerUtils(software.amazon.awssdk.core.async.AsyncResponseTransformerUtils) GetOperationWithChecksumRequest(software.amazon.awssdk.services.query.model.GetOperationWithChecksumRequest) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) Signer(software.amazon.awssdk.core.signer.Signer) PutOperationWithChecksumRequestMarshaller(software.amazon.awssdk.services.query.transform.PutOperationWithChecksumRequestMarshaller) OperationWithChecksumRequiredRequestMarshaller(software.amazon.awssdk.services.query.transform.OperationWithChecksumRequiredRequestMarshaller) CompletableFutureUtils(software.amazon.awssdk.utils.CompletableFutureUtils) CompletableFuture(java.util.concurrent.CompletableFuture) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) StreamingOutputOperationRequestMarshaller(software.amazon.awssdk.services.query.transform.StreamingOutputOperationRequestMarshaller) StreamingInputOperationRequest(software.amazon.awssdk.services.query.model.StreamingInputOperationRequest) HttpChecksumRequired(software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired) CoreMetric(software.amazon.awssdk.core.metrics.CoreMetric) AwsQueryProtocolFactory(software.amazon.awssdk.protocols.query.AwsQueryProtocolFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RequestOverrideConfiguration(software.amazon.awssdk.core.RequestOverrideConfiguration) InvalidInputException(software.amazon.awssdk.services.query.model.InvalidInputException) APostOperationResponse(software.amazon.awssdk.services.query.model.APostOperationResponse) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) GetOperationWithChecksumResponse(software.amazon.awssdk.services.query.model.GetOperationWithChecksumResponse) APostOperationWithOutputResponse(software.amazon.awssdk.services.query.model.APostOperationWithOutputResponse) APostOperationWithOutputRequestMarshaller(software.amazon.awssdk.services.query.transform.APostOperationWithOutputRequestMarshaller) Logger(org.slf4j.Logger) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) QueryAsyncWaiter(software.amazon.awssdk.services.query.waiters.QueryAsyncWaiter) StreamingInputOperationResponse(software.amazon.awssdk.services.query.model.StreamingInputOperationResponse) Pair(software.amazon.awssdk.utils.Pair) PutOperationWithChecksumRequest(software.amazon.awssdk.services.query.model.PutOperationWithChecksumRequest) QueryRequest(software.amazon.awssdk.services.query.model.QueryRequest) Consumer(java.util.function.Consumer) HttpChecksum(software.amazon.awssdk.core.interceptor.trait.HttpChecksum) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) APostOperationWithOutputRequest(software.amazon.awssdk.services.query.model.APostOperationWithOutputRequest) APostOperationRequest(software.amazon.awssdk.services.query.model.APostOperationRequest) GetOperationWithChecksumRequestMarshaller(software.amazon.awssdk.services.query.transform.GetOperationWithChecksumRequestMarshaller) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) FunctionalUtils.runAndLogError(software.amazon.awssdk.utils.FunctionalUtils.runAndLogError) Collections(java.util.Collections) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration)

Example 17 with AwsRequestOverrideConfiguration

use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.

the class DefaultEndpointDiscoveryTestAsyncClient method testDiscoveryRequired.

/**
 * Invokes the TestDiscoveryRequired operation asynchronously.
 *
 * @param testDiscoveryRequiredRequest
 * @return A Java Future containing the result of the TestDiscoveryRequired operation returned by the service.<br/>
 *         The CompletableFuture returned by this method can be completed exceptionally with the following
 *         exceptions.
 *         <ul>
 *         <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
 *         Can be used for catch all scenarios.</li>
 *         <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
 *         credentials, etc.</li>
 *         <li>EndpointDiscoveryTestException Base class for all service exceptions. Unknown exceptions will be
 *         thrown as an instance of this type.</li>
 *         </ul>
 * @sample EndpointDiscoveryTestAsyncClient.TestDiscoveryRequired
 */
@Override
public CompletableFuture<TestDiscoveryRequiredResponse> testDiscoveryRequired(TestDiscoveryRequiredRequest testDiscoveryRequiredRequest) {
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, testDiscoveryRequiredRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryRequired");
        JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
        HttpResponseHandler<TestDiscoveryRequiredResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, TestDiscoveryRequiredResponse::builder);
        HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
        boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
        boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
        if (endpointOverridden) {
            throw new IllegalStateException("This operation requires endpoint discovery, but an endpoint override was specified when the client was created. This is not supported.");
        }
        if (!endpointDiscoveryEnabled) {
            throw new IllegalStateException("This operation requires endpoint discovery, but endpoint discovery was disabled on the client.");
        }
        URI cachedEndpoint = null;
        if (endpointDiscoveryEnabled) {
            String key = testDiscoveryRequiredRequest.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsProvider).orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER)).resolveCredentials().accessKeyId();
            EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true).defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)).overrideConfiguration(testDiscoveryRequiredRequest.overrideConfiguration().orElse(null)).build();
            cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest);
        }
        CompletableFuture<TestDiscoveryRequiredResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<TestDiscoveryRequiredRequest, TestDiscoveryRequiredResponse>().withOperationName("TestDiscoveryRequired").withMarshaller(new TestDiscoveryRequiredRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector).discoveredEndpoint(cachedEndpoint).withInput(testDiscoveryRequiredRequest));
        CompletableFuture<TestDiscoveryRequiredResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
            metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
        });
        executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
        return executeFuture;
    } catch (Throwable t) {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
        return CompletableFutureUtils.failedFuture(t);
    }
}
Also used : AwsJsonProtocol(software.amazon.awssdk.protocols.json.AwsJsonProtocol) AwsAsyncClientHandler(software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler) LoggerFactory(org.slf4j.LoggerFactory) CompletableFutureUtils(software.amazon.awssdk.utils.CompletableFutureUtils) CompletableFuture(java.util.concurrent.CompletableFuture) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) DescribeEndpointsResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.DescribeEndpointsResponse) TestDiscoveryRequiredRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryRequiredRequestMarshaller) CoreMetric(software.amazon.awssdk.core.metrics.CoreMetric) TestDiscoveryIdentifiersRequiredRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryIdentifiersRequiredRequestMarshaller) TestDiscoveryOptionalRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryOptionalRequestMarshaller) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) BaseAwsJsonProtocolFactory(software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory) AwsClientOption(software.amazon.awssdk.awscore.client.config.AwsClientOption) RequestOverrideConfiguration(software.amazon.awssdk.core.RequestOverrideConfiguration) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) URI(java.net.URI) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) AsyncClientHandler(software.amazon.awssdk.core.client.handler.AsyncClientHandler) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) Logger(org.slf4j.Logger) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) EndpointDiscoveryRefreshCache(software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRefreshCache) DescribeEndpointsRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.DescribeEndpointsRequestMarshaller) EndpointDiscoveryTestException(software.amazon.awssdk.services.endpointdiscoverytest.model.EndpointDiscoveryTestException) TestDiscoveryOptionalResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryOptionalResponse) List(java.util.List) TestDiscoveryRequiredResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryRequiredResponse) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) EndpointDiscoveryRequest(software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest) TestDiscoveryRequiredRequest(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryRequiredRequest) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) HttpResponseHandler(software.amazon.awssdk.core.http.HttpResponseHandler) TestDiscoveryIdentifiersRequiredRequest(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryIdentifiersRequiredRequest) AwsJsonProtocolFactory(software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory) FunctionalUtils.runAndLogError(software.amazon.awssdk.utils.FunctionalUtils.runAndLogError) Collections(java.util.Collections) TestDiscoveryIdentifiersRequiredResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryIdentifiersRequiredResponse) Generated(software.amazon.awssdk.annotations.Generated) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) DescribeEndpointsRequest(software.amazon.awssdk.services.endpointdiscoverytest.model.DescribeEndpointsRequest) TestDiscoveryOptionalRequest(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryOptionalRequest) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) TestDiscoveryRequiredResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryRequiredResponse) TestDiscoveryRequiredRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryRequiredRequestMarshaller) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) EndpointDiscoveryRequest(software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) URI(java.net.URI) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 18 with AwsRequestOverrideConfiguration

use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.

the class DefaultEndpointDiscoveryTestAsyncClient method testDiscoveryOptional.

/**
 * Invokes the TestDiscoveryOptional operation asynchronously.
 *
 * @param testDiscoveryOptionalRequest
 * @return A Java Future containing the result of the TestDiscoveryOptional operation returned by the service.<br/>
 *         The CompletableFuture returned by this method can be completed exceptionally with the following
 *         exceptions.
 *         <ul>
 *         <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
 *         Can be used for catch all scenarios.</li>
 *         <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
 *         credentials, etc.</li>
 *         <li>EndpointDiscoveryTestException Base class for all service exceptions. Unknown exceptions will be
 *         thrown as an instance of this type.</li>
 *         </ul>
 * @sample EndpointDiscoveryTestAsyncClient.TestDiscoveryOptional
 */
@Override
public CompletableFuture<TestDiscoveryOptionalResponse> testDiscoveryOptional(TestDiscoveryOptionalRequest testDiscoveryOptionalRequest) {
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, testDiscoveryOptionalRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryOptional");
        JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
        HttpResponseHandler<TestDiscoveryOptionalResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, TestDiscoveryOptionalResponse::builder);
        HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
        boolean endpointDiscoveryEnabled = clientConfiguration.option(SdkClientOption.ENDPOINT_DISCOVERY_ENABLED);
        boolean endpointOverridden = clientConfiguration.option(SdkClientOption.ENDPOINT_OVERRIDDEN) == Boolean.TRUE;
        URI cachedEndpoint = null;
        if (endpointDiscoveryEnabled) {
            String key = testDiscoveryOptionalRequest.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsProvider).orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER)).resolveCredentials().accessKeyId();
            EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(false).defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)).overrideConfiguration(testDiscoveryOptionalRequest.overrideConfiguration().orElse(null)).build();
            cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest);
        }
        CompletableFuture<TestDiscoveryOptionalResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<TestDiscoveryOptionalRequest, TestDiscoveryOptionalResponse>().withOperationName("TestDiscoveryOptional").withMarshaller(new TestDiscoveryOptionalRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector).discoveredEndpoint(cachedEndpoint).withInput(testDiscoveryOptionalRequest));
        CompletableFuture<TestDiscoveryOptionalResponse> whenCompleted = executeFuture.whenComplete((r, e) -> {
            metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
        });
        executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
        return executeFuture;
    } catch (Throwable t) {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
        return CompletableFutureUtils.failedFuture(t);
    }
}
Also used : AwsJsonProtocol(software.amazon.awssdk.protocols.json.AwsJsonProtocol) AwsAsyncClientHandler(software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler) LoggerFactory(org.slf4j.LoggerFactory) CompletableFutureUtils(software.amazon.awssdk.utils.CompletableFutureUtils) CompletableFuture(java.util.concurrent.CompletableFuture) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) DescribeEndpointsResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.DescribeEndpointsResponse) TestDiscoveryRequiredRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryRequiredRequestMarshaller) CoreMetric(software.amazon.awssdk.core.metrics.CoreMetric) TestDiscoveryIdentifiersRequiredRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryIdentifiersRequiredRequestMarshaller) TestDiscoveryOptionalRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryOptionalRequestMarshaller) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) BaseAwsJsonProtocolFactory(software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory) AwsClientOption(software.amazon.awssdk.awscore.client.config.AwsClientOption) RequestOverrideConfiguration(software.amazon.awssdk.core.RequestOverrideConfiguration) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) URI(java.net.URI) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) AsyncClientHandler(software.amazon.awssdk.core.client.handler.AsyncClientHandler) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) Logger(org.slf4j.Logger) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) EndpointDiscoveryRefreshCache(software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRefreshCache) DescribeEndpointsRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.DescribeEndpointsRequestMarshaller) EndpointDiscoveryTestException(software.amazon.awssdk.services.endpointdiscoverytest.model.EndpointDiscoveryTestException) TestDiscoveryOptionalResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryOptionalResponse) List(java.util.List) TestDiscoveryRequiredResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryRequiredResponse) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) EndpointDiscoveryRequest(software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest) TestDiscoveryRequiredRequest(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryRequiredRequest) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) HttpResponseHandler(software.amazon.awssdk.core.http.HttpResponseHandler) TestDiscoveryIdentifiersRequiredRequest(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryIdentifiersRequiredRequest) AwsJsonProtocolFactory(software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory) FunctionalUtils.runAndLogError(software.amazon.awssdk.utils.FunctionalUtils.runAndLogError) Collections(java.util.Collections) TestDiscoveryIdentifiersRequiredResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryIdentifiersRequiredResponse) Generated(software.amazon.awssdk.annotations.Generated) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) DescribeEndpointsRequest(software.amazon.awssdk.services.endpointdiscoverytest.model.DescribeEndpointsRequest) TestDiscoveryOptionalRequest(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryOptionalRequest) TestDiscoveryOptionalResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryOptionalResponse) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) TestDiscoveryOptionalRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryOptionalRequestMarshaller) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) EndpointDiscoveryRequest(software.amazon.awssdk.core.endpointdiscovery.EndpointDiscoveryRequest) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) URI(java.net.URI) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector)

Example 19 with AwsRequestOverrideConfiguration

use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.

the class S3PresignerTest method getObject_NonSigV4SignersRaisesException.

@Test
public void getObject_NonSigV4SignersRaisesException() {
    AwsRequestOverrideConfiguration override = AwsRequestOverrideConfiguration.builder().signer(new NoOpSigner()).build();
    assertThatThrownBy(() -> presigner.presignGetObject(r -> r.signatureDuration(Duration.ofMinutes(5)).getObjectRequest(go -> go.bucket("foo34343434").key("bar").overrideConfiguration(override)))).isInstanceOf(IllegalStateException.class).hasMessageContaining("NoOpSigner");
}
Also used : Offset(org.assertj.core.data.Offset) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) RunWith(org.junit.runner.RunWith) AbstractAwsS3V4Signer(software.amazon.awssdk.auth.signer.internal.AbstractAwsS3V4Signer) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) AwsS3V4SignerParams(software.amazon.awssdk.auth.signer.params.AwsS3V4SignerParams) ChecksumConstant(software.amazon.awssdk.services.s3.checksums.ChecksumConstant) NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) RequestPayer(software.amazon.awssdk.services.s3.model.RequestPayer) S3Presigner(software.amazon.awssdk.services.s3.presigner.S3Presigner) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SignerConstant(software.amazon.awssdk.auth.signer.internal.SignerConstant) Duration(java.time.Duration) After(org.junit.After) PresignedPutObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest) Aws4SignerRequestParams(software.amazon.awssdk.auth.signer.internal.Aws4SignerRequestParams) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) URI(java.net.URI) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Region(software.amazon.awssdk.regions.Region) Aws4PresignerParams(software.amazon.awssdk.auth.signer.params.Aws4PresignerParams) Before(org.junit.Before) PresignedGetObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) Test(org.junit.Test) AwsS3V4Signer(software.amazon.awssdk.auth.signer.AwsS3V4Signer) Instant(java.time.Instant) ZoneId(java.time.ZoneId) AbstractAws4Signer(software.amazon.awssdk.auth.signer.internal.AbstractAws4Signer) Mockito(org.mockito.Mockito) LocalDate(java.time.LocalDate) Clock(java.time.Clock) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) DateUtils(software.amazon.awssdk.utils.DateUtils) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) Test(org.junit.Test)

Example 20 with AwsRequestOverrideConfiguration

use of software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration in project aws-sdk-java-v2 by aws.

the class S3PresignerTest method putObject_AdditionalHeadersAndQueryStringsCanBeAdded.

@Test
public void putObject_AdditionalHeadersAndQueryStringsCanBeAdded() {
    AwsRequestOverrideConfiguration override = AwsRequestOverrideConfiguration.builder().putHeader("X-Amz-AdditionalHeader", "foo1").putRawQueryParameter("additionalQueryParam", "foo2").build();
    PresignedPutObjectRequest presigned = presigner.presignPutObject(r -> r.signatureDuration(Duration.ofMinutes(5)).putObjectRequest(go -> go.bucket("foo34343434").key("bar").overrideConfiguration(override)));
    assertThat(presigned.isBrowserExecutable()).isFalse();
    assertThat(presigned.signedHeaders()).containsOnlyKeys("host", "x-amz-additionalheader");
    assertThat(presigned.signedHeaders().get("x-amz-additionalheader")).containsExactly("foo1");
    assertThat(presigned.httpRequest().headers()).containsKeys("x-amz-additionalheader");
    assertThat(presigned.httpRequest().rawQueryParameters().get("additionalQueryParam").get(0)).isEqualTo("foo2");
}
Also used : Offset(org.assertj.core.data.Offset) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) RunWith(org.junit.runner.RunWith) AbstractAwsS3V4Signer(software.amazon.awssdk.auth.signer.internal.AbstractAwsS3V4Signer) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) AwsS3V4SignerParams(software.amazon.awssdk.auth.signer.params.AwsS3V4SignerParams) ChecksumConstant(software.amazon.awssdk.services.s3.checksums.ChecksumConstant) NoOpSigner(software.amazon.awssdk.core.signer.NoOpSigner) RequestPayer(software.amazon.awssdk.services.s3.model.RequestPayer) S3Presigner(software.amazon.awssdk.services.s3.presigner.S3Presigner) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SignerConstant(software.amazon.awssdk.auth.signer.internal.SignerConstant) Duration(java.time.Duration) After(org.junit.After) PresignedPutObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest) Aws4SignerRequestParams(software.amazon.awssdk.auth.signer.internal.Aws4SignerRequestParams) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) URI(java.net.URI) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Region(software.amazon.awssdk.regions.Region) Aws4PresignerParams(software.amazon.awssdk.auth.signer.params.Aws4PresignerParams) Before(org.junit.Before) PresignedGetObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest) AwsCredentials(software.amazon.awssdk.auth.credentials.AwsCredentials) Test(org.junit.Test) AwsS3V4Signer(software.amazon.awssdk.auth.signer.AwsS3V4Signer) Instant(java.time.Instant) ZoneId(java.time.ZoneId) AbstractAws4Signer(software.amazon.awssdk.auth.signer.internal.AbstractAws4Signer) Mockito(org.mockito.Mockito) LocalDate(java.time.LocalDate) Clock(java.time.Clock) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) DateUtils(software.amazon.awssdk.utils.DateUtils) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) PresignedPutObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) Test(org.junit.Test)

Aggregations

AwsRequestOverrideConfiguration (software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration)23 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)13 URI (java.net.URI)11 List (java.util.List)11 Generated (software.amazon.awssdk.annotations.Generated)11 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)11 Duration (java.time.Duration)10 Consumer (java.util.function.Consumer)10 ExecutionAttributes (software.amazon.awssdk.core.interceptor.ExecutionAttributes)10 Collections (java.util.Collections)9 RequestOverrideConfiguration (software.amazon.awssdk.core.RequestOverrideConfiguration)9 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)9 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)9 ClientExecutionParams (software.amazon.awssdk.core.client.handler.ClientExecutionParams)9 HttpResponseHandler (software.amazon.awssdk.core.http.HttpResponseHandler)9 Clock (java.time.Clock)8 Instant (java.time.Instant)8 LocalDate (java.time.LocalDate)8 LocalDateTime (java.time.LocalDateTime)8 ZoneId (java.time.ZoneId)8