use of software.amazon.awssdk.services.s3.model.S3Object 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 software.amazon.awssdk.services.s3.model.S3Object in project camel by apache.
the class S3BatchConsumerMaxMessagesPerPollTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
AmazonS3ClientMock clientMock = new AmazonS3ClientMock();
// add 20 messages
for (int counter = 0; counter < 20; counter++) {
S3Object s3Object = new S3Object();
s3Object.setBucketName("mycamelbucket");
s3Object.setKey("counter-" + counter);
clientMock.objects.add(s3Object);
}
registry.bind("amazonS3Client", clientMock);
return registry;
}
use of software.amazon.awssdk.services.s3.model.S3Object in project gradle-s3-build-cache by myniva.
the class AwsS3BuildCacheService method load.
@Override
public boolean load(BuildCacheKey key, BuildCacheEntryReader reader) {
final String bucketPath = getBucketPath(key);
if (s3.doesObjectExist(bucketName, bucketPath)) {
logger.info("Found cache item '{}' in S3 bucket", bucketPath);
S3Object object = s3.getObject(bucketName, bucketPath);
try (InputStream is = object.getObjectContent()) {
reader.readFrom(is);
return true;
} catch (IOException e) {
throw new BuildCacheException("Error while reading cache object from S3 bucket", e);
}
} else {
logger.info("Did not find cache item '{}' in S3 bucket", bucketPath);
return false;
}
}
use of software.amazon.awssdk.services.s3.model.S3Object in project nifi by apache.
the class FetchS3Object method onTrigger.
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
FlowFile flowFile = session.get();
if (flowFile == null) {
return;
}
final long startNanos = System.nanoTime();
final String bucket = context.getProperty(BUCKET).evaluateAttributeExpressions(flowFile).getValue();
final String key = context.getProperty(KEY).evaluateAttributeExpressions(flowFile).getValue();
final String versionId = context.getProperty(VERSION_ID).evaluateAttributeExpressions(flowFile).getValue();
final AmazonS3 client = getClient();
final GetObjectRequest request;
if (versionId == null) {
request = new GetObjectRequest(bucket, key);
} else {
request = new GetObjectRequest(bucket, key, versionId);
}
final Map<String, String> attributes = new HashMap<>();
try (final S3Object s3Object = client.getObject(request)) {
flowFile = session.importFrom(s3Object.getObjectContent(), flowFile);
attributes.put("s3.bucket", s3Object.getBucketName());
final ObjectMetadata metadata = s3Object.getObjectMetadata();
if (metadata.getContentDisposition() != null) {
final String fullyQualified = metadata.getContentDisposition();
final int lastSlash = fullyQualified.lastIndexOf("/");
if (lastSlash > -1 && lastSlash < fullyQualified.length() - 1) {
attributes.put(CoreAttributes.PATH.key(), fullyQualified.substring(0, lastSlash));
attributes.put(CoreAttributes.ABSOLUTE_PATH.key(), fullyQualified);
attributes.put(CoreAttributes.FILENAME.key(), fullyQualified.substring(lastSlash + 1));
} else {
attributes.put(CoreAttributes.FILENAME.key(), metadata.getContentDisposition());
}
}
if (metadata.getContentMD5() != null) {
attributes.put("hash.value", metadata.getContentMD5());
attributes.put("hash.algorithm", "MD5");
}
if (metadata.getContentType() != null) {
attributes.put(CoreAttributes.MIME_TYPE.key(), metadata.getContentType());
}
if (metadata.getETag() != null) {
attributes.put("s3.etag", metadata.getETag());
}
if (metadata.getExpirationTime() != null) {
attributes.put("s3.expirationTime", String.valueOf(metadata.getExpirationTime().getTime()));
}
if (metadata.getExpirationTimeRuleId() != null) {
attributes.put("s3.expirationTimeRuleId", metadata.getExpirationTimeRuleId());
}
if (metadata.getUserMetadata() != null) {
attributes.putAll(metadata.getUserMetadata());
}
if (metadata.getSSEAlgorithm() != null) {
attributes.put("s3.sseAlgorithm", metadata.getSSEAlgorithm());
}
if (metadata.getVersionId() != null) {
attributes.put("s3.version", metadata.getVersionId());
}
} catch (final IOException | AmazonClientException ioe) {
getLogger().error("Failed to retrieve S3 Object for {}; routing to failure", new Object[] { flowFile, ioe });
flowFile = session.penalize(flowFile);
session.transfer(flowFile, REL_FAILURE);
return;
}
if (!attributes.isEmpty()) {
flowFile = session.putAllAttributes(flowFile, attributes);
}
session.transfer(flowFile, REL_SUCCESS);
final long transferMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
getLogger().info("Successfully retrieved S3 Object for {} in {} millis; routing to success", new Object[] { flowFile, transferMillis });
session.getProvenanceReporter().fetch(flowFile, "http://" + bucket + ".amazonaws.com/" + key, transferMillis);
}
use of software.amazon.awssdk.services.s3.model.S3Object in project XRTB by benmfaul.
the class Configuration method processDirectory.
public void processDirectory(AmazonS3Client s3, ObjectListing listing, String bucket) throws Exception {
for (S3ObjectSummary objectSummary : listing.getObjectSummaries()) {
long size = objectSummary.getSize();
System.out.println("*** Processing S3 " + objectSummary.getKey() + ", size = " + size);
S3Object object = s3.getObject(new GetObjectRequest(bucket, objectSummary.getKey()));
String bucketName = object.getBucketName();
String keyName = object.getKey();
if (keyName.contains("Darren")) {
System.out.println("HERE");
}
GetObjectTaggingRequest request = new GetObjectTaggingRequest(bucketName, keyName);
GetObjectTaggingResult result = s3.getObjectTagging(request);
List<Tag> tags = result.getTagSet();
String type = null;
String name = null;
if (tags.isEmpty()) {
System.err.println("Error: " + keyName + " has no tags");
} else {
for (Tag tag : tags) {
String key = tag.getKey();
String value = tag.getValue();
if (key.equals("type")) {
type = value;
}
if (key.equals("name")) {
name = value;
}
}
if (name == null)
throw new Exception("Error: " + keyName + " is missing a name tag");
if (name.contains(" "))
throw new Exception("Error: " + keyName + " has a name attribute with a space in it");
if (type == null)
throw new Exception("Error: " + keyName + " has no type tag");
if (!name.startsWith("$"))
name = "$" + name;
readData(type, name, object, size);
}
}
}
Aggregations