software.amazon.awssdk.services.s3.model.PutObjectRequest Java Examples

The following examples show how to use software.amazon.awssdk.services.s3.model.PutObjectRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyncChecksumValidationInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void afterUnmarshalling_putObjectRequest_shouldValidateChecksum() {
    SdkHttpResponse sdkHttpResponse = getSdkHttpResponseWithChecksumHeader();

    PutObjectResponse response = PutObjectResponse.builder()
                                                  .eTag(VALID_CHECKSUM)
                                                  .build();

    PutObjectRequest putObjectRequest = PutObjectRequest.builder()
                                                        .build();

    SdkHttpRequest sdkHttpRequest = SdkHttpFullRequest.builder()
                                                      .uri(URI.create("http://localhost:8080"))
                                                      .method(SdkHttpMethod.PUT)
                                                      .build();

    Context.AfterUnmarshalling afterUnmarshallingContext =
        InterceptorTestUtils.afterUnmarshallingContext(putObjectRequest, sdkHttpRequest, response, sdkHttpResponse);

    interceptor.afterUnmarshalling(afterUnmarshallingContext, getExecutionAttributesWithChecksum());
}
 
Example #2
Source File: S3AsyncOps.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	S3AsyncClient client = S3AsyncClient.create();
    CompletableFuture<PutObjectResponse> future = client.putObject(
            PutObjectRequest.builder()
                            .bucket(BUCKET)
                            .key(KEY)
                            .build(),
            AsyncRequestBody.fromFile(Paths.get("myfile.in"))
    );
    future.whenComplete((resp, err) -> {
        try {
            if (resp != null) {
                System.out.println("my response: " + resp);
            } else {
                // Handle error
                err.printStackTrace();
            }
        } finally {
            // Lets the application shut down. Only close the client when you are completely done with it.
            client.close();
        }
    });

    future.join();
}
 
Example #3
Source File: EnableChunkedEncodingInterceptor.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) {
    SdkRequest sdkRequest = context.request();

    if (sdkRequest instanceof PutObjectRequest || sdkRequest instanceof UploadPartRequest) {
        S3Configuration serviceConfiguration =
                (S3Configuration) executionAttributes.getAttribute(AwsSignerExecutionAttribute.SERVICE_CONFIG);

        boolean enableChunkedEncoding;
        if (serviceConfiguration != null) {
            enableChunkedEncoding = serviceConfiguration.chunkedEncodingEnabled();
        } else {
            enableChunkedEncoding = true;
        }

        executionAttributes.putAttributeIfAbsent(S3SignerExecutionAttribute.ENABLE_CHUNKED_ENCODING, enableChunkedEncoding);
    }

    return sdkRequest;
}
 
Example #4
Source File: AccessPointsIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void transfer_Succeeds_UsingAccessPoint() {
    StringJoiner apArn = new StringJoiner(":");
    apArn.add("arn").add("aws").add("s3").add("us-west-2").add(accountId).add("accesspoint").add(AP_NAME);

    s3.putObject(PutObjectRequest.builder()
                                 .bucket(apArn.toString())
                                 .key(KEY)
                                 .build(), RequestBody.fromString("helloworld"));

    String objectContent = s3.getObjectAsBytes(GetObjectRequest.builder()
                                                               .bucket(apArn.toString())
                                                               .key(KEY)
                                                               .build()).asUtf8String();

    assertThat(objectContent).isEqualTo("helloworld");
}
 
Example #5
Source File: PutObject.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static String putS3Object(S3Client s3, String bucketName, String objectKey, String objectPath) {

        try {
            //Put a file into the bucket
            PutObjectResponse response = s3.putObject(PutObjectRequest.builder()
                            .bucket(bucketName)
                            .key(objectKey)
                            .build(),
                    RequestBody.fromBytes(getObjectFile(objectPath)));

            return response.eTag();
        } catch (S3Exception | FileNotFoundException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        return "";
    }
 
Example #6
Source File: EndpointAddressInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private void verifyEndpoint(String protocol, String expectedEndpoint,
                            S3Configuration.Builder builder) {
    String bucket = "test-bucket";
    String key = "test-key";
    URI customUri = URI.create(String.format("%s://s3-test.com/%s/%s", protocol, bucket, key));
    URI expectedUri = URI.create(String.format("%s/%s/%s", expectedEndpoint, bucket, key));
    Context.ModifyHttpRequest ctx = context(PutObjectRequest.builder().build(), sdkHttpRequest(customUri));
    ExecutionAttributes executionAttributes = new ExecutionAttributes();
    S3Configuration s3Configuration = builder.build();

    executionAttributes.putAttribute(SERVICE_CONFIG, s3Configuration);
    executionAttributes.putAttribute(AWS_REGION, Region.US_EAST_1);

    SdkHttpRequest sdkHttpFullRequest = interceptor.modifyHttpRequest(ctx, executionAttributes);

    assertThat(sdkHttpFullRequest.getUri()).isEqualTo(expectedUri);
}
 
Example #7
Source File: EnableChunkedEncodingInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void modifyRequest_existingValueInExecutionAttributes_TakesPrecedenceOverClientConfig() {

    boolean configValue = false;
    S3Configuration config = S3Configuration.builder()
            .chunkedEncodingEnabled(configValue)
            .build();

    ExecutionAttributes executionAttributes = new ExecutionAttributes()
            .putAttribute(SERVICE_CONFIG, config)
            .putAttribute(ENABLE_CHUNKED_ENCODING, !configValue);

    interceptor.modifyRequest(context(PutObjectRequest.builder().build()), executionAttributes);

    assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isEqualTo(!configValue);
}
 
Example #8
Source File: S3PinotFS.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@Override
public boolean mkdir(URI uri)
    throws IOException {
  LOGGER.info("mkdir {}", uri);
  try {
    Preconditions.checkNotNull(uri, "uri is null");
    String path = normalizeToDirectoryPrefix(uri);
    // Bucket root directory already exists and cannot be created
    if (path.equals(DELIMITER)) {
      return true;
    }

    PutObjectRequest putObjectRequest = PutObjectRequest.builder().bucket(uri.getHost()).key(path).build();

    PutObjectResponse putObjectResponse = _s3Client.putObject(putObjectRequest, RequestBody.fromBytes(new byte[0]));

    return putObjectResponse.sdkHttpResponse().isSuccessful();
  } catch (Throwable t) {
    throw new IOException(t);
  }
}
 
Example #9
Source File: AsyncChecksumValidationInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void afterUnmarshalling_putObjectRequest_shouldValidateChecksum() {
    SdkHttpResponse sdkHttpResponse = getSdkHttpResponseWithChecksumHeader();

    PutObjectResponse response = PutObjectResponse.builder()
                                                  .eTag(VALID_CHECKSUM)
                                                  .build();

    PutObjectRequest putObjectRequest = PutObjectRequest.builder()
                                                        .build();

    SdkHttpRequest sdkHttpRequest = SdkHttpFullRequest.builder()
                                                      .uri(URI.create("http://localhost:8080"))
                                                      .method(SdkHttpMethod.PUT)
                                                      .build();

    Context.AfterUnmarshalling afterUnmarshallingContext =
        InterceptorTestUtils.afterUnmarshallingContext(putObjectRequest, sdkHttpRequest, response, sdkHttpResponse);

    interceptor.afterUnmarshalling(afterUnmarshallingContext, getExecutionAttributesWithChecksum());
}
 
Example #10
Source File: ChecksumsEnabledValidator.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that checksums should be enabled based on {@link ClientType} and the presence
 * or S3 specific headers.
 *
 * @param expectedClientType - The expected client type for enabling checksums
 * @param executionAttributes - {@link ExecutionAttributes} to determine the actual client type
 * @return If trailing checksums should be enabled for this request.
 */
public static boolean shouldRecordChecksum(SdkRequest sdkRequest,
                                           ClientType expectedClientType,
                                           ExecutionAttributes executionAttributes,
                                           SdkHttpRequest httpRequest) {
    if (!(sdkRequest instanceof PutObjectRequest)) {
        return false;
    }

    ClientType actualClientType = executionAttributes.getAttribute(SdkExecutionAttribute.CLIENT_TYPE);

    if (!expectedClientType.equals(actualClientType)) {
        return false;
    }


    if (hasServerSideEncryptionHeader(httpRequest)) {
        return false;
    }

    return checksumEnabledPerConfig(executionAttributes);
}
 
Example #11
Source File: AmazonMachineLearningIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private static void setUpS3() {
    s3 = S3Client.builder()
                 .credentialsProvider(CREDENTIALS_PROVIDER_CHAIN)
                 .region(Region.US_EAST_1)
                 .build();

    s3.createBucket(CreateBucketRequest.builder().bucket(BUCKET_NAME).build());

    Waiter.run(() -> s3.putObject(PutObjectRequest.builder()
                                                  .bucket(BUCKET_NAME)
                                                  .key(KEY)
                                                  .acl(ObjectCannedACL.PUBLIC_READ)
                                                  .build(),
                                  RequestBody.fromBytes(DATA.getBytes())))
          .ignoringException(NoSuchBucketException.class)
          .orFail();
}
 
Example #12
Source File: AccessPointsIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void transfer_Succeeds_UsingAccessPoint_CrossRegion() {
    S3Client s3DifferentRegion =
        s3ClientBuilder().region(Region.US_EAST_1).serviceConfiguration(c -> c.useArnRegionEnabled(true)).build();

    StringJoiner apArn = new StringJoiner(":");
    apArn.add("arn").add("aws").add("s3").add("us-west-2").add(accountId).add("accesspoint").add(AP_NAME);

    s3DifferentRegion.putObject(PutObjectRequest.builder()
                                                .bucket(apArn.toString())
                                                .key(KEY)
                                                .build(), RequestBody.fromString("helloworld"));

    String objectContent = s3DifferentRegion.getObjectAsBytes(GetObjectRequest.builder()
                                                                              .bucket(apArn.toString())
                                                                              .key(KEY)
                                                                              .build()).asUtf8String();

    assertThat(objectContent).isEqualTo("helloworld");
}
 
Example #13
Source File: AsyncServerSideEncryptionIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void sse_AWSKMS_succeeds() throws FileNotFoundException {
    String key = UUID.randomUUID().toString();
    PutObjectRequest request = PutObjectRequest.builder()
                                               .key(key)
                                               .bucket(BUCKET)
                                               .serverSideEncryption(ServerSideEncryption.AWS_KMS)
                                               .build();

    s3Async.putObject(request, file.toPath()).join();

    GetObjectRequest getObjectRequest = GetObjectRequest.builder()
                                                        .key(key)
                                                        .bucket(BUCKET)
                                                        .build();

    verifyGetResponse(getObjectRequest);
}
 
Example #14
Source File: S3PutObject.java    From piper with Apache License 2.0 6 votes vote down vote up
@Override
public Object handle (TaskExecution aTask) throws Exception {
  
  AmazonS3URI s3Uri = new AmazonS3URI(aTask.getRequiredString("uri"));
  
  String bucketName = s3Uri.getBucket();
  String key = s3Uri.getKey();
  
  S3Client s3 = S3Client.builder().build();
  
  s3.putObject(PutObjectRequest.builder()
                               .bucket(bucketName)
                               .key(key)
                               .acl(aTask.getString("acl")!=null?ObjectCannedACL.fromValue(aTask.getString("acl")):null)
                               .build(), Paths.get(aTask.getRequiredString("filepath")));
  
  return null;
}
 
Example #15
Source File: AsyncServerSideEncryptionIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void sse_onBucket_succeeds() throws FileNotFoundException {
    String key = UUID.randomUUID().toString();

    PutObjectRequest request = PutObjectRequest.builder()
                                               .key(key)
                                               .bucket(BUCKET_WITH_SSE)
                                               .build();

    s3Async.putObject(request, file.toPath()).join();

    GetObjectRequest getObjectRequest = GetObjectRequest.builder()
                                                        .key(key)
                                                        .bucket(BUCKET_WITH_SSE)
                                                        .build();

    verifyGetResponse(getObjectRequest);
}
 
Example #16
Source File: EndpointAddressInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
private void verifyAccesspointArn(String protocol, String accessPointArn, String expectedEndpoint,
                                  Region expectedSigningRegion,
                                  S3Configuration.Builder builder, Region region) {
    String key = "test-key";

    URI customUri = URI.create(String.format("%s://s3-test.com/%s/%s", protocol, urlEncode(accessPointArn), key));
    URI expectedUri = URI.create(String.format("%s/%s", expectedEndpoint, key));
    PutObjectRequest putObjectRequest = PutObjectRequest.builder()
                                                        .bucket(accessPointArn)
                                                        .key(key)
                                                        .build();
    Context.ModifyHttpRequest ctx = context(putObjectRequest, sdkHttpRequest(customUri));
    ExecutionAttributes executionAttributes = new ExecutionAttributes();
    S3Configuration s3Configuration = builder.build();

    executionAttributes.putAttribute(SERVICE_CONFIG, s3Configuration);
    executionAttributes.putAttribute(AWS_REGION, region);
    executionAttributes.putAttribute(SIGNING_REGION, region);

    SdkHttpRequest sdkHttpFullRequest = interceptor.modifyHttpRequest(ctx, executionAttributes);

    assertThat(executionAttributes.getAttribute(SIGNING_REGION))
        .isEqualTo(expectedSigningRegion);
    assertThat(sdkHttpFullRequest.getUri()).isEqualTo(expectedUri);
}
 
Example #17
Source File: S3BundlePersistenceProvider.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
private synchronized void createOrUpdateBundleVersion(final BundlePersistenceContext context, final InputStream contentStream)
        throws BundlePersistenceException {
    final String key = getKey(context.getCoordinate());
    LOGGER.debug("Saving bundle version to S3 in bucket '{}' with key '{}'", new Object[]{s3BucketName, key});

    final PutObjectRequest request = PutObjectRequest.builder()
            .bucket(s3BucketName)
            .key(key)
            .build();

    final RequestBody requestBody = RequestBody.fromInputStream(contentStream, context.getSize());
    try {
        s3Client.putObject(request, requestBody);
        LOGGER.debug("Successfully saved bundle version to S3 bucket '{}' with key '{}'", new Object[]{s3BucketName, key});
    } catch (Exception e) {
        throw new BundlePersistenceException("Error saving bundle version to S3 due to: " + e.getMessage(), e);
    }
}
 
Example #18
Source File: BucketAccelerateIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testAccelerateEndpoint() throws Exception {

    String status = s3.getBucketAccelerateConfiguration(GetBucketAccelerateConfigurationRequest.builder()
                                                                                               .bucket(US_BUCKET_NAME)
                                                                                               .build())
                      .statusAsString();

    if (status == null || !status.equals("Enabled")) {
        enableAccelerateOnBucket();
    }

    // PutObject
    File uploadFile = new RandomTempFile(KEY_NAME, 1000);
    try {
        accelerateClient.putObject(PutObjectRequest.builder()
                                                   .bucket(US_BUCKET_NAME)
                                                   .key(KEY_NAME)
                                                   .build(),
                                   RequestBody.fromFile(uploadFile));
    } catch (Exception e) {
        // We really only need to verify the request is using the accelerate endpoint
    }
}
 
Example #19
Source File: AsyncServerSideEncryptionIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void sse_AES256_succeeds() throws FileNotFoundException {
    String key = UUID.randomUUID().toString();
    PutObjectRequest request = PutObjectRequest.builder()
                                               .key(key)
                                               .bucket(BUCKET)
                                               .serverSideEncryption(AES256)
                                               .build();

    s3Async.putObject(request, file.toPath()).join();

    GetObjectRequest getObjectRequest = GetObjectRequest.builder()
                                                        .key(key)
                                                        .bucket(BUCKET)
                                                        .build();

    verifyGetResponse(getObjectRequest);
}
 
Example #20
Source File: SyncServerSideEncryptionIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void sse_AES256_succeeds() throws Exception {
    String key = UUID.randomUUID().toString();
    PutObjectRequest request = PutObjectRequest.builder()
                                               .key(key)
                                               .bucket(BUCKET)
                                               .serverSideEncryption(AES256)
                                               .build();

    s3.putObject(request, file.toPath());

    GetObjectRequest getObjectRequest = GetObjectRequest.builder()
                                                        .key(key)
                                                        .bucket(BUCKET)
                                                        .build();

    InputStream response = s3.getObject(getObjectRequest);
    SdkAsserts.assertFileEqualsStream(file, response);
}
 
Example #21
Source File: SyncServerSideEncryptionIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void sse_AWSKMS_succeeds() throws Exception {
    String key = UUID.randomUUID().toString();
    PutObjectRequest request = PutObjectRequest.builder()
                                               .key(key)
                                               .bucket(BUCKET)
                                               .serverSideEncryption(ServerSideEncryption.AWS_KMS)
                                               .build();

    s3.putObject(request, file.toPath());

    GetObjectRequest getObjectRequest = GetObjectRequest.builder()
                                                        .key(key)
                                                        .bucket(BUCKET)
                                                        .build();

    String response = s3.getObject(getObjectRequest, ResponseTransformer.toBytes()).asUtf8String();
    SdkAsserts.assertStringEqualsStream(response, new FileInputStream(file));
}
 
Example #22
Source File: SyncServerSideEncryptionIntegrationTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void sse_onBucket_succeeds() throws FileNotFoundException {
    String key = UUID.randomUUID().toString();

    PutObjectRequest request = PutObjectRequest.builder()
                                               .key(key)
                                               .bucket(BUCKET_WITH_SSE)
                                               .build();

    s3.putObject(request, file.toPath());

    GetObjectRequest getObjectRequest = GetObjectRequest.builder()
                                                        .key(key)
                                                        .bucket(BUCKET_WITH_SSE)
                                                        .build();

    String response = s3.getObject(getObjectRequest, ResponseTransformer.toBytes()).asUtf8String();
    SdkAsserts.assertStringEqualsStream(response, new FileInputStream(file));
}
 
Example #23
Source File: SyncChecksumValidationInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void afterUnmarshalling_putObjectRequest_with_SSE_shouldNotValidateChecksum() {
    SdkHttpResponse sdkHttpResponse = getSdkHttpResponseWithChecksumHeader();

    PutObjectResponse response = PutObjectResponse.builder()
                                                  .eTag(INVALID_CHECKSUM)
                                                  .build();

    PutObjectRequest putObjectRequest = PutObjectRequest.builder().build();

    SdkHttpRequest sdkHttpRequest = SdkHttpFullRequest.builder()
                                                      .putHeader(SERVER_SIDE_ENCRYPTION_HEADER, AWS_KMS.toString())
                                                      .putHeader("x-amz-server-side-encryption-aws-kms-key-id", ENABLE_MD5_CHECKSUM_HEADER_VALUE)
                                                      .uri(URI.create("http://localhost:8080"))
                                                      .method(SdkHttpMethod.PUT)
                                                      .build();

    Context.AfterUnmarshalling afterUnmarshallingContext =
        InterceptorTestUtils.afterUnmarshallingContext(putObjectRequest, sdkHttpRequest, response, sdkHttpResponse);

    interceptor.afterUnmarshalling(afterUnmarshallingContext, getExecutionAttributesWithChecksum());
}
 
Example #24
Source File: AsyncChecksumValidationInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void afterUnmarshalling_putObjectRequest_with_SSE_shouldNotValidateChecksum() {
    SdkHttpResponse sdkHttpResponse = getSdkHttpResponseWithChecksumHeader();

    PutObjectResponse response = PutObjectResponse.builder()
                                                  .eTag(INVALID_CHECKSUM)
                                                  .build();

    PutObjectRequest putObjectRequest = PutObjectRequest.builder().build();

    SdkHttpRequest sdkHttpRequest = SdkHttpFullRequest.builder()
                                                      .putHeader(SERVER_SIDE_ENCRYPTION_HEADER, AWS_KMS.toString())
                                                      .putHeader("x-amz-server-side-encryption-aws-kms-key-id", ENABLE_MD5_CHECKSUM_HEADER_VALUE)
                                                      .uri(URI.create("http://localhost:8080"))
                                                      .method(SdkHttpMethod.PUT)
                                                      .build();

    Context.AfterUnmarshalling afterUnmarshallingContext =
        InterceptorTestUtils.afterUnmarshallingContext(putObjectRequest, sdkHttpRequest, response, sdkHttpResponse);

    interceptor.afterUnmarshalling(afterUnmarshallingContext, getExecutionAttributesWithChecksum());
}
 
Example #25
Source File: PutObjectHeaderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void putObjectBytes_headerShouldContainContentType() {
    stubFor(any(urlMatching(".*"))
                .willReturn(response()));
    s3Client.putObject(PutObjectRequest.builder().bucket("test").key("test").build(), RequestBody.fromBytes("Hello World".getBytes()));
    verify(putRequestedFor(anyUrl()).withHeader(CONTENT_TYPE, equalTo(Mimetype.MIMETYPE_OCTET_STREAM)));
}
 
Example #26
Source File: EnableChunkedEncodingInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyRequest_valueOnServiceConfig_TakesPrecedenceOverDefaultEnabled() {

    S3Configuration config = S3Configuration.builder()
            .chunkedEncodingEnabled(false)
            .build();

    ExecutionAttributes executionAttributes = new ExecutionAttributes()
            .putAttribute(SERVICE_CONFIG, config);

    interceptor.modifyRequest(context(PutObjectRequest.builder().build()), executionAttributes);

    assertThat(executionAttributes.getAttribute(ENABLE_CHUNKED_ENCODING)).isEqualTo(false);
}
 
Example #27
Source File: ExceptionTranslationInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void otherRequest_shouldNotThrowException() {
    S3Exception s3Exception = create404S3Exception();
    Context.FailedExecution failedExecution = getFailedExecution(s3Exception,
                                                                 PutObjectRequest.builder().build());
    assertThat(interceptor.modifyException(failedExecution, new ExecutionAttributes())).isEqualTo(s3Exception);
}
 
Example #28
Source File: CreateMultipartUploadRequestInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void nonCreateMultipartRequest_shouldNotModifyHttpContent() {
    Context.ModifyHttpRequest modifyHttpRequest =
        InterceptorTestUtils.modifyHttpRequestContext(PutObjectRequest.builder().build());
    Optional<RequestBody> requestBody =
        interceptor.modifyHttpContent(modifyHttpRequest,
                                      new ExecutionAttributes());
    assertThat(modifyHttpRequest.requestBody().get()).isEqualTo(requestBody.get());
}
 
Example #29
Source File: PutObjectInterceptorTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void modifyHttpRequest_setsExpect100Continue_whenSdkRequestIsPutObject() {

    final SdkHttpRequest modifiedRequest = interceptor.modifyHttpRequest(modifyHttpRequestContext(PutObjectRequest.builder().build()),
                                                                         new ExecutionAttributes());

    assertThat(modifiedRequest.firstMatchingHeader("Expect")).hasValue("100-continue");
}
 
Example #30
Source File: PutObjectHeaderTest.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Test
public void putObjectWithContentTypeHeader_shouldNotOverrideContentTypeInRawConfig() throws IOException {
    stubFor(any(urlMatching(".*"))
                .willReturn(response()));
    String contentType = "hello world";

    putObjectRequest = (PutObjectRequest) putObjectRequest.toBuilder().overrideConfiguration(b -> b.putHeader(CONTENT_TYPE, contentType)).build();
    s3Client.putObject(putObjectRequest, RequestBody.fromString("test"));
    verify(putRequestedFor(anyUrl()).withHeader(CONTENT_TYPE, equalTo(contentType)));
}