use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project gradle by gradle.
the class S3Client method put.
public void put(InputStream inputStream, Long contentLength, URI destination) {
checkRequiredJigsawModuleIsOnPath();
try {
S3RegionalResource s3RegionalResource = new S3RegionalResource(destination);
String bucketName = s3RegionalResource.getBucketName();
String s3BucketKey = s3RegionalResource.getKey();
configureClient(s3RegionalResource);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(contentLength);
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, s3BucketKey, inputStream, objectMetadata);
LOGGER.debug("Attempting to put resource:[{}] into s3 bucket [{}]", s3BucketKey, bucketName);
amazonS3Client.putObject(putObjectRequest);
} catch (AmazonClientException e) {
throw ResourceExceptions.putFailed(destination, e);
}
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project camel by apache.
the class S3Producer method processSingleOp.
public void processSingleOp(final Exchange exchange) throws Exception {
ObjectMetadata objectMetadata = determineMetadata(exchange);
File filePayload = null;
InputStream is = null;
Object obj = exchange.getIn().getMandatoryBody();
PutObjectRequest putObjectRequest = null;
// Need to check if the message body is WrappedFile
if (obj instanceof WrappedFile) {
obj = ((WrappedFile<?>) obj).getFile();
}
if (obj instanceof File) {
filePayload = (File) obj;
is = new FileInputStream(filePayload);
} else {
is = exchange.getIn().getMandatoryBody(InputStream.class);
}
putObjectRequest = new PutObjectRequest(getConfiguration().getBucketName(), determineKey(exchange), is, objectMetadata);
String storageClass = determineStorageClass(exchange);
if (storageClass != null) {
putObjectRequest.setStorageClass(storageClass);
}
String cannedAcl = exchange.getIn().getHeader(S3Constants.CANNED_ACL, String.class);
if (cannedAcl != null) {
CannedAccessControlList objectAcl = CannedAccessControlList.valueOf(cannedAcl);
putObjectRequest.setCannedAcl(objectAcl);
}
AccessControlList acl = exchange.getIn().getHeader(S3Constants.ACL, AccessControlList.class);
if (acl != null) {
// note: if cannedacl and acl are both specified the last one will be used. refer to
// PutObjectRequest#setAccessControlList for more details
putObjectRequest.setAccessControlList(acl);
}
LOG.trace("Put object [{}] from exchange [{}]...", putObjectRequest, exchange);
PutObjectResult putObjectResult = getEndpoint().getS3Client().putObject(putObjectRequest);
LOG.trace("Received result [{}]", putObjectResult);
Message message = getMessageForResponse(exchange);
message.setHeader(S3Constants.E_TAG, putObjectResult.getETag());
if (putObjectResult.getVersionId() != null) {
message.setHeader(S3Constants.VERSION_ID, putObjectResult.getVersionId());
}
if (getConfiguration().isDeleteAfterWrite() && filePayload != null) {
// close streams
IOHelper.close(putObjectRequest.getInputStream());
IOHelper.close(is);
FileUtil.deleteFile(filePayload);
}
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project camel by apache.
the class S3ComponentNonExistingBucketTest method sendCustomHeaderValues.
@Test
public void sendCustomHeaderValues() throws Exception {
result.expectedMessageCount(1);
final Date now = new Date();
final Map<String, String> s3Headers = new HashMap<String, String>();
s3Headers.put("x-aws-s3-header", "extra");
Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(S3Constants.STORAGE_CLASS, "STANDARD");
exchange.getIn().setHeader(S3Constants.KEY, "CamelUnitTest");
exchange.getIn().setHeader(S3Constants.CONTENT_LENGTH, 2L);
exchange.getIn().setHeader(S3Constants.CONTENT_TYPE, "text/html");
exchange.getIn().setHeader(S3Constants.CACHE_CONTROL, "no-cache");
exchange.getIn().setHeader(S3Constants.CONTENT_DISPOSITION, "attachment;");
exchange.getIn().setHeader(S3Constants.CONTENT_ENCODING, "gzip");
exchange.getIn().setHeader(S3Constants.CONTENT_MD5, "TWF");
exchange.getIn().setHeader(S3Constants.LAST_MODIFIED, now);
exchange.getIn().setHeader(S3Constants.S3_HEADERS, s3Headers);
exchange.getIn().setBody("This is my bucket content.");
}
});
assertMockEndpointsSatisfied();
assertResultExchange(result.getExchanges().get(0));
PutObjectRequest putObjectRequest = client.putObjectRequests.get(0);
assertEquals("STANDARD", putObjectRequest.getStorageClass());
assertEquals("nonExistingBucket", putObjectRequest.getBucketName());
assertEquals(2L, putObjectRequest.getMetadata().getContentLength());
assertEquals("text/html", putObjectRequest.getMetadata().getContentType());
assertEquals("no-cache", putObjectRequest.getMetadata().getCacheControl());
assertEquals("attachment;", putObjectRequest.getMetadata().getContentDisposition());
assertEquals("gzip", putObjectRequest.getMetadata().getContentEncoding());
assertEquals("TWF", putObjectRequest.getMetadata().getContentMD5());
assertEquals(now, putObjectRequest.getMetadata().getLastModified());
assertEquals("extra", putObjectRequest.getMetadata().getRawMetadataValue("x-aws-s3-header"));
assertResponseMessage(exchange.getIn());
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project camel by apache.
the class S3ComponentExistingBucketTest method sendIn.
@Test
public void sendIn() throws Exception {
result.expectedMessageCount(1);
Exchange exchange = template.send("direct:start", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(S3Constants.KEY, "CamelUnitTest");
exchange.getIn().setBody("This is my bucket content.");
}
});
assertMockEndpointsSatisfied();
assertResultExchange(result.getExchanges().get(0));
PutObjectRequest putObjectRequest = client.putObjectRequests.get(0);
assertEquals("REDUCED_REDUNDANCY", putObjectRequest.getStorageClass());
assertEquals("mycamelbucket", putObjectRequest.getBucketName());
assertResponseMessage(exchange.getIn());
}
use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project camel by apache.
the class S3ComponentFileDeleteTest method sendFile.
@Test
@Override
public void sendFile() throws Exception {
result.expectedMessageCount(1);
Exchange exchange = templateDelete.send("direct:startDelete", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(S3Constants.KEY, "CamelUnitTest");
exchange.getIn().setBody(testFile);
}
});
assertMockEndpointsSatisfied();
assertResultExchange(result.getExchanges().get(0), true);
PutObjectRequest putObjectRequest = client.putObjectRequests.get(0);
assertEquals(getCamelBucket(), putObjectRequest.getBucketName());
assertResponseMessage(exchange.getIn());
assertFileNotExists(testFile.getAbsolutePath());
}
Aggregations