Search in sources :

Example 91 with PutObjectRequest

use of software.amazon.awssdk.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 92 with PutObjectRequest

use of software.amazon.awssdk.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)

Example 93 with PutObjectRequest

use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project jackrabbit-oak by apache.

the class S3Backend method addMetadataRecord.

@Override
public void addMetadataRecord(File input, String name) throws DataStoreException {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        Upload upload = tmx.upload(s3ReqDecorator.decorate(new PutObjectRequest(bucket, addMetaKeyPrefix(name), input)));
        upload.waitForUploadResult();
    } catch (InterruptedException e) {
        LOG.error("Exception in uploading metadata file {}", new Object[] { input, e });
        throw new DataStoreException("Error in uploading metadata file", e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) Upload(com.amazonaws.services.s3.transfer.Upload) S3Object(com.amazonaws.services.s3.model.S3Object) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 94 with PutObjectRequest

use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project jackrabbit-oak by apache.

the class S3Backend method addMetadataRecord.

public void addMetadataRecord(final InputStream input, final String name) throws DataStoreException {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        Upload upload = tmx.upload(s3ReqDecorator.decorate(new PutObjectRequest(bucket, addMetaKeyPrefix(name), input, new ObjectMetadata())));
        upload.waitForUploadResult();
    } catch (InterruptedException e) {
        LOG.error("Error in uploading", e);
        throw new DataStoreException("Error in uploading", e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) Upload(com.amazonaws.services.s3.transfer.Upload) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 95 with PutObjectRequest

use of software.amazon.awssdk.services.s3.model.PutObjectRequest in project hadoop by apache.

the class S3AFileSystem method newPutObjectRequest.

/**
   * Create a putObject request.
   * Adds the ACL and metadata
   * @param key key of object
   * @param metadata metadata header
   * @param srcfile source file
   * @return the request
   */
public PutObjectRequest newPutObjectRequest(String key, ObjectMetadata metadata, File srcfile) {
    Preconditions.checkNotNull(srcfile);
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, srcfile);
    setOptionalPutRequestParameters(putObjectRequest);
    putObjectRequest.setCannedAcl(cannedACL);
    putObjectRequest.setMetadata(metadata);
    return putObjectRequest;
}
Also used : PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Aggregations

PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)140 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)80 ByteArrayInputStream (java.io.ByteArrayInputStream)63 Test (org.junit.Test)61 File (java.io.File)35 IOException (java.io.IOException)32 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)29 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)23 Upload (com.amazonaws.services.s3.transfer.Upload)23 AmazonClientException (com.amazonaws.AmazonClientException)20 InputStream (java.io.InputStream)18 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)14 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)14 PutObjectRequest (software.amazon.awssdk.services.s3.model.PutObjectRequest)14 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)13 HashMap (java.util.HashMap)12 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)10 AmazonServiceException (com.amazonaws.AmazonServiceException)9 AmazonS3 (com.amazonaws.services.s3.AmazonS3)9 Exchange (org.apache.camel.Exchange)8