Search in sources :

Example 26 with PutObjectRequest

use of com.amazonaws.services.s3.model.PutObjectRequest in project camel by apache.

the class S3ComponentExistingBucketTest method sendCustomHeaderValues.

@Test
public void sendCustomHeaderValues() throws Exception {
    result.expectedMessageCount(1);
    final Date now = new Date();
    final Map<String, String> userMetadata = new HashMap<String, String>();
    userMetadata.put("CamelName", "Camel");
    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.USER_METADATA, userMetadata);
            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("mycamelbucket", 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(userMetadata, putObjectRequest.getMetadata().getUserMetadata());
    assertEquals("extra", putObjectRequest.getMetadata().getRawMetadataValue("x-aws-s3-header"));
    assertResponseMessage(exchange.getIn());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) HashMap(java.util.HashMap) Date(java.util.Date) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 27 with PutObjectRequest

use of com.amazonaws.services.s3.model.PutObjectRequest in project camel by apache.

the class S3ComponentExistingBucketTest method sendInOut.

@Test
public void sendInOut() throws Exception {
    result.expectedMessageCount(1);
    Exchange exchange = template.send("direct:start", ExchangePattern.InOut, 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.getOut());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 28 with PutObjectRequest

use of com.amazonaws.services.s3.model.PutObjectRequest in project camel by apache.

the class S3ComponentFileTest method sendFile.

@Test
public void sendFile() throws Exception {
    result.expectedMessageCount(1);
    Exchange exchange = templateKeep.send("direct:startKeep", 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());
    assertFileExists(testFile.getAbsolutePath());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 29 with PutObjectRequest

use of com.amazonaws.services.s3.model.PutObjectRequest in project camel by apache.

the class S3ComponentNonExistingBucketTest method sendInOnly.

@Test
public void sendInOnly() 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("nonExistingBucket", putObjectRequest.getBucketName());
    assertResponseMessage(exchange.getIn());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Example 30 with PutObjectRequest

use of com.amazonaws.services.s3.model.PutObjectRequest in project camel by apache.

the class S3ComponentNonExistingBucketTest method sendInOut.

@Test
public void sendInOut() throws Exception {
    result.expectedMessageCount(1);
    Exchange exchange = template.send("direct:start", ExchangePattern.InOut, 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("nonExistingBucket", putObjectRequest.getBucketName());
    assertResponseMessage(exchange.getOut());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) Test(org.junit.Test)

Aggregations

PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)33 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)21 Upload (com.amazonaws.services.s3.transfer.Upload)11 AmazonClientException (com.amazonaws.AmazonClientException)10 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)8 Exchange (org.apache.camel.Exchange)8 Processor (org.apache.camel.Processor)8 Test (org.junit.Test)8 InputStream (java.io.InputStream)7 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)7 File (java.io.File)6 IOException (java.io.IOException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 AmazonServiceException (com.amazonaws.AmazonServiceException)4 S3Object (com.amazonaws.services.s3.model.S3Object)4 Date (java.util.Date)4 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)3 Copy (com.amazonaws.services.s3.transfer.Copy)3 FileInputStream (java.io.FileInputStream)3 HashMap (java.util.HashMap)3