List of usage examples for com.amazonaws AmazonServiceException getMessage
@Override
public String getMessage()
From source file:net.firejack.aws.web.controller.AWSController.java
License:Apache License
@ExceptionHandler(AmazonServiceException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public ModelAndView handleAllExceptions(AmazonServiceException ex) { String message = ex.getMessage(); return new ModelAndView(new MappingJacksonJsonView(), Collections.singletonMap("error", message.replaceAll(".*?AWS Error Message: ", ""))); }
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 {/*from ww w.jav a 2 s . c o m*/ 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"); }
From source file:net.roboconf.iaas.ec2.IaasEc2.java
License:Apache License
@Override public void terminateVM(String instanceId) throws IaasException { try {/*from w w w . j a v a 2 s .c o m*/ TerminateInstancesRequest terminateInstancesRequest = new TerminateInstancesRequest(); terminateInstancesRequest.withInstanceIds(instanceId); this.ec2.terminateInstances(terminateInstancesRequest); } catch (AmazonServiceException e) { this.logger.severe("An error occurred on Amazon while terminating the machine. " + e.getMessage()); throw new IaasException(e); } catch (AmazonClientException e) { this.logger.severe("An error occurred while terminating a machine on Amazon EC2. " + e.getMessage()); throw new IaasException(e); } }
From source file:net.roboconf.target.ec2.internal.Ec2IaasHandler.java
License:Apache License
@Override public boolean isMachineRunning(TargetHandlerParameters parameters, String machineId) throws TargetException { boolean result = false; try {/*from www. j a v a 2 s . com*/ AmazonEC2 ec2 = createEc2Client(parameters.getTargetProperties()); DescribeInstancesRequest dis = new DescribeInstancesRequest(); dis.setInstanceIds(Collections.singletonList(machineId)); DescribeInstancesResult disresult = ec2.describeInstances(dis); result = !disresult.getReservations().isEmpty(); } catch (AmazonServiceException e) { // nothing, the instance does not exist } catch (AmazonClientException e) { this.logger.severe("An error occurred while checking whether a machine is running on Amazon EC2. " + e.getMessage()); throw new TargetException(e); } return result; }
From source file:net.roboconf.target.ec2.internal.Ec2IaasHandler.java
License:Apache License
@Override public String retrievePublicIpAddress(TargetHandlerParameters parameters, String machineId) throws TargetException { String result = null;//from www .ja va 2 s. c o m try { AmazonEC2 ec2 = createEc2Client(parameters.getTargetProperties()); DescribeInstancesRequest dis = new DescribeInstancesRequest(); dis.setInstanceIds(Collections.singletonList(machineId)); DescribeInstancesResult disresult = ec2.describeInstances(dis); if (!disresult.getReservations().isEmpty()) { // Only one instance should match this machine ID result = disresult.getReservations().get(0).getInstances().get(0).getPublicIpAddress(); } } catch (AmazonServiceException e) { // nothing, the instance does not exist } catch (Exception e) { this.logger.severe( "An error occurred while retrieving a public IP address from Amazon EC2. " + e.getMessage()); throw new TargetException(e); } return result; }
From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java
License:Open Source License
@Override public Set<S3ObjectReference> listObjects(String prefix) throws IOException { AmazonS3 client = getClient();/*from w w w .j av a 2s .c om*/ Set<S3ObjectReference> result = new LinkedHashSet<>(100); try { final ListObjectsV2Request req = new ListObjectsV2Request(); req.setBucketName(bucketName); req.setMaxKeys(maximumKeysPerRequest); req.setPrefix(prefix); ListObjectsV2Result listResult; do { listResult = client.listObjectsV2(req); for (S3ObjectSummary objectSummary : listResult.getObjectSummaries()) { result.add(new S3ObjectReference(objectSummary.getKey(), objectSummary.getSize(), objectSummary.getLastModified())); } req.setContinuationToken(listResult.getNextContinuationToken()); } while (listResult.isTruncated() == true); } catch (AmazonServiceException e) { log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(), e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId()); throw new RemoteServiceException("Error listing S3 objects at " + prefix, e); } catch (AmazonClientException e) { log.debug("Error communicating with AWS: {}", e.getMessage()); throw new IOException("Error communicating with AWS", e); } return result; }
From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java
License:Open Source License
@Override public String getObjectAsString(String key) throws IOException { AmazonS3 client = getClient();/* w w w . j a va 2 s . com*/ try { return client.getObjectAsString(bucketName, key); } catch (AmazonServiceException e) { log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(), e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId()); throw new RemoteServiceException("Error getting S3 object at " + key, e); } catch (AmazonClientException e) { log.debug("Error communicating with AWS: {}", e.getMessage()); throw new IOException("Error communicating with AWS", e); } }
From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java
License:Open Source License
@Override public S3Object getObject(String key) throws IOException { AmazonS3 client = getClient();// w ww . j ava 2 s . co m try { return client.getObject(bucketName, key); } catch (AmazonServiceException e) { log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(), e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId()); throw new RemoteServiceException("Error getting S3 object at " + key, e); } catch (AmazonClientException e) { log.debug("Error communicating with AWS: {}", e.getMessage()); throw new IOException("Error communicating with AWS", e); } }
From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java
License:Open Source License
@Override public S3ObjectReference putObject(String key, InputStream in, ObjectMetadata objectMetadata) throws IOException { AmazonS3 client = getClient();/* w w w. jav a 2s.c o m*/ try { PutObjectRequest req = new PutObjectRequest(bucketName, key, in, objectMetadata); client.putObject(req); return new S3ObjectReference(key, objectMetadata.getContentLength(), objectMetadata.getLastModified()); } catch (AmazonServiceException e) { log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(), e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId()); throw new RemoteServiceException("Error putting S3 object at " + key, e); } catch (AmazonClientException e) { log.debug("Error communicating with AWS: {}", e.getMessage()); throw new IOException("Error communicating with AWS", e); } }
From source file:net.solarnetwork.node.backup.s3.SdkS3Client.java
License:Open Source License
@Override public void deleteObjects(Set<String> keys) throws IOException { AmazonS3 client = getClient();// w ww .j av a 2 s .c o m try { DeleteObjectsRequest req = new DeleteObjectsRequest(bucketName) .withKeys(keys.stream().map(k -> new KeyVersion(k)).collect(Collectors.toList())); client.deleteObjects(req); } catch (AmazonServiceException e) { log.warn("AWS error: {}; HTTP code {}; AWS code {}; type {}; request ID {}", e.getMessage(), e.getStatusCode(), e.getErrorCode(), e.getErrorType(), e.getRequestId()); throw new RemoteServiceException("Error deleting S3 objects " + keys, e); } catch (AmazonClientException e) { log.debug("Error communicating with AWS: {}", e.getMessage()); throw new IOException("Error communicating with AWS", e); } }