Search in sources :

Example 16 with S3AsyncClient

use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.

the class SelectObjectContentTest method runSimpleQuery.

private static CompletableFuture<Void> runSimpleQuery(S3AsyncClient s3, SelectObjectContentResponseHandler handler) {
    InputSerialization inputSerialization = InputSerialization.builder().csv(CSVInput.builder().build()).compressionType(CompressionType.NONE).build();
    OutputSerialization outputSerialization = OutputSerialization.builder().csv(CSVOutput.builder().build()).build();
    SelectObjectContentRequest select = SelectObjectContentRequest.builder().bucket("test-bucket").key("test-key").expression("test-query").expressionType(ExpressionType.SQL).inputSerialization(inputSerialization).outputSerialization(outputSerialization).build();
    return s3.selectObjectContent(select, handler);
}
Also used : SelectObjectContentRequest(software.amazon.awssdk.services.s3.model.SelectObjectContentRequest) InputSerialization(software.amazon.awssdk.services.s3.model.InputSerialization) OutputSerialization(software.amazon.awssdk.services.s3.model.OutputSerialization)

Example 17 with S3AsyncClient

use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.

the class CompleteMultipartUploadFunctionalTest method completeMultipartUpload_asyncClient_errorInResponseBody_correctType.

@Test
public void completeMultipartUpload_asyncClient_errorInResponseBody_correctType() {
    String bucket = "Example-Bucket";
    String key = "Example-Object";
    String xmlResponseBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Error>\n" + "<Code>InternalError</Code>\n" + "<Message>We encountered an internal error. Please try again.</Message>\n" + "<RequestId>656c76696e6727732072657175657374</RequestId>\n" + "<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>\n" + "</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);
}
Also used : CompletionException(java.util.concurrent.CompletionException) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.Test)

Example 18 with S3AsyncClient

use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.

the class CompleteMultipartUploadFunctionalTest method completeMultipartUpload_asyncClient_completeResponse.

@Test
public void completeMultipartUpload_asyncClient_completeResponse() {
    String location = "http://Example-Bucket.s3.amazonaws.com/Example-Object";
    String bucket = "Example-Bucket";
    String key = "Example-Object";
    String eTag = "\"3858f62230ac3c915f300c664312c11f-9\"";
    String xmlResponseBody = String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<CompleteMultipartUploadResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">\n" + "<Location>%s</Location>\n" + "<Bucket>%s</Bucket>\n" + "<Key>%s</Key>\n" + "<ETag>%s</ETag>\n" + "</CompleteMultipartUploadResult>", location, bucket, key, eTag);
    stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(xmlResponseBody)));
    S3AsyncClient s3Client = getAsyncClientBuilder().build();
    CompleteMultipartUploadResponse response = s3Client.completeMultipartUpload(r -> r.bucket(bucket).key(key).uploadId("upload-id")).join();
    assertThat(response.location()).isEqualTo(location);
    assertThat(response.bucket()).isEqualTo(bucket);
    assertThat(response.key()).isEqualTo(key);
    assertThat(response.eTag()).isEqualTo(eTag);
}
Also used : S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) S3Client(software.amazon.awssdk.services.s3.S3Client) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WireMock.any(com.github.tomakehurst.wiremock.client.WireMock.any) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) S3ClientBuilder(software.amazon.awssdk.services.s3.S3ClientBuilder) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) WireMock.anyUrl(com.github.tomakehurst.wiremock.client.WireMock.anyUrl) URI(java.net.URI) CompleteMultipartUploadResponse(software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) CompleteMultipartUploadResponse(software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.Test)

Example 19 with S3AsyncClient

use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.

the class CompleteMultipartUploadFunctionalTest method completeMultipartUpload_asyncClient_errorInResponseBody_correctCode.

@Test
public void completeMultipartUpload_asyncClient_errorInResponseBody_correctCode() {
    String bucket = "Example-Bucket";
    String key = "Example-Object";
    String xmlResponseBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Error>\n" + "<Code>CustomError</Code>\n" + "<Message>We encountered an internal error. Please try again.</Message>\n" + "<RequestId>656c76696e6727732072657175657374</RequestId>\n" + "<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>\n" + "</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()).satisfies(e -> {
        S3Exception s3Exception = (S3Exception) e.getCause();
        assertThat(s3Exception.awsErrorDetails().errorCode()).isEqualTo("CustomError");
    });
}
Also used : S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) S3Client(software.amazon.awssdk.services.s3.S3Client) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WireMock.any(com.github.tomakehurst.wiremock.client.WireMock.any) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) S3ClientBuilder(software.amazon.awssdk.services.s3.S3ClientBuilder) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) WireMock.anyUrl(com.github.tomakehurst.wiremock.client.WireMock.anyUrl) URI(java.net.URI) CompleteMultipartUploadResponse(software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.Test)

Example 20 with S3AsyncClient

use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk-java-v2 by aws.

the class CompleteMultipartUploadFunctionalTest method completeMultipartUpload_asyncClient_errorInResponseBody_correctMessage.

@Test
public void completeMultipartUpload_asyncClient_errorInResponseBody_correctMessage() {
    String bucket = "Example-Bucket";
    String key = "Example-Object";
    String xmlResponseBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<Error>\n" + "<Code>CustomError</Code>\n" + "<Message>Foo bar</Message>\n" + "<RequestId>656c76696e6727732072657175657374</RequestId>\n" + "<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>\n" + "</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()).satisfies(e -> {
        S3Exception s3Exception = (S3Exception) e.getCause();
        assertThat(s3Exception.awsErrorDetails().errorMessage()).isEqualTo("Foo bar");
    });
}
Also used : S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) S3Client(software.amazon.awssdk.services.s3.S3Client) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WireMock.any(com.github.tomakehurst.wiremock.client.WireMock.any) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) Rule(org.junit.Rule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) S3ClientBuilder(software.amazon.awssdk.services.s3.S3ClientBuilder) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) WireMock.anyUrl(com.github.tomakehurst.wiremock.client.WireMock.anyUrl) URI(java.net.URI) CompleteMultipartUploadResponse(software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.Test)

Aggregations

S3AsyncClient (software.amazon.awssdk.services.s3.S3AsyncClient)28 Test (org.junit.Test)18 S3AsyncClientBuilder (software.amazon.awssdk.services.s3.S3AsyncClientBuilder)16 Region (software.amazon.awssdk.regions.Region)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)10 WireMock.any (com.github.tomakehurst.wiremock.client.WireMock.any)10 WireMock.anyUrl (com.github.tomakehurst.wiremock.client.WireMock.anyUrl)10 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)10 URI (java.net.URI)10 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)10 StaticCredentialsProvider (software.amazon.awssdk.auth.credentials.StaticCredentialsProvider)10 S3Client (software.amazon.awssdk.services.s3.S3Client)8 S3ClientBuilder (software.amazon.awssdk.services.s3.S3ClientBuilder)8 Collectors (java.util.stream.Collectors)7 GetObjectResponse (software.amazon.awssdk.services.s3.model.GetObjectResponse)7 WireMockRule (com.github.tomakehurst.wiremock.junit.WireMockRule)6 AsyncResponseTransformer (software.amazon.awssdk.core.async.AsyncResponseTransformer)6 InputStream (java.io.InputStream)5 ByteBuffer (java.nio.ByteBuffer)5