List of usage examples for com.amazonaws AmazonServiceException getErrorType
public ErrorType getErrorType()
From source file:com.crickdata.upload.s3.UploadLiveData.java
License:Open Source License
public Map<String, Date> uploadToS3(String fileName, boolean type) throws IOException { Statistics statistics = new Statistics(); Map<String, Date> perfMap = new HashMap<String, Date>(); AWSCredentials credentials = null;/*from w w w . jav a 2s . c om*/ try { credentials = new BasicAWSCredentials("AKIAI6QKTRAQE7MXQOIQ", "wIG6u1yI5ZaseeJbvYSUmD98qelIJNSCVBzt5k2q"); } 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 (C:\\Users\\bssan_000\\.aws\\credentials), and is in valid format.", e); } AmazonS3 s3 = new AmazonS3Client(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); s3.setRegion(usWest2); String bucketName; if (!type) bucketName = "cricmatchinfo"; else bucketName = "cricmatchinfoseries"; String key = fileName.replace(".json", "").trim(); try { perfMap.put("S3INSERTREQ", new Date()); statistics.setS3Req(new Date()); File f = readMatchFile(fileName); double bytes = f.length(); double kilobytes = (bytes / 1024); System.out.println("Details :" + kilobytes); s3.putObject(new PutObjectRequest(bucketName, key, f)); statistics.setSize(String.valueOf(kilobytes)); S3Object object = s3.getObject(new GetObjectRequest(bucketName, key)); perfMap.put("S3SAVERES", object.getObjectMetadata().getLastModified()); statistics.setKey(key); statistics.setS3Res(object.getObjectMetadata().getLastModified()); MyUI.stats.add(statistics); displayTextInputStream(object.getObjectContent()); ObjectListing objectListing = s3 .listObjects(new ListObjectsRequest().withBucketName(bucketName).withPrefix("My")); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { System.out.println( " - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")"); } } 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()); } return perfMap; }
From source file:com.davidgildeh.hadoop.input.simpledb.SimpleDBDAO.java
License:Apache License
/** * Does a paged query in SimpleDB/* ww w . ja va 2 s .com*/ * * @param query The Select Query * @param nextToken If there is a paging token to start from, or null if none * @return The SelectResult from the query */ private SelectResult doQuery(String query, String nextToken) { SelectResult results = null; try { if (LOG.isDebugEnabled()) { LOG.debug("Running Query: " + query); } SelectRequest selectRequest = new SelectRequest(query); if (nextToken != null) { selectRequest.setNextToken(nextToken); } results = sdb.select(selectRequest); } catch (AmazonServiceException ase) { LOG.error("Caught an AmazonServiceException, which means your request made it " + "to Amazon SimpleDB, but was rejected with an error response for some reason."); LOG.error("Select Query: " + query); 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 " + "a serious internal problem while trying to communicate with SimpleDB, " + "such as not being able to access the network."); LOG.error("Error Message: " + ace.getMessage()); } finally { return results; } }
From source file:com.dev.appx.sns.SNSMobilePush.java
License:Open Source License
public static void igniteSNS() throws IOException { /*/*from w ww . j a v a2s . c o 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. */ //sample.demoAndroidAppNotification(); // sample.demoKindleAppNotification(); // sample.demoAppleAppNotification(); // sample.demoAppleSandboxAppNotification(); // sample.demoBaiduAppNotification(); // sample.demoWNSAppNotification(); // sample.demoMPNSAppNotification(); sample.createTopic("test"); } 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.digitaslbi.helios.mock.utils.ConnectionHelper.java
public static void createFolder(String bucketName, String folderName) { // create meta-data for your folder and set content-length to 0 ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(0);/*from w w w . jav a2 s .c o m*/ // create empty content InputStream emptyContent = new ByteArrayInputStream(new byte[0]); // create a PutObjectRequest passing the folder name suffixed by / PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, folderName + MocksConstants.AWS_PARENT_DELIMITER.getValue(), emptyContent, metadata); // send request to S3 to create folder try { s3Client.putObject(putObjectRequest); } 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()); } }
From source file:com.digitaslbi.helios.mock.utils.ConnectionHelper.java
public static void uploadFile(String bucketName, String folderName, String filePath) { try {//from ww w. j a v a 2s.c o m log.debug("Uploading a new object to S3 from a file\n"); java.io.File file = new java.io.File(filePath); s3Client.putObject(new PutObjectRequest(bucketName, folderName, file) .withCannedAcl(CannedAccessControlList.PublicRead)); } 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()); } }
From source file:com.digitaslbi.helios.mock.utils.ConnectionHelper.java
public static void deleteFolder(String bucketName, String folderName) { List<S3ObjectSummary> fileList = s3Client.listObjects(bucketName, folderName).getObjectSummaries(); try {/* w w w . j a va2s .c o m*/ for (S3ObjectSummary file : fileList) { s3Client.deleteObject(bucketName, file.getKey()); } s3Client.deleteObject(bucketName, folderName); } catch (AmazonServiceException ase) { log.error("Caught an AmazonServiceException."); 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."); log.error("Error Message: " + ace.getMessage()); } }
From source file:com.digitaslbi.helios.mock.utils.ConnectionHelper.java
public static InputStream getObject(String key) { try {/*from w w w.j av a2 s.co m*/ log.debug("Downloading an object"); S3Object s3object = s3Client.getObject( new GetObjectRequest(prop.getProperty(MocksConstants.AWS_BUCKET_NAME.getValue()), key)); log.debug("Content-Type: " + s3object.getObjectMetadata().getContentType()); //displayTextInputStream(s3object.getObjectContent()); return s3object.getObjectContent(); } 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()); } return null; }
From source file:com.digitaslbi.helios.utils.S3Helper.java
public static void createFolder(String folderName) { connect();//from ww w. ja v a 2 s . com // create meta-data for your folder and set content-length to 0 ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(0); // create empty content InputStream emptyContent = new ByteArrayInputStream(new byte[0]); // create a PutObjectRequest passing the folder name suffixed by / PutObjectRequest putObjectRequest = new PutObjectRequest(S3Properties.getInstance().getBucketName(), folderName + Constants.AWS_PARENT_DELIMITER.getValue(), emptyContent, metadata); // send request to S3 to create folder try { s3Client.putObject(putObjectRequest); } catch (AmazonServiceException ase) { log.error("[S3Helper][createFolder] 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("[S3Helper][createFolder] 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()); } }
From source file:com.digitaslbi.helios.utils.S3Helper.java
public static void uploadFile(String fileName, byte[] content) { connect();//from ww w. j a v a2 s . c o m ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(content.length); try { log.info("[S3Helper][uploadFile] Uploading a new object to S3: " + fileName); PutObjectRequest putObjectRequest = new PutObjectRequest(S3Properties.getInstance().getBucketName(), fileName, new ByteArrayInputStream(content), metadata); putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead); s3Client.putObject(putObjectRequest); } catch (AmazonServiceException ase) { log.error("[S3Helper][uploadFile] 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("[S3Helper][uploadFile] 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()); } }
From source file:com.digitaslbi.helios.utils.S3Helper.java
public static void deleteFolder(String folderName) { connect();/* w w w . ja v a 2 s. co m*/ List<S3ObjectSummary> fileList = s3Client .listObjects(S3Properties.getInstance().getBucketName(), folderName).getObjectSummaries(); try { for (S3ObjectSummary file : fileList) { s3Client.deleteObject(S3Properties.getInstance().getBucketName(), file.getKey()); } s3Client.deleteObject(S3Properties.getInstance().getBucketName(), folderName); } catch (AmazonServiceException ase) { log.error("[S3Helper][deleteFolder] Caught an AmazonServiceException."); 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("[S3Helper][deleteFolder] Caught an AmazonClientException."); log.error("Error Message: " + ace.getMessage()); } }