List of usage examples for com.amazonaws AmazonClientException AmazonClientException
public AmazonClientException(String message, Throwable t)
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
private String getJSONFromS3Pointer(MessageS3Pointer s3Pointer) { String s3PointerStr = null;//from www . ja v a 2 s.com try { JsonDataConverter jsonDataConverter = new JsonDataConverter(); s3PointerStr = jsonDataConverter.serializeToJson(s3Pointer); } catch (Exception e) { String errorMessage = "Failed to convert S3 object pointer to text. Message was not sent."; LOG.error(errorMessage, e); throw new AmazonClientException(errorMessage, e); } return s3PointerStr; }
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
private void storeTextInS3(String s3Key, String messageContentStr, Long messageContentSize) { InputStream messageContentStream = new ByteArrayInputStream( messageContentStr.getBytes(StandardCharsets.UTF_8)); ObjectMetadata messageContentStreamMetadata = new ObjectMetadata(); messageContentStreamMetadata.setContentLength(messageContentSize); PutObjectRequest putObjectRequest = new PutObjectRequest(clientConfiguration.getS3BucketName(), s3Key, messageContentStream, messageContentStreamMetadata); try {// w w w . ja va 2 s. c o m clientConfiguration.getAmazonS3Client().putObject(putObjectRequest); } catch (AmazonServiceException e) { String errorMessage = "Failed to store the message content in an S3 object. SQS message was not sent."; LOG.error(errorMessage, e); throw new AmazonServiceException(errorMessage, e); } catch (AmazonClientException e) { String errorMessage = "Failed to store the message content in an S3 object. SQS message was not sent."; LOG.error(errorMessage, e); throw new AmazonClientException(errorMessage, e); } }
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
private static long getStringSizeInBytes(String str) { CountingOutputStream counterOutputStream = new CountingOutputStream(); try {/* w w w.ja va2 s . c om*/ Writer writer = new OutputStreamWriter(counterOutputStream, "UTF-8"); writer.write(str); writer.flush(); writer.close(); } catch (IOException e) { String errorMessage = "Failed to calculate the size of message payload."; LOG.error(errorMessage, e); throw new AmazonClientException(errorMessage, e); } return counterOutputStream.getTotalSize(); }
From source file:com.app.dynamoDb.DynamoUserAuthority.java
License:Open Source License
/** * The only information needed to create a client are security credentials * consisting of the AWS Access Key ID and Secret Access Key. All other * configuration, such as the service endpoints, are performed * automatically. Client parameters, such as proxies, can be specified in an * optional ClientConfiguration object when constructing a client. * * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration */// w ww . j a v a 2 s . co m private static void init() throws Exception { /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (C:\\Users\\yogeshrawat\\.aws\\credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("default").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 (C:\\Users\\yogeshrawat\\.aws\\credentials), and is in valid format.", e); } dynamoDB = new AmazonDynamoDBClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); dynamoDB.setRegion(usWest2); }
From source file:com.arc.cloud.aws.s3.S3Sample.java
License:Open Source License
public static void main(String[] args) throws IOException { /*/*from www . j av a2s . com*/ * 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); } AmazonS3 s3 = new AmazonS3Client(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); s3.setRegion(usWest2); String bucketName = "my-first-s3-bucket-" + UUID.randomUUID(); String key = "MyObjectKey"; System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("===========================================\n"); try { /* * Create a new S3 bucket - Amazon S3 bucket names are globally unique, * so once a bucket name has been taken by any user, you can't create * another bucket with that same name. * * You can optionally specify a location for your bucket if you want to * keep your data closer to your applications or users. */ System.out.println("Creating bucket " + bucketName + "\n"); s3.createBucket(bucketName); /* * List the buckets in your account */ System.out.println("Listing buckets"); for (Bucket bucket : s3.listBuckets()) { System.out.println(" - " + bucket.getName()); } System.out.println(); /* * Upload an object to your bucket - You can easily upload a file to * S3, or upload directly an InputStream if you know the length of * the data in the stream. You can also specify your own metadata * when uploading to S3, which allows you set a variety of options * like content-type and content-encoding, plus additional metadata * specific to your applications. */ System.out.println("Uploading a new object to S3 from a file\n"); s3.putObject(new PutObjectRequest(bucketName, key, createSampleFile())); /* * Download an object - When you download an object, you get all of * the object's metadata and a stream from which to read the contents. * It's important to read the contents of the stream as quickly as * possibly since the data is streamed directly from Amazon S3 and your * network connection will remain open until you read all the data or * close the input stream. * * GetObjectRequest also supports several other options, including * conditional downloading of objects based on modification times, * ETags, and selectively downloading a range of an object. */ System.out.println("Downloading an object"); S3Object object = s3.getObject(new GetObjectRequest(bucketName, key)); System.out.println("Content-Type: " + object.getObjectMetadata().getContentType()); displayTextInputStream(object.getObjectContent()); /* * List objects in your bucket by prefix - There are many options for * listing the objects in your bucket. Keep in mind that buckets with * many objects might truncate their results when listing their objects, * so be sure to check if the returned object listing is truncated, and * use the AmazonS3.listNextBatchOfObjects(...) operation to retrieve * additional results. */ System.out.println("Listing objects"); ObjectListing objectListing = s3 .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("My")); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.println( " - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); } System.out.println(); /* * Delete an object - Unless versioning has been turned on for your bucket, * there is no way to undelete an object, so use caution when deleting objects. */ System.out.println("Deleting an object\n"); s3.deleteObject(bucketName, key); /* * Delete a bucket - A bucket must be completely empty before it can be * deleted, so remember to delete any objects from your buckets before * you try to delete them. */ System.out.println("Deleting bucket " + bucketName + "\n"); s3.deleteBucket(bucketName); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon S3, 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 S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.atlassian.localstack.sample.S3Sample.java
License:Open Source License
public static void main(String[] args) throws IOException { /*/*from w w w .j a va 2s .c o 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); } runTest(credentials); }
From source file:com.boundary.aws.kinesis.Sample.java
License:Open Source License
private static void init() throws Exception { /*// www. j a v a2 s. c om * The ProfileCredentialsProvider will return your [default] credential * profile by reading from the credentials file located at * (HOME/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("default").getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. ", e); } kinesisClient = new AmazonKinesisClient(credentials); Region region = Region.getRegion(Regions.US_WEST_2); kinesisClient.setRegion(region); }
From source file:com.boundary.aws.sqs.Sample.java
License:Open Source License
public static void main(String[] args) throws Exception { String queueName = "boundary-sqs-demo-queue"; /*/* www. j a va 2 s . com*/ * The ProfileCredentialsProvider will return your [default] credential * profile by reading from the credentials file located at * (HOME/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("default").getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. ", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2); try { // Create a queue System.out.printf("Creating queue: %s.\n", queueName); CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); int messageCount = 100; // Send a messages for (int count = 1; count <= messageCount; count++) { System.out.printf("Sending message %3d to %s.\n", count, queueName); sqs.sendMessage(new SendMessageRequest(myQueueUrl, new Date() + ": This is my message text.")); } for (int count = 1; count <= messageCount; count++) { ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message msg : messages) { System.out.printf("Received message: %s queue: %s body: %s\n", msg.getMessageId(), queueName, msg.getBody()); System.out.printf("Deleting message: %s queue: %s\n", msg.getMessageId(), queueName); String messageRecieptHandle = msg.getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle)); } } System.out.printf("Deleting queue: %s\n", queueName); 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()); } sqs.shutdown(); }
From source file:com.calamp.services.kinesis.events.utils.CredentialUtils.java
License:Open Source License
public static AWSCredentialsProvider getCredentialsProvider() throws Exception { /*//from ww w . ja v a2 s . c o m * The ProfileCredentialsProvider will return your [default] credential profile by * reading from the credentials file located at (~/.aws/credentials). */ AWSCredentialsProvider credentialsProvider = null; try { credentialsProvider = new ProfileCredentialsProvider("default"); } 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); } return credentialsProvider; }
From source file:com.cloud.Assignment.QueueSender.java
License:Open Source License
public boolean sendToQueue(String queue, String message) throws Exception { Properties props = new Properties(); AWSCredentials credentials = null;//from w w w . j av a2s.c o m String myQueueUrl = null; System.out.println("Queue :" + queue + " Message :" + message); try { credentials = new ClasspathPropertiesFileCredentialsProvider("AwsCredentials.properties") .getCredentials(); ClassLoader loader = Thread.currentThread().getContextClassLoader(); props.load(loader.getResourceAsStream("/QueueURL.properties")); } 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 (/Users/prabhus/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usWest2); try { myQueueUrl = props.getProperty(queue); System.out.println("URL :" + myQueueUrl); System.out.println("Sending " + message); sqs.sendMessage(new SendMessageRequest(myQueueUrl, message)); isMessagePosted = true; } catch (AmazonServiceException ase) { throw new AmazonServiceException("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); } catch (AmazonClientException ace) { System.out.println("Error Message: " + ace.getMessage()); throw new AmazonClientException("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."); } return isMessagePosted; }