Search in sources :

Example 11 with JsonOperationMetadata

use of software.amazon.awssdk.protocols.json.JsonOperationMetadata in project aws-sdk-java-v2 by aws.

the class DefaultJsonClient method putOperationWithChecksum.

/**
 * Invokes the PutOperationWithChecksum operation.
 *
 * @param putOperationWithChecksumRequest
 * @param requestBody
 *        The content to send to the service. A {@link RequestBody} can be created using one of several factory
 *        methods for various sources of data. For example, to create a request body from a file you can do the
 *        following.
 *
 *        <pre>
 * {@code RequestBody.fromFile(new File("myfile.txt"))}
 * </pre>
 *
 *        See documentation in {@link RequestBody} for additional details and which sources of data are supported.
 *        The service documentation for the request content is as follows '
 *        <p>
 *        Object data.
 *        </p>
 *        '
 * @param responseTransformer
 *        Functional interface for processing the streamed response content. The unmarshalled
 *        PutOperationWithChecksumResponse and an InputStream to the response content are provided as parameters to
 *        the callback. The callback may return a transformed type which will be the return value of this method.
 *        See {@link software.amazon.awssdk.core.sync.ResponseTransformer} for details on implementing this
 *        interface and for links to pre-canned implementations for common scenarios like downloading to a file. The
 *        service documentation for the response content is as follows '
 *        <p>
 *        Object data.
 *        </p>
 *        '.
 * @return The transformed result of the ResponseTransformer.
 * @throws SdkException
 *         Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
 *         catch all scenarios.
 * @throws SdkClientException
 *         If any client side error occurs such as an IO related failure, failure to get credentials, etc.
 * @throws JsonException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample JsonClient.PutOperationWithChecksum
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/PutOperationWithChecksum"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public <ReturnT> ReturnT putOperationWithChecksum(PutOperationWithChecksumRequest putOperationWithChecksumRequest, RequestBody requestBody, ResponseTransformer<PutOperationWithChecksumResponse, ReturnT> responseTransformer) throws AwsServiceException, SdkClientException, JsonException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true).isPayloadJson(false).build();
    HttpResponseHandler<PutOperationWithChecksumResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, PutOperationWithChecksumResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, putOperationWithChecksumRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "PutOperationWithChecksum");
        return clientHandler.execute(new ClientExecutionParams<PutOperationWithChecksumRequest, PutOperationWithChecksumResponse>().withOperationName("PutOperationWithChecksum").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(putOperationWithChecksumRequest).withMetricCollector(apiCallMetricCollector).putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM, HttpChecksum.builder().requestChecksumRequired(false).requestValidationMode(putOperationWithChecksumRequest.checksumModeAsString()).responseAlgorithms("CRC32C", "CRC32", "SHA1", "SHA256").isRequestStreaming(true).build()).withRequestBody(requestBody).withMarshaller(StreamingRequestMarshaller.builder().delegateMarshaller(new PutOperationWithChecksumRequestMarshaller(protocolFactory)).requestBody(requestBody).build()), responseTransformer);
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : PutOperationWithChecksumRequestMarshaller(software.amazon.awssdk.services.json.transform.PutOperationWithChecksumRequestMarshaller) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) PutOperationWithChecksumResponse(software.amazon.awssdk.services.json.model.PutOperationWithChecksumResponse) PutOperationWithChecksumRequest(software.amazon.awssdk.services.json.model.PutOperationWithChecksumRequest)

Example 12 with JsonOperationMetadata

use of software.amazon.awssdk.protocols.json.JsonOperationMetadata in project aws-sdk-java-v2 by aws.

the class DefaultJsonClient method aPostOperationWithOutput.

/**
 * <p>
 * Performs a post operation to the query service and has modelled output
 * </p>
 *
 * @param aPostOperationWithOutputRequest
 * @return Result of the APostOperationWithOutput operation returned by the service.
 * @throws InvalidInputException
 *         The request was rejected because an invalid or out-of-range value was supplied for an input parameter.
 * @throws SdkException
 *         Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
 *         catch all scenarios.
 * @throws SdkClientException
 *         If any client side error occurs such as an IO related failure, failure to get credentials, etc.
 * @throws JsonException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample JsonClient.APostOperationWithOutput
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/APostOperationWithOutput"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public APostOperationWithOutputResponse aPostOperationWithOutput(APostOperationWithOutputRequest aPostOperationWithOutputRequest) throws InvalidInputException, AwsServiceException, SdkClientException, JsonException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
    HttpResponseHandler<APostOperationWithOutputResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, APostOperationWithOutputResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationWithOutputRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperationWithOutput");
        return clientHandler.execute(new ClientExecutionParams<APostOperationWithOutputRequest, APostOperationWithOutputResponse>().withOperationName("APostOperationWithOutput").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(aPostOperationWithOutputRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new APostOperationWithOutputRequestMarshaller(protocolFactory)));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : APostOperationWithOutputRequest(software.amazon.awssdk.services.json.model.APostOperationWithOutputRequest) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) APostOperationWithOutputRequestMarshaller(software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller) APostOperationWithOutputResponse(software.amazon.awssdk.services.json.model.APostOperationWithOutputResponse)

Example 13 with JsonOperationMetadata

use of software.amazon.awssdk.protocols.json.JsonOperationMetadata in project aws-sdk-java-v2 by aws.

the class DefaultJsonClient method aPostOperation.

/**
 * <p>
 * Performs a post operation to the query service and has no output
 * </p>
 *
 * @param aPostOperationRequest
 * @return Result of the APostOperation operation returned by the service.
 * @throws InvalidInputException
 *         The request was rejected because an invalid or out-of-range value was supplied for an input parameter.
 * @throws SdkException
 *         Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
 *         catch all scenarios.
 * @throws SdkClientException
 *         If any client side error occurs such as an IO related failure, failure to get credentials, etc.
 * @throws JsonException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample JsonClient.APostOperation
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/APostOperation" target="_top">AWS
 *      API Documentation</a>
 */
@Override
public APostOperationResponse aPostOperation(APostOperationRequest aPostOperationRequest) throws InvalidInputException, AwsServiceException, SdkClientException, JsonException {
    JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
    HttpResponseHandler<APostOperationResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, APostOperationResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, aPostOperationRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "APostOperation");
        String hostPrefix = "{StringMember}-foo.";
        HostnameValidator.validateHostnameCompliant(aPostOperationRequest.stringMember(), "StringMember", "aPostOperationRequest");
        String resolvedHostExpression = String.format("%s-foo.", aPostOperationRequest.stringMember());
        return clientHandler.execute(new ClientExecutionParams<APostOperationRequest, APostOperationResponse>().withOperationName("APostOperation").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).hostPrefixExpression(resolvedHostExpression).withInput(aPostOperationRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new APostOperationRequestMarshaller(protocolFactory)));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : APostOperationResponse(software.amazon.awssdk.services.json.model.APostOperationResponse) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) APostOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata)

Example 14 with JsonOperationMetadata

use of software.amazon.awssdk.protocols.json.JsonOperationMetadata in project aws-sdk-java-v2 by aws.

the class DefaultJsonAsyncClient method operationWithChecksumRequired.

/**
 * Invokes the OperationWithChecksumRequired operation asynchronously.
 *
 * @param operationWithChecksumRequiredRequest
 * @return A Java Future containing the result of the OperationWithChecksumRequired 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>JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance
 *         of this type.</li>
 *         </ul>
 * @sample JsonAsyncClient.OperationWithChecksumRequired
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/OperationWithChecksumRequired"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public CompletableFuture<OperationWithChecksumRequiredResponse> operationWithChecksumRequired(OperationWithChecksumRequiredRequest operationWithChecksumRequiredRequest) {
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, operationWithChecksumRequiredRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Json Service");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "OperationWithChecksumRequired");
        JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
        HttpResponseHandler<OperationWithChecksumRequiredResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, OperationWithChecksumRequiredResponse::builder);
        HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
        CompletableFuture<OperationWithChecksumRequiredResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<OperationWithChecksumRequiredRequest, OperationWithChecksumRequiredResponse>().withOperationName("OperationWithChecksumRequired").withMarshaller(new OperationWithChecksumRequiredRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector).putExecutionAttribute(SdkInternalExecutionAttribute.HTTP_CHECKSUM_REQUIRED, HttpChecksumRequired.create()).withInput(operationWithChecksumRequiredRequest));
        CompletableFuture<OperationWithChecksumRequiredResponse> 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 : ExceptionMetadata(software.amazon.awssdk.protocols.core.ExceptionMetadata) AwsAsyncClientHandler(software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler) StreamingInputOutputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingInputOutputOperationRequestMarshaller) EventStreamOperationResponseHandler(software.amazon.awssdk.services.json.model.EventStreamOperationResponseHandler) AsyncStreamingRequestMarshaller(software.amazon.awssdk.core.runtime.transform.AsyncStreamingRequestMarshaller) AsyncResponseTransformer(software.amazon.awssdk.core.async.AsyncResponseTransformer) InputEventStreamTwo(software.amazon.awssdk.services.json.model.InputEventStreamTwo) StreamingInputOperationRequest(software.amazon.awssdk.services.json.model.StreamingInputOperationRequest) AsyncClientHandler(software.amazon.awssdk.core.client.handler.AsyncClientHandler) PaginatedOperationWithResultKeyResponse(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) PaginatedOperationWithResultKeyPublisher(software.amazon.awssdk.services.json.paginators.PaginatedOperationWithResultKeyPublisher) EventStreamOperationWithOnlyInputRequestMarshaller(software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyInputRequestMarshaller) APostOperationWithOutputResponse(software.amazon.awssdk.services.json.model.APostOperationWithOutputResponse) EventStream(software.amazon.awssdk.services.json.model.EventStream) APostOperationRequest(software.amazon.awssdk.services.json.model.APostOperationRequest) PaginatedOperationWithoutResultKeyPublisher(software.amazon.awssdk.services.json.paginators.PaginatedOperationWithoutResultKeyPublisher) PaginatedOperationWithoutResultKeyResponse(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyResponse) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) AsyncAws4Signer(software.amazon.awssdk.auth.signer.AsyncAws4Signer) SdkAdvancedAsyncClientOption(software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption) APostOperationWithOutputRequestMarshaller(software.amazon.awssdk.services.json.transform.APostOperationWithOutputRequestMarshaller) EventStreamOperationRequest(software.amazon.awssdk.services.json.model.EventStreamOperationRequest) HttpResponseHandler(software.amazon.awssdk.core.http.HttpResponseHandler) Generated(software.amazon.awssdk.annotations.Generated) AsyncResponseTransformerUtils(software.amazon.awssdk.core.async.AsyncResponseTransformerUtils) PaginatedOperationWithResultKeyRequestMarshaller(software.amazon.awssdk.services.json.transform.PaginatedOperationWithResultKeyRequestMarshaller) PaginatedOperationWithoutResultKeyRequestMarshaller(software.amazon.awssdk.services.json.transform.PaginatedOperationWithoutResultKeyRequestMarshaller) OperationWithChecksumRequiredResponse(software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse) EventStreamTaggedUnionJsonMarshaller(software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionJsonMarshaller) VoidSdkResponse(software.amazon.awssdk.core.protocol.VoidSdkResponse) CompletableFutureUtils(software.amazon.awssdk.utils.CompletableFutureUtils) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) VersionInfo(software.amazon.awssdk.core.util.VersionInfo) PaginatedOperationWithResultKeyRequest(software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest) CoreMetric(software.amazon.awssdk.core.metrics.CoreMetric) BaseAwsJsonProtocolFactory(software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory) RequestOverrideConfiguration(software.amazon.awssdk.core.RequestOverrideConfiguration) EventStreamOperationWithOnlyOutputResponse(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputResponse) StreamingOutputOperationRequest(software.amazon.awssdk.services.json.model.StreamingOutputOperationRequest) InputEventTwoMarshaller(software.amazon.awssdk.services.json.transform.InputEventTwoMarshaller) SdkInternalExecutionAttribute(software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Executor(java.util.concurrent.Executor) Publisher(org.reactivestreams.Publisher) APostOperationWithOutputRequest(software.amazon.awssdk.services.json.model.APostOperationWithOutputRequest) EventStreamOperationWithOnlyInputResponse(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputResponse) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) GetWithoutRequiredMembersResponse(software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersResponse) DefaultInputEventTwo(software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventTwo) GetWithoutRequiredMembersRequestMarshaller(software.amazon.awssdk.services.json.transform.GetWithoutRequiredMembersRequestMarshaller) LoggerFactory(org.slf4j.LoggerFactory) StreamingInputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingInputOperationRequestMarshaller) ByteBuffer(java.nio.ByteBuffer) JsonException(software.amazon.awssdk.services.json.model.JsonException) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) DefaultInputEvent(software.amazon.awssdk.services.json.model.inputeventstream.DefaultInputEvent) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) EventStreamOperationWithOnlyInputRequest(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyInputRequest) ApiName(software.amazon.awssdk.core.ApiName) GetWithoutRequiredMembersRequest(software.amazon.awssdk.services.json.model.GetWithoutRequiredMembersRequest) SdkClientOption(software.amazon.awssdk.core.client.config.SdkClientOption) HostnameValidator(software.amazon.awssdk.utils.HostnameValidator) StreamingOutputOperationResponse(software.amazon.awssdk.services.json.model.StreamingOutputOperationResponse) APostOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.APostOperationRequestMarshaller) StreamingInputOperationResponse(software.amazon.awssdk.services.json.model.StreamingInputOperationResponse) EventStreamOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.EventStreamOperationRequestMarshaller) DefaultInputEventOne(software.amazon.awssdk.services.json.model.inputeventstreamtwo.DefaultInputEventOne) SdkPojoBuilder(software.amazon.awssdk.core.SdkPojoBuilder) InputEventMarshaller(software.amazon.awssdk.services.json.transform.InputEventMarshaller) OperationWithChecksumRequiredRequest(software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredRequest) InputEventStream(software.amazon.awssdk.services.json.model.InputEventStream) List(java.util.List) APostOperationResponse(software.amazon.awssdk.services.json.model.APostOperationResponse) StreamingInputOutputOperationRequest(software.amazon.awssdk.services.json.model.StreamingInputOutputOperationRequest) AttachHttpMetadataResponseHandler(software.amazon.awssdk.core.client.handler.AttachHttpMetadataResponseHandler) Aws4UnsignedPayloadSigner(software.amazon.awssdk.auth.signer.Aws4UnsignedPayloadSigner) JsonRequest(software.amazon.awssdk.services.json.model.JsonRequest) EventStreamOperationWithOnlyOutputRequestMarshaller(software.amazon.awssdk.services.json.transform.EventStreamOperationWithOnlyOutputRequestMarshaller) OperationWithChecksumRequiredRequestMarshaller(software.amazon.awssdk.services.json.transform.OperationWithChecksumRequiredRequestMarshaller) AwsRequestOverrideConfiguration(software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration) Signer(software.amazon.awssdk.core.signer.Signer) AwsJsonProtocol(software.amazon.awssdk.protocols.json.AwsJsonProtocol) EventStreamAsyncResponseTransformer(software.amazon.awssdk.awscore.eventstream.EventStreamAsyncResponseTransformer) EventStreamTaggedUnionPojoSupplier(software.amazon.awssdk.awscore.eventstream.EventStreamTaggedUnionPojoSupplier) CompletableFuture(java.util.concurrent.CompletableFuture) HttpChecksumRequired(software.amazon.awssdk.core.interceptor.trait.HttpChecksumRequired) InvalidInputException(software.amazon.awssdk.services.json.model.InvalidInputException) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) PaginatedOperationWithoutResultKeyRequest(software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest) Logger(org.slf4j.Logger) EventStreamOperationWithOnlyOutputRequest(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputRequest) Pair(software.amazon.awssdk.utils.Pair) SdkPublisher(software.amazon.awssdk.core.async.SdkPublisher) EventStreamAws4Signer(software.amazon.awssdk.auth.signer.EventStreamAws4Signer) Consumer(java.util.function.Consumer) StreamingOutputOperationRequestMarshaller(software.amazon.awssdk.services.json.transform.StreamingOutputOperationRequestMarshaller) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) EventStreamOperationWithOnlyOutputResponseHandler(software.amazon.awssdk.services.json.model.EventStreamOperationWithOnlyOutputResponseHandler) StreamingInputOutputOperationResponse(software.amazon.awssdk.services.json.model.StreamingInputOutputOperationResponse) AwsClientHandlerUtils(software.amazon.awssdk.awscore.client.handler.AwsClientHandlerUtils) EventStreamOperationResponse(software.amazon.awssdk.services.json.model.EventStreamOperationResponse) SdkResponse(software.amazon.awssdk.core.SdkResponse) AwsJsonProtocolFactory(software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory) FunctionalUtils.runAndLogError(software.amazon.awssdk.utils.FunctionalUtils.runAndLogError) Collections(java.util.Collections) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) OperationWithChecksumRequiredResponse(software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse) JsonOperationMetadata(software.amazon.awssdk.protocols.json.JsonOperationMetadata) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) NoOpMetricCollector(software.amazon.awssdk.metrics.NoOpMetricCollector) OperationWithChecksumRequiredRequestMarshaller(software.amazon.awssdk.services.json.transform.OperationWithChecksumRequiredRequestMarshaller)

Example 15 with JsonOperationMetadata

use of software.amazon.awssdk.protocols.json.JsonOperationMetadata in project aws-sdk-java-v2 by aws.

the class DefaultEndpointDiscoveryTestAsyncClient method testDiscoveryIdentifiersRequired.

/**
 * Invokes the TestDiscoveryIdentifiersRequired operation asynchronously.
 *
 * @param testDiscoveryIdentifiersRequiredRequest
 * @return A Java Future containing the result of the TestDiscoveryIdentifiersRequired 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.TestDiscoveryIdentifiersRequired
 */
@Override
public CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> testDiscoveryIdentifiersRequired(TestDiscoveryIdentifiersRequiredRequest testDiscoveryIdentifiersRequiredRequest) {
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "AwsEndpointDiscoveryTest");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TestDiscoveryIdentifiersRequired");
        JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
        HttpResponseHandler<TestDiscoveryIdentifiersRequiredResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, TestDiscoveryIdentifiersRequiredResponse::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 = testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().flatMap(AwsRequestOverrideConfiguration::credentialsProvider).orElseGet(() -> clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER)).resolveCredentials().accessKeyId();
            EndpointDiscoveryRequest endpointDiscoveryRequest = EndpointDiscoveryRequest.builder().required(true).defaultEndpoint(clientConfiguration.option(SdkClientOption.ENDPOINT)).overrideConfiguration(testDiscoveryIdentifiersRequiredRequest.overrideConfiguration().orElse(null)).build();
            cachedEndpoint = endpointDiscoveryCache.get(key, endpointDiscoveryRequest);
        }
        CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<TestDiscoveryIdentifiersRequiredRequest, TestDiscoveryIdentifiersRequiredResponse>().withOperationName("TestDiscoveryIdentifiersRequired").withMarshaller(new TestDiscoveryIdentifiersRequiredRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector).discoveredEndpoint(cachedEndpoint).withInput(testDiscoveryIdentifiersRequiredRequest));
        CompletableFuture<TestDiscoveryIdentifiersRequiredResponse> 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) TestDiscoveryIdentifiersRequiredRequestMarshaller(software.amazon.awssdk.services.endpointdiscoverytest.transform.TestDiscoveryIdentifiersRequiredRequestMarshaller) MetricPublisher(software.amazon.awssdk.metrics.MetricPublisher) TestDiscoveryIdentifiersRequiredResponse(software.amazon.awssdk.services.endpointdiscoverytest.model.TestDiscoveryIdentifiersRequiredResponse) 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)

Aggregations

AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)35 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)35 MetricPublisher (software.amazon.awssdk.metrics.MetricPublisher)35 NoOpMetricCollector (software.amazon.awssdk.metrics.NoOpMetricCollector)35 JsonOperationMetadata (software.amazon.awssdk.protocols.json.JsonOperationMetadata)35 ClientExecutionParams (software.amazon.awssdk.core.client.handler.ClientExecutionParams)27 Collections (java.util.Collections)19 List (java.util.List)19 CompletableFuture (java.util.concurrent.CompletableFuture)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19 Generated (software.amazon.awssdk.annotations.Generated)19 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)19 AwsAsyncClientHandler (software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler)19 RequestOverrideConfiguration (software.amazon.awssdk.core.RequestOverrideConfiguration)19 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)19 SdkClientOption (software.amazon.awssdk.core.client.config.SdkClientOption)19 AsyncClientHandler (software.amazon.awssdk.core.client.handler.AsyncClientHandler)19 HttpResponseHandler (software.amazon.awssdk.core.http.HttpResponseHandler)19 CoreMetric (software.amazon.awssdk.core.metrics.CoreMetric)19