List of usage examples for com.amazonaws AmazonClientException AmazonClientException
public AmazonClientException(String message, Throwable t)
From source file:Reference.SimpleQueueServiceSample.java
License:Open Source License
public static void main(String[] args) throws Exception { /*//w w w. j a v a2 s .c o m * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (). */ 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 (/Users/daniel/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usEast1); 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"); for (String queueUrl : sqs.listQueues().getQueueUrls()) { System.out.println(" QueueUrl: " + queueUrl); } 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"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } System.out.println(); // Delete a message System.out.println("Deleting a message.\n"); String messageRecieptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle)); // 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:rg.ent.S3SampleB.java
License:Open Source License
public static void copyFileBtweenBuckets() { AWSCredentials credentials = null;/* w w w .j a v a2s . c o m*/ 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 (/Users/john/.aws/credentials), and is in valid format.", e); } String file_name = "640_262098533.JPG"; String source_bucket = "royaltygroupimages"; String dest_bucket = "royaltygroupupload"; AmazonS3 s3 = new AmazonS3Client(credentials); CopyObjectRequest cor = new CopyObjectRequest(source_bucket, file_name, dest_bucket, file_name); s3.copyObject(cor); s3.setObjectAcl(dest_bucket, file_name, CannedAccessControlList.PublicRead); //S3Object[] filteredObjects = s3Service.listObjects("sourceBucket", "appData/", null); //for(S3Object object: filteredObjects ){ // s3Service.copyObject("sourceBucket", "newAppData/" + object.getKey().substring(object.getKey().indexOf("/"), "destBucket", object, false); //} }
From source file:S3Controller.DownloadingImages.java
public static void main(String[] args) throws IOException { AWSCredentials credentials = null;/*from w ww.j a va 2s . co m*/ String aws_access_key_id = "PUT_YOUR_aws_access_key_id_HERE"; String aws_secret_access_key = "PUT_YOUR_aws_secret_access_key_HERE"; try { credentials = new BasicAWSCredentials(aws_access_key_id, aws_secret_access_key);//.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 AP_SOUTHEAST_1 = Region.getRegion(Regions.AP_SOUTHEAST_1); s3.setRegion(AP_SOUTHEAST_1); String bucketName = "PUT_YOUR_S3-BUCKET-NAME_HERE"; String key = "PUT_YOUR_S3-BUCKET-KEY_HERE"; try { ArrayList arr = new ArrayList(); ArrayList EmailArray = new ArrayList(); Bucket bucket = new Bucket(bucketName); ObjectListing objects = s3.listObjects(bucket.getName()); do { for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) { // System.out.println(objectSummary.getKey() + "\t" + // objectSummary.getSize() + "\t" + // StringUtils.fromDate(objectSummary.getLastModified())); arr.add(objectSummary.getKey()); } objects = s3.listNextBatchOfObjects(objects); } while (objects.isTruncated()); KrakenIOExampleMain kraken = new KrakenIOExampleMain(); for (int i = 0; i < arr.size(); i++) { System.out.println("Compressing: " + arr.get(i)); String s = (String) arr.get(i); GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket.getName(), s); System.out.println(s3.generatePresignedUrl(request)); URL Glink = s3.generatePresignedUrl(request); String Dlink = Glink.toString(); System.out.println("Download Link:" + Dlink); kraken.Compression(Dlink, bucketName); System.out.println("Compression completed: " + arr.get(i)); EmailArray.add("Processed Image:" + arr.get(i)); } System.out.println("Start Emailing list"); EmailSender esender = new EmailSender(); esender.EmailVerification(GetNotificationEmail, EmailArray); System.out.println("Kraken compression completed"); } 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()); } catch (ExecutionException ex) { Logger.getLogger(DownloadingImages.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(DownloadingImages.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:S3Controller.UploadImages.java
public void UploadToS3(String bucketname, String filename, String filepath) { // public static void main(String[] args) { AWSCredentials credentials = null;/*from w ww .j a v a2 s . c om*/ String aws_access_key_id = "PUT_YOUR_aws_access_key_id_HERE"; String aws_secret_access_key = "PUT_YOUR_aws_secret_access_key_HERE"; String bucketName = bucketname; //"zillionbucket"; String fileName = filename; //"javaee_duke_image.jpg"; String localpath = filepath; //"C:\\Users\\Hariom\\Documents\\NetBeansProjects\\JavaApplication9\\src\\ProcessedImages\\javaee_duke_image.jpg"; try { credentials = new BasicAWSCredentials(aws_access_key_id, aws_secret_access_key);//.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 AP_SOUTHEAST_1 = Region.getRegion(Regions.AP_SOUTHEAST_1); s3.setRegion(AP_SOUTHEAST_1); try { s3.putObject(new PutObjectRequest(bucketName, fileName, new File(localpath)) .withCannedAcl(CannedAccessControlList.PublicRead)); System.out.println("File Uploaded to S3: " + fileName); } 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:scheduler.SQSService.java
License:Apache License
public SQSService(String queueName) { /*/* w w w . j a v a 2s. c om*/ * 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); } sqs = new AmazonSQSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usEast1); // Create a queue or returns the URL of an existing one //System.out.println("Creating a new SQS queue called " + queueName); CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName); queueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); }
From source file:searchengine.WordToDoc.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 *///from w w w . ja va 2s.com private static void init() throws Exception { /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (/home/cis455/.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 (/home/cis455/.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:Server.aws.yulei.SQSOperation.java
License:Open Source License
public static void sendSQS(String message) { AWSCredentials credentials = null;/*from ww w . jav a 2 s. co m*/ 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 (/Users/daniel/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_EAST_1); 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 = "https://sqs.us-east-1.amazonaws.com/659322195879/MyQueue"; // List queues System.out.println("Listing all queues in your account.\n"); for (String queueUrl : sqs.listQueues().getQueueUrls()) { System.out.println(" QueueUrl: " + queueUrl); } System.out.println(); // Send a message System.out.println("Sending a message to MyQueue----\n"); sqs.sendMessage(new SendMessageRequest(myQueueUrl, message)); } catch (Exception e) { Thread.currentThread().interrupt(); } }
From source file:Server.aws.yulei.SQSOperation.java
License:Open Source License
public static void receiveSQS() { AWSCredentials credentials = null;//w ww. j a v a2 s. c o m 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 (/Users/daniel/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_EAST_1); 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 = "https://sqs.us-east-1.amazonaws.com/659322195879/MyQueue"; // List queues System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { String realData = message.getBody(); AlchemyAPI alchemyObj = AlchemyAPI .GetInstanceFromString("a47635756e657c0dac0bc2d282dbde377de01513"); JSONParser parser = new JSONParser(); JSONObject decodeObj = (JSONObject) parser.parse(realData); String content = (String) decodeObj.get("content"); // load text String text = content; // analyze text Document doc = alchemyObj.TextGetTextSentiment(text); String score = "0.00000"; // parse XML result // String sentiment = doc.getElementsByTagName("type").item(0).getTextContent(); // score = doc.getElementsByTagName("score").item(0).getTextContent(); decodeObj.put("score", score); decodeObj.put("sentiment", "Positive"); StringWriter sw = new StringWriter(); decodeObj.writeJSONString(sw); String jsonText = sw.toString(); SNSPushToGCM.push(jsonText); } } catch (Exception e) { Thread.currentThread().interrupt(); } }
From source file:Servlet.WorkPool.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.PropertiesCredentials * @see com.amazonaws.ClientConfiguration *//*from www. j a v a2 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 * (/home/zeweijiang/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("jiangzewei").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 (/home/zeweijiang/.aws/credentials), and is in valid format.", e); } sqs = new AmazonSQSClient(credentials); sns = new AmazonSNSClient(credentials); }
From source file:sqs_examples.SimpleQueueServiceSample.java
License:Open Source License
public static void main(String[] args) throws Exception { /*//from w w w . j a v a 2 s . c o m * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (/Users/pmacharl/.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 (/Users/pmacharl/.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"); for (String queueUrl : sqs.listQueues().getQueueUrls()) { System.out.println(" QueueUrl: " + queueUrl); } 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"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } 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()); } }