use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class BaseEventStreamAsyncAws4Signer method transformRequestProvider.
@Override
protected AsyncRequestBody transformRequestProvider(String headerSignature, Aws4SignerRequestParams signerRequestParams, Aws4SignerParams signerParams, AsyncRequestBody asyncRequestBody) {
/**
* Concat trailing empty frame to publisher
*/
Publisher<ByteBuffer> publisherWithTrailingEmptyFrame = appendEmptyFrame(asyncRequestBody);
/**
* Map publisher with signing function
*/
Publisher<ByteBuffer> publisherWithSignedFrame = transformRequestBodyPublisher(publisherWithTrailingEmptyFrame, headerSignature, signerParams.awsCredentials(), signerRequestParams);
AsyncRequestBody transformedRequestBody = AsyncRequestBody.fromPublisher(publisherWithSignedFrame);
return new SigningRequestBodyProvider(transformedRequestBody);
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class S3CrtRequestBodyStreamAdapterTest method getRequestData_publisherThrows_wrapsExceptionIfNotRuntimeException.
@Test
public void getRequestData_publisherThrows_wrapsExceptionIfNotRuntimeException() {
Publisher<ByteBuffer> errorPublisher = Flowable.error(new IOException("Some I/O error happened"));
AsyncRequestBody requestBody = AsyncRequestBody.fromPublisher(errorPublisher);
S3CrtRequestBodyStreamAdapter adapter = new S3CrtRequestBodyStreamAdapter(requestBody);
assertThatThrownBy(() -> adapter.sendRequestBody(ByteBuffer.allocate(16))).isInstanceOf(RuntimeException.class).hasCauseInstanceOf(IOException.class);
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class S3CrtRequestBodyStreamAdapterTest method getRequestData_publisherThrows_surfacesException.
@Test
public void getRequestData_publisherThrows_surfacesException() {
Publisher<ByteBuffer> errorPublisher = Flowable.error(new RuntimeException("Something wrong happened"));
AsyncRequestBody requestBody = AsyncRequestBody.fromPublisher(errorPublisher);
S3CrtRequestBodyStreamAdapter adapter = new S3CrtRequestBodyStreamAdapter(requestBody);
assertThatThrownBy(() -> adapter.sendRequestBody(ByteBuffer.allocate(16))).isInstanceOf(RuntimeException.class).hasMessageContaining("Something wrong happened");
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class DefaultJsonAsyncClient 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>JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance
* of this type.</li>
* </ul>
* @sample JsonAsyncClient.StreamingInputOperation
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-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, "Json Service");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "StreamingInputOperation");
if (!isSignerOverridden(clientConfiguration)) {
streamingInputOperationRequest = applySignerOverride(streamingInputOperationRequest, AsyncAws4Signer.create());
}
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false).isPayloadJson(true).build();
HttpResponseHandler<StreamingInputOperationResponse> responseHandler = protocolFactory.createResponseHandler(operationMetadata, StreamingInputOperationResponse::builder);
HttpResponseHandler<AwsServiceException> errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata);
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> 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);
}
}
use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.
the class S3CrtClientPutObjectIntegrationTest method putObject_fileRequestBody_objectSentCorrectly.
@Test
public void putObject_fileRequestBody_objectSentCorrectly() throws Exception {
AsyncRequestBody body = AsyncRequestBody.fromFile(testFile.toPath());
s3Crt.putObject(r -> r.bucket(TEST_BUCKET).key(TEST_KEY), body).join();
ResponseInputStream<GetObjectResponse> objContent = S3IntegrationTestBase.s3.getObject(r -> r.bucket(TEST_BUCKET).key(TEST_KEY), ResponseTransformer.toInputStream());
byte[] expectedSum = ChecksumUtils.computeCheckSum(Files.newInputStream(testFile.toPath()));
Assertions.assertThat(ChecksumUtils.computeCheckSum(objContent)).isEqualTo(expectedSum);
}
Aggregations