List of usage examples for com.amazonaws AmazonServiceException getStatusCode
public int getStatusCode()
From source file:io.relution.jenkins.awssqs.util.ErrorType.java
License:Apache License
/** * Returns a value indicating whether the specified service exception has the specified error * code and HTTP status.//from w w w . j a v a2 s.c om * @param e The {@link AmazonServiceException} to test. * @param errorCode The error code to match, can be {@code null}. * @param httpStatus The HTTP status to match. Use {@code -1} to match any HTTP status. * @return {@code true} if the specified exception has the specified error code and HTTP status; * otherwise, {@code false}. */ public static boolean is(final AmazonServiceException e, final String errorCode, final int httpStatus) { if (e == null) { return false; } if (errorCode != null && !StringUtils.equals(errorCode, e.getErrorCode())) { return false; } if (httpStatus != -1 && e.getStatusCode() != httpStatus) { return false; } return true; }
From source file:io.robrose.hop.watermap.aws.DynamoGeoClient.java
License:Open Source License
public static void main(String[] args) { init();/*from ww w . ja v a2 s . c o m*/ try { String tableName = "water-safe-locations-table"; config = new GeoDataManagerConfiguration(dynamoDB, tableName); geoDataManager = new GeoDataManager(config); // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, tableName)) { System.out.println("Table " + tableName + " is already ACTIVE"); } else { // Create a table with a primary hash key named 'name', which holds a string /* CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName) .withKeySchema(new KeySchemaElement().withAttributeName("name").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("name").withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest).getTableDescription(); */ //AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config); CreateTableResult createTableResult = dynamoDB.createTable(createTableRequest); System.out.println("Created Table: " + tableName); // Wait for it to become active System.out.println("Waiting for " + tableName + " to become ACTIVE..."); Tables.waitForTableToBecomeActive(dynamoDB, tableName); } // Describe our new table DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(tableName); TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); System.out.println("Table Description: " + tableDescription); Map<String, String> m = new HashMap<>(); m.put("lat", "51.5034070"); m.put("lng", "-0.1275920"); m.put("violationCode", "47"); // request = new JSONObject(m); //try { // putPoint(request); //}catch(JSONException f){ // System.out.println("Bad JSON"); //} // Scan items for movies with a year attribute greater than 1985 HashMap<String, Condition> scanFilter = new HashMap<>(); Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()) .withAttributeValueList(new AttributeValue().withN("1985")); scanFilter.put("year", condition); ScanRequest scanRequest = new ScanRequest(tableName);//.withScanFilter(scanFilter); ScanResult scanResult = dynamoDB.scan(scanRequest); System.out.println("Result: " + scanResult); } 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:io.starter.messaging.SNSMobilePush.java
License:Open Source License
public static void main(String[] args) throws IOException { /*//from w w w . j a v a 2s .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 */ String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY"; String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY"; if (awsAccessKey == null) awsAccessKey = AWS_ACCESS_KEY; if (awsSecretKey == null) awsSecretKey = AWS_SECRET_KEY; AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); AmazonSNS sns = new AmazonSNSClient( new PropertiesCredentials(SNSMobilePush.class.getResourceAsStream("AwsCredentials.properties"))); // AmazonSNS sns = new AmazonSNSClient(credentials); sns.setEndpoint("https://sns.us-west-2.amazonaws.com"); System.out.println("===========================================\n"); System.out.println("Initializing Communication with Amazon SNS"); System.out.println("===========================================\n"); try { SNSMobilePush sample = new SNSMobilePush(sns); /* TODO: Uncomment the services you wish to use. */ // sample.starterAndroidAppNotification(); // sample.starterKindleAppNotification(); sample.starterAppleAppNotification(); // sample.starterAppleSandboxAppNotification(); // sample.starterBaiduAppNotification(); // sample.starterWNSAppNotification(); // sample.starterMPNSAppNotification(); } 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:jetbrains.buildServer.util.amazon.AWSException.java
License:Apache License
@Nullable public static String getIdentity(@NotNull Throwable t) { if (t instanceof AWSException) return ((AWSException) t).getIdentity(); if (t instanceof AmazonServiceException) { final AmazonServiceException ase = (AmazonServiceException) t; return ase.getServiceName() + ase.getErrorType().name() + String.valueOf(ase.getStatusCode()) + ase.getErrorCode();/* w ww . java 2 s. co m*/ } return null; }
From source file:jetbrains.buildServer.util.amazon.AWSException.java
License:Apache License
@Nullable public static String getDetails(@NotNull Throwable t) { if (t instanceof AWSException) return ((AWSException) t).getDetails(); if (t instanceof AmazonServiceException) { final AmazonServiceException ase = (AmazonServiceException) t; return "\n" + "Service: " + ase.getServiceName() + "\n" + "HTTP Status Code: " + ase.getStatusCode() + "\n" + "AWS Error Code: " + ase.getErrorCode() + "\n" + "Error Type: " + ase.getErrorType() + "\n" + "Request ID: " + ase.getRequestId();/*from w w w . jav a 2 s . com*/ } return null; }
From source file:jp.dqneo.amazons3.sample.S3Sample.java
License:Open Source License
public static void main(String[] args) throws IOException { /*// w w w .j ava 2 s. com * Important: 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 */ AmazonS3 s3 = new AmazonS3Client( new PropertiesCredentials(S3Sample.class.getResourceAsStream("AwsCredentials.properties"))); s3.setEndpoint("https://s3-ap-northeast-1.amazonaws.com"); String bucketName = "my-first-s3-bucket-" + UUID.randomUUID(); String key = "2/foo/bar"; System.out.println("==========================================="); System.out.println("Getting Started with Amazon S3"); System.out.println("===========================================\n"); try { /* * 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"); PutObjectRequest p = new PutObjectRequest(bucketName, key, createSampleFile()); s3.putObject(p); System.out.println("ok\n"); } 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:main.java.ddb.loader.DDBLoaderUtils.java
License:Apache License
static void createTable() throws Exception { try {/*from w ww .jav a 2 s .c o m*/ CreateTableRequest create_req = new CreateTableRequest().withTableName(DDBSampleLoader.TBL_NAME) .withKeySchema(new KeySchemaElement().withAttributeName("Id").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("Id") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(DDBSampleLoader.RCU) .withWriteCapacityUnits(DDBSampleLoader.WCU)); DDBSampleLoader.log.info("Creating a new table ..."); TableUtils.createTableIfNotExists(DDBSampleLoader.ddb_client, create_req); DDBSampleLoader.log.info("Waiting for the table status to be 'ACTIVE' ..."); TableUtils.waitUntilActive(DDBSampleLoader.ddb_client, DDBSampleLoader.TBL_NAME); } catch (AmazonServiceException e) { DDBSampleLoader.log.error("Caught an AmazonServiceException ..."); DDBSampleLoader.log.error("Error Message: " + e.getMessage()); DDBSampleLoader.log.error("HTTP Status Code: " + e.getStatusCode()); DDBSampleLoader.log.error("AWS Error Code: " + e.getErrorCode()); DDBSampleLoader.log.error("Error Type: " + e.getErrorType()); DDBSampleLoader.log.error("Request ID: " + e.getRequestId()); } catch (AmazonClientException e) { DDBSampleLoader.log.error("Caught an AmazonClientException ..."); DDBSampleLoader.log.error("Error Message: " + e.getMessage()); } }
From source file:modules.storage.AmazonS3Storage.java
License:Open Source License
private void logAmazonServiceException(AmazonServiceException ase) { logger.error("Caught an AmazonServiceException, which " + "means your request made it " + "to Amazon S3, but was rejected with an error response " + "for some reason." + " Error Message: " + ase.getMessage() + " HTTP Status Code: " + ase.getStatusCode() + " AWS Error Code: " + ase.getErrorCode() + " Error Type: " + ase.getErrorType() + " Request ID: " + ase.getRequestId(), ase);// w w w.j a va 2 s .c o m }
From source file:n3phele.storage.s3.CloudStorageImpl.java
License:Open Source License
public boolean createBucket(Repository repo) throws ForbiddenException { Credential credential = repo.getCredential().decrypt(); AmazonS3Client s3 = new AmazonS3Client( new BasicAWSCredentials(credential.getAccount(), credential.getSecret())); s3.setEndpoint(repo.getTarget().toString()); try {/*from w w w. j a v a 2s .co m*/ try { s3.listObjects(new ListObjectsRequest(repo.getRoot(), null, null, null, 0)); // it exists and the current account owns it return false; } catch (AmazonServiceException ase) { switch (ase.getStatusCode()) { case 403: /* * A permissions error means the bucket exists, but is owned by * another account. */ throw new ForbiddenException( "Bucket " + repo.getRoot() + " has already been created by another user."); case 404: Bucket bucket = s3.createBucket(repo.getRoot()); log.info("Bucket created " + bucket.getName()); return true; default: throw ase; } } } catch (AmazonServiceException e) { log.log(Level.WARNING, "Service Error processing " + repo, e); } catch (AmazonClientException e) { log.log(Level.SEVERE, "Client Error processing " + repo, e); } return false; }
From source file:net.oletalk.hellospringboot.dao.S3Dao.java
public void uploadFile(String bucketName, String key, File file) throws S3Exception { AmazonS3 s3client = new AmazonS3Client(new ClasspathPropertiesFileCredentialsProvider()); try {/* w w w. j ava2 s .com*/ LOG.info("Uploading file to S3"); s3client.putObject(new PutObjectRequest(bucketName, key, file)); } catch (AmazonServiceException ase) { LOG.error("Problem uploading file to S3: " + ase.getMessage() + " (status code " + ase.getStatusCode() + ")"); throw new S3Exception("Problem uploading file to S3"); } catch (AmazonClientException ace) { LOG.error("Internal error uploading file to S3: " + ace.getMessage()); throw new S3Exception("Problem uploading file to S3"); } LOG.info("Upload complete"); }