List of usage examples for com.amazonaws AmazonServiceException getMessage
@Override
public String getMessage()
From source file:org.excalibur.service.aws.ec2.EC2.java
License:Open Source License
public Image getImageById(String imageId) { Image image = null;/*from ww w . j ava2s .com*/ try { DescribeImagesResult describeImages = ec2_ .describeImages(new DescribeImagesRequest().withImageIds(imageId)); image = Lists2.first(describeImages.getImages()); } catch (com.amazonaws.AmazonServiceException exception) { LOG.error("Error on describing image: [{}]. Error message: [{}]", imageId, exception.getMessage(), exception); } return image; }
From source file:org.finra.dm.dao.impl.S3DaoImpl.java
License:Apache License
@Override public ObjectMetadata getObjectMetadata(final S3FileTransferRequestParamsDto params) { AmazonS3Client s3Client = null;// ww w .j av a 2 s . co m try { s3Client = getAmazonS3(params); return s3Operations.getObjectMetadata(params.getS3BucketName(), params.getS3KeyPrefix(), s3Client); } catch (AmazonServiceException e) { if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) { return null; } throw new IllegalStateException( String.format("Failed to get S3 metadata for object key \"%s\" from bucket \"%s\". Reason: %s", params.getS3KeyPrefix(), params.getS3BucketName(), e.getMessage()), e); } finally { // Shutdown the AmazonS3Client instance to release resources. if (s3Client != null) { s3Client.shutdown(); } } }
From source file:org.finra.dm.dao.impl.S3DaoImpl.java
License:Apache License
@Override public void createDirectory(final S3FileTransferRequestParamsDto params) { // Create metadata for the directory marker and set content-length to 0 bytes. ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(0);/*from w w w.j a va 2 s . c om*/ prepareMetadata(params, metadata); // Create empty content. InputStream emptyContent = new ByteArrayInputStream(new byte[0]); // Create a PutObjectRequest passing the folder name suffixed by '/'. String directoryName = params.getS3KeyPrefix() + (params.getS3KeyPrefix().endsWith("/") ? "" : "/"); PutObjectRequest putObjectRequest = new PutObjectRequest(params.getS3BucketName(), directoryName, emptyContent, metadata); AmazonS3Client s3Client = null; try { s3Client = getAmazonS3(params); s3Operations.putObject(putObjectRequest, s3Client); } catch (AmazonServiceException e) { throw new IllegalStateException( String.format("Failed to create 0 byte S3 object with \"%s\" key in bucket \"%s\". Reason: %s", directoryName, params.getS3BucketName(), e.getMessage()), e); } finally { // Shutdown the AmazonS3Client instance to release resources. if (s3Client != null) { s3Client.shutdown(); } } }
From source file:org.finra.dm.service.impl.EmrServiceImpl.java
License:Apache License
/** * Handles the AmazonServiceException, throws corresponding exception based on status code in amazon exception. *///from w w w .ja va 2 s. c o m private void handleAmazonException(AmazonServiceException ex, String message) throws IllegalArgumentException, ObjectNotFoundException { if (ex.getStatusCode() == HttpStatus.SC_BAD_REQUEST) { throw new IllegalArgumentException(message + " Reason: " + ex.getMessage(), ex); } else if (ex.getStatusCode() == HttpStatus.SC_NOT_FOUND) { throw new ObjectNotFoundException(message + " Reason: " + ex.getMessage(), ex); } throw ex; }
From source file:org.finra.herd.dao.impl.S3DaoImpl.java
License:Apache License
@Override public void createDirectory(final S3FileTransferRequestParamsDto params) { // Create metadata for the directory marker and set content-length to 0 bytes. ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(0);/*from w ww. j av a2s .c o m*/ prepareMetadata(params, metadata); // Create empty content. InputStream emptyContent = new ByteArrayInputStream(new byte[0]); // Create a PutObjectRequest passing the folder name suffixed by '/'. String directoryName = StringUtils.appendIfMissing(params.getS3KeyPrefix(), "/"); PutObjectRequest putObjectRequest = new PutObjectRequest(params.getS3BucketName(), directoryName, emptyContent, metadata); // KMS key ID is being set through prepareMetadata() AmazonS3Client s3Client = getAmazonS3(params); try { s3Operations.putObject(putObjectRequest, s3Client); } catch (AmazonServiceException e) { throw new IllegalStateException( String.format("Failed to create 0 byte S3 object with \"%s\" key in bucket \"%s\". Reason: %s", directoryName, params.getS3BucketName(), e.getMessage()), e); } finally { // Shutdown the AmazonS3Client instance to release resources. s3Client.shutdown(); } }
From source file:org.finra.herd.dao.impl.S3DaoImpl.java
License:Apache License
@Override public ObjectMetadata getObjectMetadata(final S3FileTransferRequestParamsDto params) { AmazonS3Client s3Client = getAmazonS3(params); try {/* w ww. j a va 2 s. c o m*/ return s3Operations.getObjectMetadata(params.getS3BucketName(), params.getS3KeyPrefix(), s3Client); } catch (AmazonServiceException e) { if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) { return null; } throw new IllegalStateException( String.format("Failed to get S3 metadata for object key \"%s\" from bucket \"%s\". Reason: %s", params.getS3KeyPrefix(), params.getS3BucketName(), e.getMessage()), e); } finally { // Shutdown the AmazonS3Client instance to release resources. s3Client.shutdown(); } }
From source file:org.finra.herd.dao.impl.S3DaoImpl.java
License:Apache License
@Override public void validateGlacierS3FilesRestored(S3FileTransferRequestParamsDto params) throws RuntimeException { LOGGER.info(/*from w w w . jav a 2s.c o m*/ "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.finra.herd.service.helper.AwsServiceHelper.java
License:Apache License
/** * Handles the AmazonServiceException, throws corresponding exception based on status code in amazon exception. * * @param amazonServiceException the AWS exception that will be handled by this method. * @param message the message to include with this exception. * * @throws IllegalArgumentException the exception to be thrown with a HttpStatus.SC_BAD_REQUEST * @throws ObjectNotFoundException the exception to be thrown with a HttpStatus.SC_NOT_FOUND *//* www . java2 s . c o m*/ public void handleAmazonException(AmazonServiceException amazonServiceException, String message) throws IllegalArgumentException, ObjectNotFoundException { if (amazonServiceException.getStatusCode() == HttpStatus.SC_BAD_REQUEST) { throw new IllegalArgumentException(message + " Reason: " + amazonServiceException.getMessage(), amazonServiceException); } else if (amazonServiceException.getStatusCode() == HttpStatus.SC_NOT_FOUND) { throw new ObjectNotFoundException(message + " Reason: " + amazonServiceException.getMessage(), amazonServiceException); } throw amazonServiceException; }
From source file:org.freeeed.aws.SimpleQueueServiceSample.java
License:Apache License
public static void main(String[] args) throws Exception { /*//w w w . j a v a 2 s. co m * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); try { // Create a queue System.out.println("Creating a new SQS queue called MyQueue.\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("MyQueue"); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); // List queues System.out.println("Listing all queues in your account.\n"); // TODO restore System.out.println(); // Send a message System.out.println("Sending a message to MyQueue.\n"); sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my message text.")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { System.out.println(message.toString()); } System.out.println(); // Delete a message System.out.println("Deleting a message.\n"); String messageReceiptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageReceiptHandle)); // Delete a queue System.out.println("Deleting the test queue.\n"); sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SQS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:org.geowebcache.s3.S3BlobStore.java
License:Open Source License
public S3BlobStore(S3BlobStoreConfig config, TileLayerDispatcher layers, LockProvider lockProvider) throws StorageException { checkNotNull(config);//from ww w . ja va 2 s . com checkNotNull(layers); checkNotNull(config.getAwsAccessKey(), "Access key not provided"); checkNotNull(config.getAwsSecretKey(), "Secret key not provided"); this.bucketName = config.getBucket(); String prefix = config.getPrefix() == null ? "" : config.getPrefix(); this.keyBuilder = new TMSKeyBuilder(prefix, layers); conn = config.buildClient(); try { log.debug("Checking access rights to bucket " + bucketName); AccessControlList bucketAcl = this.conn.getBucketAcl(bucketName); List<Grant> grants = bucketAcl.getGrantsAsList(); log.debug("Bucket " + bucketName + " permissions: " + grants); } catch (AmazonServiceException se) { throw new StorageException("Server error listing buckets: " + se.getMessage(), se); } catch (AmazonClientException ce) { throw new StorageException("Unable to connect to AWS S3", ce); } this.s3Ops = new S3Ops(conn, bucketName, keyBuilder, lockProvider); }