use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class GetObjectAsyncIntegrationTest method customResponseHandler_InterceptorRecievesResponsePojo.
@Test
public void customResponseHandler_InterceptorRecievesResponsePojo() throws Exception {
final CompletableFuture<String> cf = new CompletableFuture<>();
try (S3AsyncClient asyncWithInterceptor = createClientWithInterceptor(new AssertingExecutionInterceptor())) {
String result = asyncWithInterceptor.getObject(getObjectRequest, new AsyncResponseTransformer<GetObjectResponse, String>() {
@Override
public CompletableFuture<String> prepare() {
return cf;
}
@Override
public void onResponse(GetObjectResponse response) {
// POJO returned by modifyResponse should be delivered to the AsyncResponseTransformer
assertThat(response.metadata()).hasEntrySatisfying("x-amz-assert", s -> assertThat(s).isEqualTo("injected-value"));
}
@Override
public void onStream(SdkPublisher<ByteBuffer> publisher) {
publisher.subscribe(new SimpleSubscriber(b -> {
}) {
@Override
public void onComplete() {
super.onComplete();
cf.complete("result");
}
});
}
@Override
public void exceptionOccurred(Throwable throwable) {
cf.completeExceptionally(throwable);
}
}).join();
assertThat(result).isEqualTo("result");
}
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method async_getObject_with_validation_enabled_no_http_checksum.
@Test
public void async_getObject_with_validation_enabled_no_http_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(EXAMPLE_RESPONSE_BODY)));
S3AsyncClient s3Client = getAsyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
String response = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key").checksumMode(ChecksumMode.ENABLED), AsyncResponseTransformer.toBytes()).join().asUtf8String();
assertThat(response).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isEqualTo(ChecksumValidation.CHECKSUM_ALGORITHM_NOT_FOUND);
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isNull();
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class GetObjectWithChecksumTest method async_getObject_with_validation_not_enabled_incorrect_http_checksum.
@Test
public void async_getObject_with_validation_not_enabled_incorrect_http_checksum(WireMockRuntimeInfo wm) {
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("x-amz-checksum-crc32", "incorrect").withBody(EXAMPLE_RESPONSE_BODY)));
S3AsyncClient s3Client = getAsyncClientBuilder(wm).overrideConfiguration(o -> o.addExecutionInterceptor(captureChecksumValidationInterceptor)).build();
String response = s3Client.getObject(r -> r.bucket(EXAMPLE_BUCKET).key("key"), AsyncResponseTransformer.toBytes()).join().asUtf8String();
assertThat(response).isEqualTo("Hello world");
assertThat(captureChecksumValidationInterceptor.responseValidation()).isNull();
assertThat(captureChecksumValidationInterceptor.validationAlgorithm()).isNull();
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.
the class CompleteMultipartUploadFunctionalTest method completeMultipartUpload_asyncClient_errorInResponseBody_invalidErrorXml.
@Test
public void completeMultipartUpload_asyncClient_errorInResponseBody_invalidErrorXml() {
String bucket = "Example-Bucket";
String key = "Example-Object";
String xmlResponseBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Error>\n" + "<SomethingWeird></SomethingWeird>" + "</Error>";
stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(xmlResponseBody)));
S3AsyncClient s3Client = getAsyncClientBuilder().build();
assertThatThrownBy(() -> s3Client.completeMultipartUpload(r -> r.bucket(bucket).key(key).uploadId("upload-id")).join()).isInstanceOf(CompletionException.class).hasCauseInstanceOf(S3Exception.class);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project flink by splunk.
the class AWSServicesTestUtils method listBucketObjects.
public static List<S3Object> listBucketObjects(S3AsyncClient s3, String bucketName) throws ExecutionException, InterruptedException {
ListObjectsRequest listObjects = ListObjectsRequest.builder().bucket(bucketName).build();
CompletableFuture<ListObjectsResponse> res = s3.listObjects(listObjects);
return res.get().contents();
}
Aggregations