List of usage examples for com.amazonaws AmazonServiceException getErrorType
public ErrorType getErrorType()
From source file:com.aws.sns.service.notifications.sns.SNSMobilePush.java
License:Open Source License
public static void main(String[] args) throws IOException { /*/*from w w w . j a v a2s . c om*/ * 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 www . j a v a2 s . c om 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 w w w. ja v a 2s.c o 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.climate.oada.dao.impl.S3ResourceDAO.java
License:Open Source License
/** * Log AWSServiceException details./*from ww w . ja v a 2 s . c om*/ * * @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()); }
From source file:com.cloudbees.gasp.services.APNRegistrationService.java
License:Apache License
@POST @Path("register") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response doRegister(@FormParam("token") String token) { try {/*from www. jav a 2 s .c om*/ // Create an SNS app endpoint CreatePlatformEndpointResult platformEndpointResult = snsMobile .createPlatformEndpoint("Gasp APN Platform Endpoint", token, snsMobile.getApnPlatformArn()); APNDataStore.registerArn(token, platformEndpointResult.getEndpointArn()); LOGGER.info("Registered: " + platformEndpointResult.getEndpointArn()); } catch (AmazonServiceException ase) { LOGGER.debug("AmazonServiceException"); LOGGER.debug(" Error Message: " + ase.getMessage()); LOGGER.debug(" HTTP Status Code: " + ase.getStatusCode()); LOGGER.debug(" AWS Error Code: " + ase.getErrorCode()); LOGGER.debug(" Error Type: " + ase.getErrorType()); LOGGER.debug(" Request ID: " + ase.getRequestId()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (AmazonClientException ace) { LOGGER.debug("AmazonClientException"); LOGGER.debug(" Error Message: " + ace.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).build(); }
From source file:com.cloudbees.gasp.services.APNRegistrationService.java
License:Apache License
@POST @Path("unregister") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response doUnregister(@FormParam("token") String token) { try {// www .j av a2 s .c o m // Delete the SNS app endpoint snsMobile.deleteEndpointArn(APNDataStore.getEndpointArn(token)); LOGGER.info("Deleted endpoint: " + APNDataStore.getEndpointArn(token)); APNDataStore.unregisterArn(token); LOGGER.info("Unregistered device: " + token); } catch (AmazonServiceException ase) { LOGGER.debug("AmazonServiceException"); LOGGER.debug(" Error Message: " + ase.getMessage()); LOGGER.debug(" HTTP Status Code: " + ase.getStatusCode()); LOGGER.debug(" AWS Error Code: " + ase.getErrorCode()); LOGGER.debug(" Error Type: " + ase.getErrorType()); LOGGER.debug(" Request ID: " + ase.getRequestId()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (AmazonClientException ace) { LOGGER.debug("AmazonClientException"); LOGGER.debug(" Error Message: " + ace.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).build(); }
From source file:com.cloudbees.gasp.services.DataSyncService.java
License:Apache License
private void sendPushNotifications(String messageText) { try {/*from w w w . j a v a 2 s. c o m*/ SNSMobile snsMobile = new SNSMobile(); // Send update to all registered APN endpoints for (String endpointArn : APNDataStore.getEndpoints()) { LOGGER.info("Sending update to APN endpoint ARN: " + endpointArn); snsMobile.pushNotification(SNSMobile.Platform.APNS_SANDBOX, endpointArn, getApnMessage(messageText)); } // Send update to all registered GCM endpoints for (String endpointArn : GCMDataStore.getEndpoints()) { LOGGER.info("Sending update to GCM endpoint ARN: " + endpointArn); snsMobile.pushNotification(SNSMobile.Platform.GCM, endpointArn, getGcmMessage(messageText)); } } catch (AmazonServiceException ase) { LOGGER.debug("AmazonServiceException"); LOGGER.debug(" Error Message: " + ase.getMessage()); LOGGER.debug(" HTTP Status Code: " + ase.getStatusCode()); LOGGER.debug(" AWS Error Code: " + ase.getErrorCode()); LOGGER.debug(" Error Type: " + ase.getErrorType()); LOGGER.debug(" Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { LOGGER.debug("AmazonClientException"); LOGGER.debug(" Error Message: " + ace.getMessage()); } catch (Exception e) { return; } }
From source file:com.cloudbees.gasp.services.GCMRegistrationService.java
License:Apache License
@POST @Path("register") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response doRegister(@FormParam("regId") String regId) { try {/*from www. ja va2 s. c o m*/ CreatePlatformEndpointResult platformEndpointResult = snsMobile .createPlatformEndpoint("Gasp GCM Platform Endpoint", regId, snsMobile.getGcmPlatformArn()); GCMDataStore.registerArn(regId, platformEndpointResult.getEndpointArn()); LOGGER.info("Registered: " + platformEndpointResult.getEndpointArn()); } catch (AmazonServiceException ase) { LOGGER.debug("AmazonServiceException"); LOGGER.debug(" Error Message: " + ase.getMessage()); LOGGER.debug(" HTTP Status Code: " + ase.getStatusCode()); LOGGER.debug(" AWS Error Code: " + ase.getErrorCode()); LOGGER.debug(" Error Type: " + ase.getErrorType()); LOGGER.debug(" Request ID: " + ase.getRequestId()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (AmazonClientException ace) { LOGGER.debug("AmazonClientException"); LOGGER.debug(" Error Message: " + ace.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).build(); }
From source file:com.cloudbees.gasp.services.GCMRegistrationService.java
License:Apache License
@POST @Path("unregister") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response doUnregister(@FormParam("regId") String regId) { try {//w ww . j a v a2 s .com // Delete the SNS app endpoint snsMobile.deleteEndpointArn(GCMDataStore.getEndpointArn(regId)); LOGGER.info("Deleted endpoint: " + GCMDataStore.getEndpointArn(regId)); GCMDataStore.unregisterArn(regId); LOGGER.info("Unregistered device: " + regId); } catch (AmazonServiceException ase) { LOGGER.debug("AmazonServiceException"); LOGGER.debug(" Error Message: " + ase.getMessage()); LOGGER.debug(" HTTP Status Code: " + ase.getStatusCode()); LOGGER.debug(" AWS Error Code: " + ase.getErrorCode()); LOGGER.debug(" Error Type: " + ase.getErrorType()); LOGGER.debug(" Request ID: " + ase.getRequestId()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (AmazonClientException ace) { LOGGER.debug("AmazonClientException"); LOGGER.debug(" Error Message: " + ace.getMessage()); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).build(); }
From source file:com.cloudhub.aws.extractor.AWSCSVExtractor.java
License:Apache License
/** * Requests billing information from Amazon S3. * This method may spawn multiple threads as needed to complete the task. * *//*from ww w . j av a 2s . co m*/ @Override public String getTotalCost() { String totalCost = null; try { log.debug("Listing objects ..."); final ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName); ObjectListing objectListing; do { objectListing = s3client.listObjects(listObjectsRequest); for (final S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { log.debug(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); if (objectSummary.getKey().contains(Constants.MATCHER_BILLING_CSV.getKeyPattern())) { totalCost = persist(Constants.MATCHER_BILLING_CSV, objectSummary); } else if (objectSummary.getKey().contains(Constants.MATCHER_COST_ALLOCATION.getKeyPattern())) { totalCost = persist(Constants.MATCHER_COST_ALLOCATION, objectSummary); } } listObjectsRequest.setMarker(objectListing.getNextMarker()); } while (objectListing.isTruncated()); } catch (AmazonServiceException ase) { log.error("Caught an AmazonServiceException, " + "which means your request made it " + "to Amazon S3, but was rejected with an error response " + "for some reason."); 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()); } catch (AmazonClientException ace) { log.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."); log.error("Error Message: " + ace.getMessage()); } catch (IOException ioe) { log.error("Caught an IOException while writing to disk."); log.error("Error Message: " + ioe.getMessage()); } return totalCost; }