Search in sources :

Example 1 with StreamingInputOperationRequestMarshaller

use of software.amazon.awssdk.services.query.transform.StreamingInputOperationRequestMarshaller in project aws-sdk-java-v2 by aws.

the class DefaultQueryAsyncClient method streamingInputOperation.

/**
 * Some operation with a streaming input
 *
 * @param streamingInputOperationRequest
 * @param requestBody
 *        Functional interface that can be implemented to produce the request content in a non-blocking manner. The
 *        size of the content is expected to be known up front. See {@link AsyncRequestBody} for specific details on
 *        implementing this interface as well as links to precanned implementations for common scenarios like
 *        uploading from a file. The service documentation for the request content is as follows 'This be a stream'
 * @return A Java Future containing the result of the StreamingInputOperation 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>QueryException Base class for all service exceptions. Unknown exceptions will be thrown as an
 *         instance of this type.</li>
 *         </ul>
 * @sample QueryAsyncClient.StreamingInputOperation
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/query-service-2010-05-08/StreamingInputOperation"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public CompletableFuture<StreamingInputOperationResponse> streamingInputOperation(StreamingInputOperationRequest streamingInputOperationRequest, AsyncRequestBody requestBody) {
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation");
        if (!isSignerOverridden(clientConfiguration)) {
            streamingInputOperationRequest = applySignerOverride(streamingInputOperationRequest, AsyncAws4Signer.create());
        }
        HttpResponseHandler<StreamingInputOperationResponse> responseHandler = protocolFactory.createResponseHandler(StreamingInputOperationResponse::builder);
        HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
        CompletableFuture<StreamingInputOperationResponse> executeFuture = clientHandler.execute(new ClientExecutionParams<StreamingInputOperationRequest, StreamingInputOperationResponse>().withOperationName("StreamingInputOperation").withMarshaller(AsyncStreamingRequestMarshaller.builder().delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)).asyncRequestBody(requestBody).build()).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector).withAsyncRequestBody(requestBody).withInput(streamingInputOperationRequest));
        CompletableFuture<StreamingInputOperationResponse> whenCompleteFuture = null;
        whenCompleteFuture = executeFuture.whenComplete((r, e) -> {
            metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
        });
        return CompletableFutureUtils.forwardExceptionTo(whenCompleteFuture, executeFuture);
    } catch (Throwable t) {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
        return CompletableFutureUtils.failedFuture(t);
    }
}
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) ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) StreamingInputOperationRequestMarshaller(software.amazon.awssdk.services.query.transform.StreamingInputOperationRequestMarshaller) StreamingInputOperationResponse(software.amazon.awssdk.services.query.model.StreamingInputOperationResponse) 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)

Example 2 with StreamingInputOperationRequestMarshaller

use of software.amazon.awssdk.services.query.transform.StreamingInputOperationRequestMarshaller in project aws-sdk-java-v2 by aws.

the class DefaultQueryClient method streamingInputOperation.

/**
 * Some operation with a streaming input
 *
 * @param streamingInputOperationRequest
 * @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 'This be a stream'
 * @return Result of the StreamingInputOperation operation returned by the service.
 * @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 QueryException
 *         Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
 * @sample QueryClient.StreamingInputOperation
 * @see <a href="https://docs.aws.amazon.com/goto/WebAPI/query-service-2010-05-08/StreamingInputOperation"
 *      target="_top">AWS API Documentation</a>
 */
@Override
public StreamingInputOperationResponse streamingInputOperation(StreamingInputOperationRequest streamingInputOperationRequest, RequestBody requestBody) throws AwsServiceException, SdkClientException, QueryException {
    HttpResponseHandler<StreamingInputOperationResponse> responseHandler = protocolFactory.createResponseHandler(StreamingInputOperationResponse::builder);
    HttpResponseHandler<AwsServiceException> errorResponseHandler = protocolFactory.createErrorResponseHandler();
    List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, streamingInputOperationRequest.overrideConfiguration().orElse(null));
    MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector.create("ApiCall");
    try {
        apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Query Service");
        apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation");
        return clientHandler.execute(new ClientExecutionParams<StreamingInputOperationRequest, StreamingInputOperationResponse>().withOperationName("StreamingInputOperation").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(streamingInputOperationRequest).withMetricCollector(apiCallMetricCollector).withRequestBody(requestBody).withMarshaller(StreamingRequestMarshaller.builder().delegateMarshaller(new StreamingInputOperationRequestMarshaller(protocolFactory)).requestBody(requestBody).build()));
    } finally {
        metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
    }
}
Also used : ClientExecutionParams(software.amazon.awssdk.core.client.handler.ClientExecutionParams) StreamingInputOperationRequestMarshaller(software.amazon.awssdk.services.query.transform.StreamingInputOperationRequestMarshaller) StreamingInputOperationResponse(software.amazon.awssdk.services.query.model.StreamingInputOperationResponse) 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)

Aggregations

AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)2 ClientExecutionParams (software.amazon.awssdk.core.client.handler.ClientExecutionParams)2 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)2 MetricPublisher (software.amazon.awssdk.metrics.MetricPublisher)2 NoOpMetricCollector (software.amazon.awssdk.metrics.NoOpMetricCollector)2 StreamingInputOperationResponse (software.amazon.awssdk.services.query.model.StreamingInputOperationResponse)2 StreamingInputOperationRequestMarshaller (software.amazon.awssdk.services.query.transform.StreamingInputOperationRequestMarshaller)2 Collections (java.util.Collections)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Consumer (java.util.function.Consumer)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Generated (software.amazon.awssdk.annotations.Generated)1 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)1 AsyncAws4Signer (software.amazon.awssdk.auth.signer.AsyncAws4Signer)1 AwsRequestOverrideConfiguration (software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration)1 AwsAsyncClientHandler (software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler)1 RequestOverrideConfiguration (software.amazon.awssdk.core.RequestOverrideConfiguration)1