List of usage examples for com.amazonaws AmazonServiceException getErrorCode
public String getErrorCode()
From source file:ch.cyberduck.core.threading.BackgroundException.java
License:Open Source License
/** * @return Detailed message from the underlying cause. *//*from w w w . j a v a 2s . com*/ public String getDetailedCauseMessage() { final Throwable cause = this.getCause(); StringBuilder buffer = new StringBuilder(); if (null != cause) { if (StringUtils.isNotBlank(cause.getMessage())) { String m = StringUtils.chomp(cause.getMessage()); buffer.append(m); if (!m.endsWith(".")) { buffer.append("."); } } if (cause instanceof ServiceException) { final ServiceException s3 = (ServiceException) cause; if (StringUtils.isNotBlank(s3.getResponseStatus())) { // HTTP method status buffer.append(" ").append(s3.getResponseStatus()).append("."); } if (StringUtils.isNotBlank(s3.getErrorMessage())) { // S3 protocol message buffer.append(" ").append(s3.getErrorMessage()); } } else if (cause instanceof SardineException) { final SardineException http = (SardineException) cause; if (StringUtils.isNotBlank(http.getResponsePhrase())) { buffer.delete(0, buffer.length()); // HTTP method status buffer.append(http.getResponsePhrase()).append("."); } } else if (cause instanceof org.jets3t.service.impl.rest.HttpException) { final org.jets3t.service.impl.rest.HttpException http = (org.jets3t.service.impl.rest.HttpException) cause; buffer.append(" ").append(http.getResponseCode()); if (StringUtils.isNotBlank(http.getResponseMessage())) { buffer.append(" ").append(http.getResponseMessage()); } } else if (cause instanceof CloudFrontServiceException) { final CloudFrontServiceException cf = (CloudFrontServiceException) cause; if (StringUtils.isNotBlank(cf.getErrorMessage())) { buffer.append(" ").append(cf.getErrorMessage()); } if (StringUtils.isNotBlank(cf.getErrorDetail())) { buffer.append(" ").append(cf.getErrorDetail()); } } else if (cause instanceof FilesException) { final FilesException cf = (FilesException) cause; final StatusLine status = cf.getHttpStatusLine(); if (null != status) { if (StringUtils.isNotBlank(status.getReasonPhrase())) { buffer.append(" ").append(status.getReasonPhrase()); } } } else if (cause instanceof AmazonServiceException) { final AmazonServiceException a = (AmazonServiceException) cause; final String status = a.getErrorCode(); if (StringUtils.isNotBlank(status)) { buffer.append(" ").append(status); } } } String message = buffer.toString(); if (!StringUtils.isEmpty(message)) { if (Character.isLetter(message.charAt(message.length() - 1))) { message = message + "."; } } return Locale.localizedString(message, "Error"); }
From source file:Cloud.Tweets.SimpleQueueServiceSample.java
License:Open Source License
public void addmessage(AmazonSQS abc, String x) { System.out.println("Sending a message to MyQueue.\n" + myQueueUrl); try {/*from www. j a v a 2s . co m*/ System.out.println(x); abc.sendMessage(new SendMessageRequest(myQueueUrl, x)); System.out.println("Message Sent.\n"); } 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:cloudExplorer.BucketClass.java
License:Open Source License
String makeBucket(String access_key, String secret_key, String bucket, String endpoint, String region) { String message = null;//from w ww.j a v a 2 s .co m AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration().withSignerOverride("S3SignerType")); s3Client.setEndpoint(endpoint); try { if (endpoint.contains("amazon")) { s3Client.createBucket(new CreateBucketRequest(bucket)); } else { s3Client.createBucket(new CreateBucketRequest(bucket, region)); } message = ("\nAttempting to create the bucket. Please view the Bucket list window for an update."); } catch (AmazonServiceException ase) { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + ase.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + ase.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + ase.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + ase.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + ase.getMessage()); System.out.print("\nHTTP Status Code: " + ase.getStatusCode()); System.out.print("\nAWS Error Code: " + ase.getErrorCode()); System.out.print("\nError Type: " + ase.getErrorType()); System.out.print("\nRequest ID: " + ase.getRequestId()); } } if (message == null) { message = "Failed to create bucket."; } return message; }
From source file:cloudExplorer.BucketClass.java
License:Open Source License
String listBuckets(String access_key, String secret_key, String endpoint) { AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration().withSignerOverride("S3SignerType")); s3Client.setEndpoint(endpoint);/* ww w .ja v a2 s.c o m*/ String[] array = new String[10]; String bucketlist = null; int i = 0; try { for (Bucket bucket : s3Client.listBuckets()) { bucketlist = bucketlist + " " + bucket.getName(); } } catch (AmazonServiceException ase) { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + ase.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + ase.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + ase.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + ase.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + ase.getMessage()); System.out.print("\nHTTP Status Code: " + ase.getStatusCode()); System.out.print("\nAWS Error Code: " + ase.getErrorCode()); System.out.print("\nError Type: " + ase.getErrorType()); System.out.print("\nRequest ID: " + ase.getRequestId()); } } catch (Exception lsbuckets) { if (lsbuckets.getMessage().contains("peer not authenticated") || lsbuckets.getMessage().contains("hostname in certificate didn't match")) { if (NewJFrame.gui) { mainFrame.jTextArea1.append( "\nError: This program does not support non-trusted SSL certificates\n\nor your SSL certificates are incorrect."); } else { System.out.print( "\n\nError: This program does not support non-trusted SSL certificates\n\nor your SSL certificates are not correctly installed."); } } } String parse = null; if (bucketlist != null) { parse = bucketlist.replace("null", ""); } else { parse = "no_bucket_found"; } return parse; }
From source file:cloudExplorer.Delete.java
License:Open Source License
public void run() { AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration().withSignerOverride("S3SignerType")); s3Client.setEndpoint(endpoint);//from www . jav a2 s. co m try { if (version != null) { s3Client.deleteVersion(new DeleteVersionRequest(bucket, what, version)); } else { s3Client.deleteObject(new DeleteObjectRequest(bucket, what)); } if (!debug) { NewJFrame.jTextArea1.append("\nDeleted object: " + what); } calibrate(); } catch (AmazonServiceException ase) { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + ase.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + ase.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + ase.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + ase.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + ase.getMessage()); System.out.print("\nHTTP Status Code: " + ase.getStatusCode()); System.out.print("\nAWS Error Code: " + ase.getErrorCode()); System.out.print("\nError Type: " + ase.getErrorType()); System.out.print("\nRequest ID: " + ase.getRequestId()); } } catch (Exception delete) { } }
From source file:cloudExplorer.Get.java
License:Open Source License
public void run() { String message = null;//from www. j a va 2 s .c o m AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); File file = new File(what); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration().withSignerOverride("S3SignerType")); s3Client.setEndpoint(endpoint); try { long t1 = System.currentTimeMillis(); S3Object s3object = s3Client.getObject(new GetObjectRequest(bucket, what, version)); InputStream objectData = s3object.getObjectContent(); this.writeFile(objectData, destination); long t2 = System.currentTimeMillis(); long diff = t2 - t1; if (!mainFrame.perf) { if (terminal) { System.out.print("\nDownloaded: " + what + " in " + diff / 1000 + " second(s).\n"); } else { mainFrame.jTextArea1.append("\nDownloaded: " + what + " in " + diff / 1000 + " second(s)."); mainFrame.calibrateTextArea(); } } } catch (AmazonServiceException ase) { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + ase.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + ase.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + ase.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + ase.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + ase.getMessage()); System.out.print("\nHTTP Status Code: " + ase.getStatusCode()); System.out.print("\nAWS Error Code: " + ase.getErrorCode()); System.out.print("\nError Type: " + ase.getErrorType()); System.out.print("\nRequest ID: " + ase.getRequestId()); } } catch (Exception get) { } calibrate(); }
From source file:cloudExplorer.Put.java
License:Open Source License
public void run() { try {//from ww w . j av a 2s . co m AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration().withSignerOverride("S3SignerType")); s3Client.setEndpoint(endpoint); TransferManager tx = new TransferManager(s3Client); File file = new File(what); PutObjectRequest putRequest; if (!rrs) { putRequest = new PutObjectRequest(bucket, ObjectKey, file); } else { putRequest = new PutObjectRequest(bucket, ObjectKey, file) .withStorageClass(StorageClass.ReducedRedundancy); } MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap(); String mimeType = mimeTypesMap.getContentType(file); mimeType = mimeTypesMap.getContentType(file); ObjectMetadata objectMetadata = new ObjectMetadata(); if (encrypt) { objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); } if ((ObjectKey.contains(".html")) || ObjectKey.contains(".txt")) { objectMetadata.setContentType("text/html"); } else { objectMetadata.setContentType(mimeType); } long t1 = System.currentTimeMillis(); putRequest.setMetadata(objectMetadata); Upload myUpload = tx.upload(putRequest); myUpload.waitForCompletion(); tx.shutdownNow(); long t2 = System.currentTimeMillis(); long diff = t2 - t1; if (!mainFrame.perf) { if (terminal) { System.out.print("\nUploaded object: " + ObjectKey + " in " + diff / 1000 + " second(s).\n"); } else { mainFrame.jTextArea1 .append("\nUploaded object: " + ObjectKey + " in " + diff / 1000 + " second(s)."); } } } catch (AmazonServiceException ase) { if (NewJFrame.gui) { mainFrame.jTextArea1.append("\n\nError Message: " + ase.getMessage()); mainFrame.jTextArea1.append("\nHTTP Status Code: " + ase.getStatusCode()); mainFrame.jTextArea1.append("\nAWS Error Code: " + ase.getErrorCode()); mainFrame.jTextArea1.append("\nError Type: " + ase.getErrorType()); mainFrame.jTextArea1.append("\nRequest ID: " + ase.getRequestId()); calibrate(); } else { System.out.print("\n\nError Message: " + ase.getMessage()); System.out.print("\nHTTP Status Code: " + ase.getStatusCode()); System.out.print("\nAWS Error Code: " + ase.getErrorCode()); System.out.print("\nError Type: " + ase.getErrorType()); System.out.print("\nRequest ID: " + ase.getRequestId()); } } catch (Exception put) { } calibrate(); }
From source file:cloudworker.DynamoDBService.java
License:Apache License
private static void createTable() throws Exception { try {/*from ww w .j a v a 2 s . c o m*/ // Create table if it does not exist yet if (Tables.doesTableExist(dynamoDB, TABLE_NAME)) { //System.out.println("Table " + TABLE_NAME + " is already ACTIVE"); } else { // Create a table with a primary hash key named 'taskID', which holds a string CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(TABLE_NAME) .withKeySchema(new KeySchemaElement().withAttributeName("taskID").withKeyType(KeyType.HASH)) .withAttributeDefinitions(new AttributeDefinition().withAttributeName("taskID") .withAttributeType(ScalarAttributeType.S)) .withProvisionedThroughput( new ProvisionedThroughput().withReadCapacityUnits(1L).withWriteCapacityUnits(1L)); TableDescription tableDescription = dynamoDB.createTable(createTableRequest).getTableDescription(); //System.out.println("Created Table: " + tableDescription); // Wait for it to become active //System.out.println("Waiting for " + TABLE_NAME + " to become ACTIVE..."); Tables.waitForTableToBecomeActive(dynamoDB, TABLE_NAME); } // Describe our new table // DescribeTableRequest describeTableRequest = new DescribeTableRequest().withTableName(TABLE_NAME); // TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable(); // System.out.println("Table Description: " + tableDescription); } 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.acer.batterycapacitydemo.CognitoSyncClientManager.java
License:Open Source License
public boolean wipeCredentialsOnAuthError(AmazonServiceException ex) { Log.e(LOG_TAG, "Error, wipeCredentialsOnAuthError called" + ex); if (/*w ww.j a v a2s.c om*/ // STS // http://docs.amazonwebservices.com/STS/latest/APIReference/CommonErrors.html ex.getErrorCode().equals("IncompleteSignature") || ex.getErrorCode().equals("InternalFailure") || ex.getErrorCode().equals("InvalidClientTokenId") || ex.getErrorCode().equals("OptInRequired") || ex.getErrorCode().equals("RequestExpired") || ex.getErrorCode().equals("ServiceUnavailable") // DynamoDB // http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/ErrorHandling.html#APIErrorTypes || ex.getErrorCode().equals("AccessDeniedException") || ex.getErrorCode().equals("IncompleteSignatureException") || ex.getErrorCode().equals("MissingAuthenticationTokenException") || ex.getErrorCode().equals("ValidationException") || ex.getErrorCode().equals("InternalFailure") || ex.getErrorCode().equals("InternalServerError")) { return true; } return false; }
From source file:com.ad.mediasharing.awsclientmanager.AmazonClientManager.java
License:Open Source License
public boolean wipeCredentialsOnAuthError(AmazonServiceException ex) { if (//w w w . j a v a2 s.c o m // For S3 // http://docs.amazonwebservices.com/AmazonS3/latest/API/ErrorResponses.html#ErrorCodeList ex.getErrorCode().equals("AccessDenied") || ex.getErrorCode().equals("BadDigest") || ex.getErrorCode().equals("CredentialsNotSupported") || ex.getErrorCode().equals("ExpiredToken") || ex.getErrorCode().equals("InternalError") || ex.getErrorCode().equals("InvalidAccessKeyId") || ex.getErrorCode().equals("InvalidPolicyDocument") || ex.getErrorCode().equals("InvalidToken") || ex.getErrorCode().equals("NotSignedUp") || ex.getErrorCode().equals("RequestTimeTooSkewed") || ex.getErrorCode().equals("SignatureDoesNotMatch") || ex.getErrorCode().equals("TokenRefreshRequired")) { clearCredentials(); return true; } return false; }