Search in sources :

Example 21 with AsyncRequestBody

use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.

the class UploadRequestTest method bodyEqualsGivenBody.

@Test
public void bodyEqualsGivenBody() {
    AsyncRequestBody requestBody = AsyncRequestBody.fromString("foo");
    UploadRequest request = UploadRequest.builder().putObjectRequest(b -> b.bucket("bucket").key("key")).requestBody(requestBody).build();
    assertThat(request.requestBody()).isSameAs(requestBody);
}
Also used : AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) Test(org.junit.Test)

Example 22 with AsyncRequestBody

use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.

the class ContentLengthMismatchTest method contentShorterThanRequestBodyLengthFails.

@Test
public void contentShorterThanRequestBodyLengthFails() {
    String bucket = "Example-Bucket";
    String key = "Example-Object";
    S3AsyncClient s3Client = getAsyncClientBuilder().build();
    AsyncRequestBody requestBody = new AsyncRequestBody() {

        @Override
        public Optional<Long> contentLength() {
            return Optional.of(2L);
        }

        @Override
        public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
            AsyncRequestBody.fromString("A").subscribe(subscriber);
        }
    };
    assertThatThrownBy(() -> s3Client.putObject(r -> r.bucket(bucket).key(key), requestBody).get(10, TimeUnit.SECONDS)).isInstanceOf(ExecutionException.class).hasMessageContaining("content-length");
}
Also used : Subscriber(org.reactivestreams.Subscriber) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) ExecutionException(java.util.concurrent.ExecutionException) ByteBuffer(java.nio.ByteBuffer) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.Test)

Example 23 with AsyncRequestBody

use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.

the class ContentLengthMismatchTest method checksumDoesNotExceedAsyncRequestBodyLengthForPuts.

@Test
public void checksumDoesNotExceedAsyncRequestBodyLengthForPuts() {
    String bucket = "Example-Bucket";
    String key = "Example-Object";
    String content = "Hello, World!";
    String eTag = "65A8E27D8879283831B664BD8B7F0AD4";
    stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withHeader("ETag", eTag)));
    S3AsyncClient s3Client = getAsyncClientBuilder().build();
    PutObjectResponse response = s3Client.putObject(r -> r.bucket(bucket).key(key), new AsyncRequestBody() {

        @Override
        public Optional<Long> contentLength() {
            return Optional.of((long) content.length());
        }

        @Override
        public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
            AsyncRequestBody.fromString(content + " Extra stuff!").subscribe(subscriber);
        }
    }).join();
    verify(putRequestedFor(anyUrl()).withRequestBody(equalTo(content)));
    assertThat(response.eTag()).isEqualTo(eTag);
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) WireMock.any(com.github.tomakehurst.wiremock.client.WireMock.any) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) ByteBuffer(java.nio.ByteBuffer) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) URI(java.net.URI) Region(software.amazon.awssdk.regions.Region) Subscriber(org.reactivestreams.Subscriber) PutObjectResponse(software.amazon.awssdk.services.s3.model.PutObjectResponse) WireMock.equalTo(com.github.tomakehurst.wiremock.client.WireMock.equalTo) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Test(org.junit.Test) WireMock.verify(com.github.tomakehurst.wiremock.client.WireMock.verify) WireMock.putRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Rule(org.junit.Rule) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) Optional(java.util.Optional) WireMock.anyUrl(com.github.tomakehurst.wiremock.client.WireMock.anyUrl) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Subscriber(org.reactivestreams.Subscriber) PutObjectResponse(software.amazon.awssdk.services.s3.model.PutObjectResponse) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) ByteBuffer(java.nio.ByteBuffer) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) Test(org.junit.Test)

Example 24 with AsyncRequestBody

use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.

the class AsyncChecksumValidationInterceptorTest method modifyAsyncHttpContent_putObjectRequestChecksumEnabled_shouldWrapChecksumRequestBody.

@Test
public void modifyAsyncHttpContent_putObjectRequestChecksumEnabled_shouldWrapChecksumRequestBody() {
    ExecutionAttributes executionAttributes = getExecutionAttributes();
    Context.ModifyHttpRequest modifyHttpRequest = InterceptorTestUtils.modifyHttpRequestContext(PutObjectRequest.builder().build());
    Optional<AsyncRequestBody> asyncRequestBody = interceptor.modifyAsyncHttpContent(modifyHttpRequest, executionAttributes);
    assertThat(asyncRequestBody.isPresent()).isTrue();
    assertThat(executionAttributes.getAttribute(CHECKSUM)).isNotNull();
    assertThat(asyncRequestBody.get()).isExactlyInstanceOf(ChecksumCalculatingAsyncRequestBody.class);
}
Also used : InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext) Context(software.amazon.awssdk.core.interceptor.Context) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) ChecksumCalculatingAsyncRequestBody(software.amazon.awssdk.services.s3.checksums.ChecksumCalculatingAsyncRequestBody) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) Test(org.junit.jupiter.api.Test)

Example 25 with AsyncRequestBody

use of software.amazon.awssdk.core.async.AsyncRequestBody in project aws-sdk-java-v2 by aws.

the class AsyncChecksumValidationInterceptorTest method modifyAsyncHttpContent_nonPutObjectRequest_shouldNotModify.

@Test
public void modifyAsyncHttpContent_nonPutObjectRequest_shouldNotModify() {
    ExecutionAttributes executionAttributes = getExecutionAttributes();
    Context.ModifyHttpRequest modifyHttpRequest = InterceptorTestUtils.modifyHttpRequestContext(GetObjectRequest.builder().build());
    Optional<AsyncRequestBody> asyncRequestBody = interceptor.modifyAsyncHttpContent(modifyHttpRequest, executionAttributes);
    assertThat(asyncRequestBody).isEqualTo(modifyHttpRequest.asyncRequestBody());
}
Also used : InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext) Context(software.amazon.awssdk.core.interceptor.Context) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) ChecksumCalculatingAsyncRequestBody(software.amazon.awssdk.services.s3.checksums.ChecksumCalculatingAsyncRequestBody) AsyncRequestBody(software.amazon.awssdk.core.async.AsyncRequestBody) Test(org.junit.jupiter.api.Test)

Aggregations

AsyncRequestBody (software.amazon.awssdk.core.async.AsyncRequestBody)51 ByteBuffer (java.nio.ByteBuffer)25 Test (org.junit.jupiter.api.Test)24 List (java.util.List)17 Test (org.junit.Test)13 Subscriber (org.reactivestreams.Subscriber)12 CompletableFuture (java.util.concurrent.CompletableFuture)11 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)11 Publisher (org.reactivestreams.Publisher)9 Flowable (io.reactivex.Flowable)8 Consumer (java.util.function.Consumer)8 AsyncAws4Signer (software.amazon.awssdk.auth.signer.AsyncAws4Signer)8 AsyncResponseTransformer (software.amazon.awssdk.core.async.AsyncResponseTransformer)8 Signer (software.amazon.awssdk.core.signer.Signer)8 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)8 Collections (java.util.Collections)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 Generated (software.amazon.awssdk.annotations.Generated)7 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)7