List of usage examples for com.amazonaws.services.s3.model ObjectMetadata getStorageClass
public String getStorageClass()
From source file:io.konig.camel.aws.s3.DeleteObjectEndpoint.java
License:Apache License
public Exchange createExchange(ExchangePattern pattern, final S3Object s3Object) { LOG.trace("Getting object with key [{}] from bucket [{}]...", s3Object.getKey(), s3Object.getBucketName()); ObjectMetadata objectMetadata = s3Object.getObjectMetadata(); LOG.trace("Got object [{}]", s3Object); Exchange exchange = super.createExchange(pattern); Message message = exchange.getIn();/*from w w w. jav a2s .co m*/ if (configuration.isIncludeBody()) { message.setBody(s3Object.getObjectContent()); } else { message.setBody(null); } message.setHeader(S3Constants.KEY, s3Object.getKey()); message.setHeader(S3Constants.BUCKET_NAME, s3Object.getBucketName()); message.setHeader(S3Constants.E_TAG, objectMetadata.getETag()); message.setHeader(S3Constants.LAST_MODIFIED, objectMetadata.getLastModified()); message.setHeader(S3Constants.VERSION_ID, objectMetadata.getVersionId()); message.setHeader(S3Constants.CONTENT_TYPE, objectMetadata.getContentType()); message.setHeader(S3Constants.CONTENT_MD5, objectMetadata.getContentMD5()); message.setHeader(S3Constants.CONTENT_LENGTH, objectMetadata.getContentLength()); message.setHeader(S3Constants.CONTENT_ENCODING, objectMetadata.getContentEncoding()); message.setHeader(S3Constants.CONTENT_DISPOSITION, objectMetadata.getContentDisposition()); message.setHeader(S3Constants.CACHE_CONTROL, objectMetadata.getCacheControl()); message.setHeader(S3Constants.S3_HEADERS, objectMetadata.getRawMetadata()); message.setHeader(S3Constants.SERVER_SIDE_ENCRYPTION, objectMetadata.getSSEAlgorithm()); message.setHeader(S3Constants.USER_METADATA, objectMetadata.getUserMetadata()); message.setHeader(S3Constants.EXPIRATION_TIME, objectMetadata.getExpirationTime()); message.setHeader(S3Constants.REPLICATION_STATUS, objectMetadata.getReplicationStatus()); message.setHeader(S3Constants.STORAGE_CLASS, objectMetadata.getStorageClass()); /** * If includeBody != true, it is safe to close the object here. If * includeBody == true, the caller is responsible for closing the stream * and object once the body has been fully consumed. As of 2.17, the * consumer does not close the stream or object on commit. */ if (!configuration.isIncludeBody()) { IOHelper.close(s3Object); } else { if (configuration.isAutocloseBody()) { exchange.addOnCompletion(new SynchronizationAdapter() { @Override public void onDone(Exchange exchange) { IOHelper.close(s3Object); } }); } } return exchange; }
From source file:org.finra.herd.dao.impl.MockS3OperationsImpl.java
License:Apache License
@Override public void restoreObject(RestoreObjectRequest requestRestore, AmazonS3 s3Client) { if (requestRestore.getKey().endsWith(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) { AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception"); throttlingException.setErrorCode("ThrottlingException"); throw throttlingException; } else if (MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION.equals(requestRestore.getBucketName())) { AmazonServiceException amazonServiceException = new AmazonServiceException( S3Operations.ERROR_CODE_NO_SUCH_BUCKET); amazonServiceException.setStatusCode(404); throw amazonServiceException; } else if (MOCK_S3_BUCKET_NAME_ACCESS_DENIED.equals(requestRestore.getBucketName())) { AmazonServiceException amazonServiceException = new AmazonServiceException( S3Operations.ERROR_CODE_ACCESS_DENIED); amazonServiceException.setStatusCode(403); throw amazonServiceException; } else if (MOCK_S3_BUCKET_NAME_INTERNAL_ERROR.equals(requestRestore.getBucketName()) || requestRestore.getKey().endsWith(MOCK_S3_FILE_NAME_SERVICE_EXCEPTION)) { throw new AmazonServiceException(S3Operations.ERROR_CODE_INTERNAL_ERROR); } else {//from ww w . j a v a 2 s . c o m MockS3Bucket mockS3Bucket = getOrCreateBucket(requestRestore.getBucketName()); MockS3Object mockS3Object = mockS3Bucket.getObjects().get(requestRestore.getKey()); if (mockS3Object == null) { AmazonServiceException amazonServiceException = new AmazonServiceException( S3Operations.ERROR_CODE_NO_SUCH_KEY); amazonServiceException.setStatusCode(404); throw amazonServiceException; } // Get object metadata. ObjectMetadata objectMetadata = mockS3Object.getObjectMetadata(); // Fail if the object is not in Glacier. if (!StorageClass.Glacier.toString().equals(objectMetadata.getStorageClass())) { AmazonServiceException amazonServiceException = new AmazonServiceException( "object is not in Glacier"); throw amazonServiceException; } // Fail if the object is already being restored. if (objectMetadata.getOngoingRestore()) { AmazonServiceException amazonServiceException = new AmazonServiceException( "object is already being restored"); throw amazonServiceException; } // Update the object metadata to indicate that there is an ongoing restore request. objectMetadata.setOngoingRestore(true); } }
From source file:org.finra.herd.dao.impl.S3DaoImpl.java
License:Apache License
@Override public void validateGlacierS3FilesRestored(S3FileTransferRequestParamsDto params) throws RuntimeException { LOGGER.info(/* ww w. jav a 2 s . com*/ "Checking for already restored Glacier storage class objects... s3KeyPrefix=\"{}\" s3BucketName=\"{}\" s3KeyCount={}", params.getS3KeyPrefix(), params.getS3BucketName(), params.getFiles().size()); if (!CollectionUtils.isEmpty(params.getFiles())) { // Initialize a key value pair for the error message in the catch block. String key = params.getFiles().get(0).getPath().replaceAll("\\\\", "/"); try { // Create an S3 client. AmazonS3Client s3Client = getAmazonS3(params); try { for (File file : params.getFiles()) { key = file.getPath().replaceAll("\\\\", "/"); ObjectMetadata objectMetadata = s3Operations.getObjectMetadata(params.getS3BucketName(), key, s3Client); // Fail if a not already restored object is detected. if (BooleanUtils.isNotFalse(objectMetadata.getOngoingRestore())) { throw new IllegalArgumentException(String.format( "Archived Glacier S3 file \"%s\" is not restored. StorageClass {%s}, OngoingRestore flag {%s}, S3 bucket name {%s}", key, objectMetadata.getStorageClass(), objectMetadata.getOngoingRestore(), params.getS3BucketName())); } } } finally { s3Client.shutdown(); } } catch (AmazonServiceException e) { throw new IllegalStateException( String.format("Fail to check restore status for \"%s\" key in \"%s\" bucket. Reason: %s", key, params.getS3BucketName(), e.getMessage()), e); } } }
From source file:org.xmlsh.aws.util.AWSS3Command.java
License:BSD License
protected void writeMeta(ObjectMetadata m) throws InvalidArgumentException, XMLStreamException, SaxonApiException { mLogger.entry(m);/*ww w. ja v a 2 s . co m*/ startElement(sMetaDataElem); attribute("cache-control", m.getCacheControl()); attribute("content-disposition", m.getContentDisposition()); attribute("content-encoding", m.getContentEncoding()); attribute("md5", m.getContentMD5()); attribute("etag", m.getETag()); attribute("version-id", m.getVersionId()); attribute("content-length", String.valueOf(m.getContentLength())); attribute("last-modified", Util.formatXSDateTime(m.getLastModified())); attribute("expiration-time", Util.formatXSDateTime(m.getExpirationTime())); attribute("expiration-time-rule-id", m.getExpirationTimeRuleId()); attribute("httpExpiresDate", Util.formatXSDateTime(m.getHttpExpiresDate())); attribute("ongoingRestore", m.getOngoingRestore()); attribute("restore-expiration-time", Util.formatXSDateTime(m.getRestoreExpirationTime())); attribute("instance-length", m.getInstanceLength()); attribute("sse-algorithm", m.getSSEAlgorithm()); attribute("sse-aws-kms-key-id", m.getSSEAwsKmsKeyId()); attribute("sse-customer-algorithm", m.getSSECustomerAlgorithm()); attribute("sse-customer-key-md5", m.getSSECustomerKeyMd5()); attribute("storage-class", m.getStorageClass()); startElement("user-metadata"); for (Entry<String, String> user : m.getUserMetadata().entrySet()) { startElement(sUserMetaDataElem); attribute("name", user.getKey()); attribute("value", user.getValue()); endElement(); } endElement(); endElement(); mLogger.exit(); }