use of software.amazon.awssdk.services.s3.model.GetObjectRequest in project carina by qaprosoft.
the class AmazonS3Manager method get.
/**
* Get any file from Amazon S3 storage as S3Object.
*
* @param bucket
* - S3 Bucket name.
* @param key
* - S3 storage path. Example:
* DEMO/TestSuiteName/TestMethodName/file.txt
* @return S3Object
*/
public S3Object get(String bucket, String key) {
if (bucket == null) {
throw new RuntimeException("Bucket is null!");
}
if (bucket.isEmpty()) {
throw new RuntimeException("Bucket is empty!");
}
if (key == null) {
throw new RuntimeException("Key is null!");
}
if (key.isEmpty()) {
throw new RuntimeException("Key is empty!");
}
try {
LOGGER.info("Finding an s3object...");
// TODO investigate possibility to add percentage of completed
// downloading
S3Object s3object = s3client.getObject(new GetObjectRequest(bucket, key));
LOGGER.info("Content-Type: " + s3object.getObjectMetadata().getContentType());
return s3object;
/*
* GetObjectRequest rangeObjectRequest = new GetObjectRequest(
* bucketName, key); rangeObjectRequest.setRange(0, 10); S3Object
* objectPortion = s3client.getObject(rangeObjectRequest);
*/
} catch (AmazonServiceException ase) {
LOGGER.error("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response for some reason.\n" + "Error Message: " + ase.getMessage() + "\n" + "HTTP Status Code: " + ase.getStatusCode() + "\n" + "AWS Error Code: " + ase.getErrorCode() + "\n" + "Error Type: " + ase.getErrorType() + "\n" + "Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
LOGGER.error("Caught an AmazonClientException, which " + "means the client encountered " + "an internal error while trying to " + "communicate with S3, " + "such as not being able to access the network.\n" + "Error Message: " + ace.getMessage());
}
// TODO investigate pros and cons returning null
throw new RuntimeException("Unable to download '" + key + "' from Amazon S3 bucket '" + bucket + "'");
}
use of software.amazon.awssdk.services.s3.model.GetObjectRequest in project bender by Nextdoor.
the class GeoIpOperationFactory method setConf.
@Override
public void setConf(AbstractConfig config) {
this.config = (GeoIpOperationConfig) config;
AmazonS3Client client = this.s3Factory.newInstance();
AmazonS3URI uri = new AmazonS3URI(this.config.getGeoLiteDb());
GetObjectRequest req = new GetObjectRequest(uri.getBucket(), uri.getKey());
S3Object obj = client.getObject(req);
try {
this.databaseReader = new DatabaseReader.Builder(obj.getObjectContent()).withCache(new CHMCache()).build();
} catch (IOException e) {
throw new ConfigurationException("Unable to read " + this.config.getGeoLiteDb(), e);
}
}
Aggregations