@Test(expectedExceptions = IllegalArgumentException.class) public void testOver5GBIsBad() { S3Object object = injector.getInstance(S3Object.Factory.class).create(null); Payload payload = Payloads.newStringPayload(""); payload.getContentMetadata().setContentLength(5368709120000L); object.setPayload(payload); object.getMetadata().setKey("foo"); HttpRequest request = HttpRequest.builder().method("PUT").endpoint("http: BindS3ObjectMetadataToRequest binder = injector.getInstance(BindS3ObjectMetadataToRequest.class); binder.bindToRequest(request, object); }
@SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof S3Object, "this binder is only valid for S3Object!, not %s", input); checkNotNull(request, "request"); S3Object s3Object = S3Object.class.cast(input); checkArgument(s3Object.getMetadata().getKey() != null, "s3Object.getMetadata().getKey() must be set!"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() != null, "contentLength must be set, streaming not supported"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() <= 5L * 1024 * 1024 * 1024, "maximum size for put object is 5GB"); StorageClass storageClass = s3Object.getMetadata().getStorageClass(); if (storageClass != StorageClass.STANDARD) { request = (R) request.toBuilder() .replaceHeader("x-amz-storage-class", storageClass.toString()) .build(); } request = metadataPrefixer.bindToRequest(request, s3Object.getMetadata().getUserMetadata()); return request; }
BindS3ObjectMetadataToRequest implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof S3Object, "this binder is only valid for S3Object!, not %s", input); checkNotNull(request, "request"); S3Object s3Object = S3Object.class.cast(input); checkArgument(s3Object.getMetadata().getKey() != null, "s3Object.getMetadata().getKey() must be set!"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() != null, "contentLength must be set, streaming not supported"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() <= 5L * 1024 * 1024 * 1024, "maximum size for put object is 5GB"); StorageClass storageClass = s3Object.getMetadata().getStorageClass(); if (storageClass != StorageClass.STANDARD) { request = (R) request.toBuilder() .replaceHeader("x-amz-storage-class", storageClass.toString()) .build(); } request = metadataPrefixer.bindToRequest(request, s3Object.getMetadata().getUserMetadata()); return request; } }
BindS3ObjectMetadataToRequest implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof S3Object, "this binder is only valid for S3Object!, not %s", input); checkNotNull(request, "request"); S3Object s3Object = S3Object.class.cast(input); checkArgument(s3Object.getMetadata().getKey() != null, "s3Object.getMetadata().getKey() must be set!"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() != null, "contentLength must be set, streaming not supported"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() <= 5L * 1024 * 1024 * 1024, "maximum size for put object is 5GB"); StorageClass storageClass = s3Object.getMetadata().getStorageClass(); if (storageClass != StorageClass.STANDARD) { request = (R) request.toBuilder() .replaceHeader("x-amz-storage-class", storageClass.toString()) .build(); } request = metadataPrefixer.bindToRequest(request, s3Object.getMetadata().getUserMetadata()); return request; } @Inject  BindS3ObjectMetadataToRequest(BindMapToHeadersWithPrefix metadataPrefixer); }
BindS3ObjectMetadataToRequest implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof S3Object, "this binder is only valid for S3Object!, not %s", input); checkNotNull(request, "request"); S3Object s3Object = S3Object.class.cast(input); checkArgument(s3Object.getMetadata().getKey() != null, "s3Object.getMetadata().getKey() must be set!"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() != null, "contentLength must be set, streaming not supported"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() <= 5L * 1024 * 1024 * 1024, "maximum size for put object is 5GB"); StorageClass storageClass = s3Object.getMetadata().getStorageClass(); if (storageClass != StorageClass.STANDARD) { request = (R) request.toBuilder() .replaceHeader("x-amz-storage-class", storageClass.toString()) .build(); } request = metadataPrefixer.bindToRequest(request, s3Object.getMetadata().getUserMetadata()); return request; } @Inject  BindS3ObjectMetadataToRequest(BindMapToHeadersWithPrefix metadataPrefixer); @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input); }
BindS3ObjectMetadataToRequest implements Binder { @SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(checkNotNull(input, "input") instanceof S3Object, "this binder is only valid for S3Object!, not %s", input); checkNotNull(request, "request"); S3Object s3Object = S3Object.class.cast(input); checkArgument(s3Object.getMetadata().getKey() != null, "s3Object.getMetadata().getKey() must be set!"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() != null, "contentLength must be set, streaming not supported"); checkArgument(s3Object.getPayload().getContentMetadata().getContentLength() <= 5L * 1024 * 1024 * 1024, "maximum size for put object is 5GB"); StorageClass storageClass = s3Object.getMetadata().getStorageClass(); if (storageClass != StorageClass.STANDARD) { request = (R) request.toBuilder() .replaceHeader("x-amz-storage-class", storageClass.toString()) .build(); } request = metadataPrefixer.bindToRequest(request, s3Object.getMetadata().getUserMetadata()); return request; } @Inject  BindS3ObjectMetadataToRequest(BindMapToHeadersWithPrefix metadataPrefixer); @SuppressWarnings("unchecked") @Override R bindToRequest(R request, Object input);  }