List of usage examples for com.amazonaws AmazonServiceException getMessage
@Override
public String getMessage()
From source file:com.athena.sqs.MessageDispatcher.java
License:Apache License
/** * Send message to amazon sqs//from ww w . ja va2 s. co m * @param queueName * @param messages * @throws MessageException */ public void doSend(String queueName, String jsonString) throws MessageException { String transactionId = UUID.randomUUID().toString(); try { logger.debug("Getting Queue URL from Amazon [" + queueName + "]"); String queueUrl = messageContext.getQueue(queueName); logger.debug("Sending a message to [" + queueName + "][" + queueUrl + "]"); // if message is small enough to be sent as one message, do it if (jsonString.getBytes(MessageSplitter.UTF_8).length <= MessageSplitter.SQS_MAX_MESSAGE_SIZE) { String header = makeHeader(MessageTransferType.JSON, "athena", transactionId, true, 1, 1); logger.debug("This is smaller message"); logger.debug("[HEADER] : " + header); String singleMessage = header + encoder.encodeBuffer(jsonString.getBytes()); client.sendMessage(new SendMessageRequest(queueUrl, singleMessage)); logger.debug("Single message sent successfully"); } else { logger.debug("This is larger than " + MessageSplitter.SQS_MAX_MESSAGE_SIZE); List<String> messageList = MessageSplitter.split(encoder.encodeBuffer(jsonString.getBytes())); int current = 1; int total = messageList.size(); String header = null; String chunkedMessage = null; for (String target : messageList) { header = makeHeader(MessageTransferType.JSON, "athena", transactionId, false, current++, total); chunkedMessage = header + target; client.sendMessage(new SendMessageRequest(queueUrl, chunkedMessage)); logger.debug(chunkedMessage); } logger.debug("Complex message sent successfully"); } } catch (AmazonServiceException ase) { logger.error("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); logger.error("Error Message: " + ase.getMessage()); logger.error("HTTP Status Code: " + ase.getStatusCode()); logger.error("AWS Error Code: " + ase.getErrorCode()); logger.error("Error Type: " + ase.getErrorType()); logger.error("Request ID: " + ase.getRequestId()); throw new MessageException( MessageFormat.format(MessageErrors.AMAZON_ERROR.getDescription(), ase.getMessage())); } catch (AmazonClientException ace) { logger.error("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."); logger.error("Error Message: " + ace.getMessage()); throw new MessageException( MessageFormat.format(MessageErrors.AMAZON_ERROR.getDescription(), ace.getMessage())); } catch (IOException ioe) { throw new MessageException( MessageFormat.format(MessageErrors.INTERNAL_ERROR.getDescription(), ioe.getMessage())); } catch (Exception e) { throw new MessageException( MessageFormat.format(MessageErrors.INTERNAL_ERROR.getDescription(), e.getMessage())); } finally { } }
From source file:com.att.aro.core.cloud.aws.AwsRepository.java
License:Apache License
@Override public TransferState put(File file) { try {//from w w w. j av a 2s .c om PutObjectRequest req = new PutObjectRequest(bucketName, file.getName(), file); Upload myUpload = transferMgr.upload(req); myUpload.waitForCompletion(); transferMgr.shutdownNow(); return myUpload.getState(); } catch (AmazonServiceException ase) { LOGGER.error("Error Message: " + ase.getMessage()); } catch (Exception exception) { LOGGER.error(exception.getMessage(), exception); } return null; }
From source file:com.aws.sampleImage.url.LambdaFunctionImageURLCrawlerHandler.java
private void handleEachRecord(String eventName, StreamRecord streamRecord) { try {//from ww w .j a va 2 s. co m //Only if Insert then start processing if (INSERT_EVENT.equalsIgnoreCase(eventName)) { Map<String, AttributeValue> newImageMap = streamRecord.getNewImage(); AttributeValue keywordsAttrVal = newImageMap.get("keywords"); AttributeValue synsetCodeAttrVal = newImageMap.get("synset_code"); String keywords = keywordsAttrVal.getS(); String synsetCode = synsetCodeAttrVal.getS(); /*System.out.println("Keywords : " + keywords); System.out.println("SynsetCode : " + synsetCode);*/ String[] keywordFragments = keywords.split(","); for (int i = 0; i < keywordFragments.length; i++) { //System.out.println("Calling Flickr API for getting Image URL :: " + keywordFragments[i]); callFlickrAPIForEachKeyword(keywordFragments[i], synsetCode); } } } catch (AmazonServiceException ase) { System.out.println(ase.getMessage()); //ace.printStackTrace(); } catch (AmazonClientException ace) { System.out.println(ace.getMessage()); //ace.printStackTrace(); } catch (Exception ex) { System.out.println(ex.getMessage()); //ex.printStackTrace(); } }
From source file:com.aws.sns.service.notifications.sns.SNSMobilePush.java
License:Open Source License
public static void sendPushNotifications(NotificationTaskWorkerInput input) { try {/* w ww. ja v a 2 s.c o m*/ System.out.println("===========================================\n"); System.out.println("Getting Started with Amazon SNS"); System.out.println("===========================================\n"); try { SNSMobilePush sample = new SNSMobilePush(sns); if (SNSPlatformHelper.Platform.GCM.name() == input.getPlatform().name()) { sample.demoAndroidAppNotification(input.getToken(), input.getMessage(), input.getAction(), input.getCollapseKey()); } else if (SNSPlatformHelper.Platform.APNS.name() == input.getPlatform().name()) { sample.demoAppleAppNotification(input.getToken(), input.getMessage(), input.getAction(), input.getCollapseKey()); } else { LOGGER.error("Unsupported SNS Notification Service :" + input.getPlatform().name()); } // sample.demoKindleAppNotification(); // sample.demoAppleAppNotification(); // sample.demoAppleSandboxAppNotification(); // sample.demoBaiduAppNotification(); // sample.demoWNSAppNotification(); // sample.demoMPNSAppNotification(); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, 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 SNS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } } catch (Exception e) { LOGGER.error("Error in sendPushNofifications :", e); } }
From source file:com.aws.sns.service.notifications.sns.SNSMobilePush.java
License:Open Source License
public static void main(String[] args) throws IOException { /*// ww w.j a v a 2s. co m * TODO: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this sample. * http://aws.amazon.com/security-credentials */ AmazonSNS sns = new AmazonSNSClient( new PropertiesCredentials(SNSMobilePush.class.getResourceAsStream("AwsCredentials.properties"))); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); System.out.println("===========================================\n"); System.out.println("Getting Started with Amazon SNS"); System.out.println("===========================================\n"); try { SNSMobilePush sample = new SNSMobilePush(sns); /* TODO: Uncomment the services you wish to use. */ String registrationId = "APA91bEzO4gs7gqC0PPaw1RKzlDY5cEmRwGzV4k5DPzc_uxp8aLyNVGS3Wx7G6O3lj9v17aqUBtoTyg3JZvbsOVt81mdUDTDDiXoiWLJt9PtcWUUNKYyJsiaq1OlPnSNRx2djcfPS7Pp"; sample.demoAndroidAppNotification(registrationId, "Test Message", "payload action", "Moonfrog"); // sample.demoKindleAppNotification(); // sample.demoAppleAppNotification("c522823644bf4e799d94adc7bc4c1f1dd57066a38cc72b7d37cf48129379c13b", "APNS Welcome !!!", "apns", "Moonfrog"); // sample.demoAppleSandboxAppNotification(); // sample.demoBaiduAppNotification(); // sample.demoWNSAppNotification(); // sample.demoMPNSAppNotification(); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SNS, 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 SNS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.boundary.aws.dynamodb.QueryDynamoDB.java
License:Open Source License
public static void main(String[] args) throws Exception { init();/*from w w w .j a v a2 s. co m*/ try { String tableName = "my-favorite-movies-table"; // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is already ACTIVE"); } else { System.out.println("Table to query " + tableName + "does not exist"); } while (true) { // Scan items for movies with a year attribute greater than 1985 HashMap<String, Condition> scanFilter = new HashMap<String, Condition>(); Condition scanCondition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()) .withAttributeValueList(new AttributeValue().withN("1985")); scanFilter.put("year", scanCondition); ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); System.out.println("Result: " + scanResult); Condition hashKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS("Matrix")); Map<String, Condition> keyConditions = new HashMap<String, Condition>(); keyConditions.put("name", hashKeyCondition); QueryRequest queryRequest = new QueryRequest().withTableName(tableName) .withKeyConditions(keyConditions); QueryResult queryResult = dynamoDB.query(queryRequest); System.out.println("Result: " + queryResult); Thread.sleep(5000); } } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to AWS, 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 AWS, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
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"; /*/*from www .jav a 2 s .co m*/ * 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.boxupp.dao.AwsProjectDAOManager.java
License:Apache License
private String getPrivateHostName(String instanceID, String accessKeyId, String secretKey, String instanceRegion) {// w w w . ja v a 2 s . c o m String privateHostName = null; BasicAWSCredentials cred = new BasicAWSCredentials(accessKeyId, secretKey); AmazonEC2Client ec2Client = new AmazonEC2Client(cred); try { ec2Client.setRegion(Region.getRegion(Regions.fromName(instanceRegion))); ArrayList<String> instanceIds = new ArrayList<String>(); instanceIds.add(instanceID); DescribeInstancesRequest req = new DescribeInstancesRequest(); req.setInstanceIds(instanceIds); DescribeInstancesResult result = ec2Client.describeInstances(req); Instance instance = result.getReservations().get(0).getInstances().get(0); privateHostName = instance.getPrivateDnsName(); } catch (AmazonServiceException amazonServiceException) { logger.info("Error while fecthing instance info from aws " + amazonServiceException.getMessage()); } catch (Exception exception) { logger.info("Error while fecthing instance info from aws " + exception.getMessage()); } return privateHostName; }
From source file:com.boxupp.dao.AwsProjectDAOManager.java
License:Apache License
public StatusBean authenticateAwsCredentials(JsonNode awsCredentials) { StatusBean statusBean = new StatusBean(); String keyPair = awsCredentials.get("awsKeyPair").asText(); String privateKeyPath = awsCredentials.get("privateKeyPath").asText(); try {/* w ww. j ava 2 s . c om*/ checkIfPrivateFileExists(privateKeyPath); BasicAWSCredentials cred = new BasicAWSCredentials(awsCredentials.get("awsAccessKeyId").asText(), awsCredentials.get("awsSecretAccessKey").asText()); AmazonEC2Client ec2Client = new AmazonEC2Client(cred); statusBean = validateKeyPair(ec2Client, keyPair); } catch (AmazonServiceException amazonServiceException) { statusBean.setStatusCode(1); statusBean.setStatusMessage("Error while authenticating aws credentials"); logger.info("invalid aws credentials " + amazonServiceException.getMessage()); } catch (FileNotFoundException fileNotFoundException) { statusBean.setStatusCode(1); statusBean.setStatusMessage("Private Key file not found at entered path"); logger.info("Private Key file not found at entered path " + fileNotFoundException.getMessage()); } catch (Exception exception) { statusBean.setStatusCode(1); statusBean.setStatusMessage("Error while authenticating aws credentials"); logger.info("invalid aws credentials " + exception.getMessage()); } return statusBean; }
From source file:com.climate.oada.dao.impl.S3ResourceDAO.java
License:Open Source License
/** * Log AWSServiceException details./*from w ww .j av a 2s . c o m*/ * * @param ase - exception object. */ private void logAWSServiceException(AmazonServiceException ase) { LOG.error( "Caught an AmazonServiceException, " + "request to Amazon S3 was rejected with an error response"); LOG.error("Error Message: " + ase.getMessage()); LOG.error("HTTP Status Code: " + ase.getStatusCode()); LOG.error("AWS Error Code: " + ase.getErrorCode()); LOG.error("Error Type: " + ase.getErrorType()); LOG.error("Request ID: " + ase.getRequestId()); }