use of com.amazonaws.services.s3.model.PutObjectRequest in project camel by apache.
the class AmazonS3ClientMock method putObject.
@SuppressWarnings("resource")
@Override
public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws AmazonClientException, AmazonServiceException {
putObjectRequests.add(putObjectRequest);
S3Object s3Object = new S3Object();
s3Object.setBucketName(putObjectRequest.getBucketName());
s3Object.setKey(putObjectRequest.getKey());
if (putObjectRequest.getFile() != null) {
try {
s3Object.setObjectContent(new FileInputStream(putObjectRequest.getFile()));
} catch (FileNotFoundException e) {
throw new AmazonServiceException("Cannot store the file object.", e);
}
} else {
s3Object.setObjectContent(putObjectRequest.getInputStream());
}
objects.add(s3Object);
PutObjectResult putObjectResult = new PutObjectResult();
putObjectResult.setETag("3a5c8b1ad448bca04584ecb55b836264");
return putObjectResult;
}
use of com.amazonaws.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 com.amazonaws.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 com.amazonaws.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());
}
use of com.amazonaws.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);
}
}
Aggregations