use of software.amazon.awssdk.services.json.transform.StreamingOutputOperationRequestMarshaller in project aws-sdk-java-v2 by aws.
the class DefaultJsonAsyncClient method streamingOutputOperation.
/**
* Some operation with a streaming output
*
* @param streamingOutputOperationRequest
* @param asyncResponseTransformer
* The response transformer for processing the streaming response in a non-blocking manner. See
* {@link AsyncResponseTransformer} for details on how this callback should be implemented and for links to
* precanned implementations for common scenarios like downloading to a file. The service documentation for
* the response content is as follows 'This be a stream'.
* @return A future to the transformed result of the AsyncResponseTransformer.<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.StreamingOutputOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/StreamingOutputOperation"
* target="_top">AWS API Documentation</a>
*/
@Override
public <ReturnT> CompletableFuture<ReturnT> streamingOutputOperation(StreamingOutputOperationRequest streamingOutputOperationRequest, AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT> asyncResponseTransformer) {
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest.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, "StreamingOutputOperation");
Pair<AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT>, CompletableFuture<Void>> pair = AsyncResponseTransformerUtils.wrapWithEndOfStreamFuture(asyncResponseTransformer);
asyncResponseTransformer = pair.left();
CompletableFuture<Void> endOfStreamFuture = pair.right();
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true).isPayloadJson(false).build();
HttpResponseHandler<StreamingOutputOperationResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, StreamingOutputOperationResponse::builder);
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
CompletableFuture<ReturnT> executeFuture = clientHandler.execute(new ClientExecutionParams<StreamingOutputOperationRequest, StreamingOutputOperationResponse>().withOperationName("StreamingOutputOperation").withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)).withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withMetricCollector(apiCallMetricCollector).withInput(streamingOutputOperationRequest), asyncResponseTransformer);
AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT> finalAsyncResponseTransformer = asyncResponseTransformer;
CompletableFuture<ReturnT> whenCompleted = executeFuture.whenComplete((r, e) -> {
if (e != null) {
runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", () -> finalAsyncResponseTransformer.exceptionOccurred(e));
}
endOfStreamFuture.whenComplete((r2, e2) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
AsyncResponseTransformer<StreamingOutputOperationResponse, ReturnT> finalAsyncResponseTransformer = asyncResponseTransformer;
runAndLogError(log, "Exception thrown in exceptionOccurred callback, ignoring", () -> finalAsyncResponseTransformer.exceptionOccurred(t));
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
use of software.amazon.awssdk.services.json.transform.StreamingOutputOperationRequestMarshaller in project aws-sdk-java-v2 by aws.
the class DefaultJsonClient method streamingOutputOperation.
/**
* Some operation with a streaming output
*
* @param streamingOutputOperationRequest
* @param responseTransformer
* Functional interface for processing the streamed response content. The unmarshalled
* StreamingOutputOperationResponse 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 'This be a stream'.
* @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.StreamingOutputOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/StreamingOutputOperation"
* target="_top">AWS API Documentation</a>
*/
@Override
public <ReturnT> ReturnT streamingOutputOperation(StreamingOutputOperationRequest streamingOutputOperationRequest, ResponseTransformer<StreamingOutputOperationResponse, ReturnT> responseTransformer) throws AwsServiceException, SdkClientException, JsonException {
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(true).isPayloadJson(false).build();
HttpResponseHandler<StreamingOutputOperationResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, StreamingOutputOperationResponse::builder);
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
List<MetricPublisher> metricPublishers = resolveMetricPublishers(clientConfiguration, streamingOutputOperationRequest.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, "StreamingOutputOperation");
return clientHandler.execute(new ClientExecutionParams<StreamingOutputOperationRequest, StreamingOutputOperationResponse>().withOperationName("StreamingOutputOperation").withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler).withInput(streamingOutputOperationRequest).withMetricCollector(apiCallMetricCollector).withMarshaller(new StreamingOutputOperationRequestMarshaller(protocolFactory)), responseTransformer);
} finally {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
}
}
Aggregations