List of usage examples for com.amazonaws AmazonServiceException AmazonServiceException
public AmazonServiceException(String errorMessage)
From source file:AbstractAmazonKinesisFirehoseDelivery.java
License:Open Source License
/** * Method to wait until the delivery stream becomes active. * * @param deliveryStreamName the delivery stream * @throws Exception//from ww w . j av a 2 s. co m */ protected static void waitForDeliveryStreamToBecomeAvailable(String deliveryStreamName) throws Exception { LOG.info("Waiting for " + deliveryStreamName + " to become ACTIVE..."); long startTime = System.currentTimeMillis(); long endTime = startTime + (10 * 60 * 1000); while (System.currentTimeMillis() < endTime) { try { Thread.sleep(1000 * 20); } catch (InterruptedException e) { // Ignore interruption (doesn't impact deliveryStream creation) } DeliveryStreamDescription deliveryStreamDescription = describeDeliveryStream(deliveryStreamName); String deliveryStreamStatus = deliveryStreamDescription.getDeliveryStreamStatus(); LOG.info(" - current state: " + deliveryStreamStatus); if (deliveryStreamStatus.equals("ACTIVE")) { return; } } throw new AmazonServiceException("DeliveryStream " + deliveryStreamName + " never went active"); }
From source file:com.cloud.Assignment.QueueSender.java
License:Open Source License
public boolean sendToQueue(String queue, String message) throws Exception { Properties props = new Properties(); AWSCredentials credentials = null;//ww w.ja v a 2s . c o m String myQueueUrl = null; System.out.println("Queue :" + queue + " Message :" + message); try { credentials = new ClasspathPropertiesFileCredentialsProvider("AwsCredentials.properties") .getCredentials(); ClassLoader loader = Thread.currentThread().getContextClassLoader(); props.load(loader.getResourceAsStream("/QueueURL.properties")); } 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 (/Users/prabhus/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usWest2); try { myQueueUrl = props.getProperty(queue); System.out.println("URL :" + myQueueUrl); System.out.println("Sending " + message); sqs.sendMessage(new SendMessageRequest(myQueueUrl, message)); isMessagePosted = true; } catch (AmazonServiceException ase) { throw new AmazonServiceException("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); } catch (AmazonClientException ace) { System.out.println("Error Message: " + ace.getMessage()); throw new AmazonClientException("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."); } return isMessagePosted; }
From source file:com.msi.dns53.client.DNS53Client.java
License:Apache License
@SuppressWarnings("unchecked") public void exceptionMapper(ClientResponse response, String resultXml) throws AmazonServiceException { ErrorResponsePOJO er = null;/*from www .ja v a2s . co m*/ try { StringReader reader = new StringReader(resultXml); JAXBContext context = JAXBContext.newInstance(ErrorResponsePOJO.class); Unmarshaller unmarshaller = context.createUnmarshaller(); er = (ErrorResponsePOJO) unmarshaller.unmarshal(reader); } catch (JAXBException e) { e.printStackTrace(); throw new AmazonClientException("There was a problem parsing the error response xml with JAXB.", e); } if (er == null || er.getError() == null || er.getRequestId() == null || er.getError().getCode() == null || er.getError().getMessage() == null || er.getError().getType() == null) { throw new AmazonClientException( "Error response xml did not contain expected elements although it is well formed."); } String errCode = er.getError().getCode(); Class<AmazonServiceException> clazz = null; Constructor<AmazonServiceException> c = null; AmazonServiceException exception = null; try { String clazzName = ExceptionMap.getExceptionMap().getMap().get(errCode); clazz = (Class<AmazonServiceException>) Class.forName(clazzName); c = (Constructor<AmazonServiceException>) clazz.getConstructor(String.class); exception = (AmazonServiceException) c.newInstance(new Object[] { er.getError().getMessage() }); } catch (NullPointerException e) { exception = new AmazonServiceException(er.getError().getMessage()); } catch (Exception e) { e.printStackTrace(); throw new AmazonClientException("Client could not determine the type of the error response."); } if (exception == null) { throw new AmazonClientException( "Client encountered a problem while it was mapping the error response."); } exception.setErrorCode(er.getError().getCode()); ErrorType et = ErrorType.Unknown; if ("Sender".equals(er.getError().getType())) { et = ErrorType.Service; } exception.setErrorType(et); exception.setRequestId(er.getRequestId()); exception.setStatusCode(response.getStatus()); exception.setServiceName("DNS53"); throw exception; }
From source file:com.netflix.edda.AwsException.java
License:Apache License
public static void raise(int code, String svc, String reqId, String error, String msg) { StringBuffer buf = new StringBuffer().append("Status Code: ").append(code).append(", AWS Service: ") .append(svc).append(", AWS Request ID: ").append(reqId).append(", AWS Error Code: ").append(error) .append(", AWS Error Message:").append(msg); AmazonServiceException e = new AmazonServiceException(buf.toString()); e.setStatusCode(code);//from ww w .j a v a 2 s . c o m e.setServiceName(svc); e.setRequestId(reqId); e.setErrorCode(error); throw e; }
From source file:com.netflix.edda.EddaAwsClient.java
License:Apache License
protected byte[] doGet(final String uri) { try {// ww w .jav a2s.co m return EddaContext.getContext().getRxHttp().get(mkUrl(uri)).flatMap(response -> { if (response.getStatus().code() != 200) { AmazonServiceException e = new AmazonServiceException("Failed to fetch " + uri); e.setStatusCode(response.getStatus().code()); e.setErrorCode("Edda"); e.setRequestId(uri); return rx.Observable.error(e); } return response.getContent().reduce(new ByteArrayOutputStream(), (out, bb) -> { try { bb.readBytes(out, bb.readableBytes()); } catch (IOException e) { throw new RuntimeException(e); } return out; }).map(out -> { return out.toByteArray(); }); }).toBlocking().toFuture().get(2, TimeUnit.MINUTES); } catch (Exception e) { throw new RuntimeException("failed to get url: " + uri, e); } }
From source file:com.upplication.s3fs.util.AmazonS3ClientMock.java
License:Open Source License
@Override public AccessControlList getObjectAcl(String bucketName, String key) throws AmazonClientException { S3Element elem = find(bucketName, key); if (elem != null) { return elem.getPermission(); } else {//from w ww .j a va 2 s .co m throw new AmazonServiceException("key not found, " + key); } }
From source file:com.upplication.s3fs.util.AmazonS3ClientMock.java
License:Open Source License
@Override public AccessControlList getBucketAcl(String bucketName) throws AmazonClientException { Bucket bucket = find(bucketName);//from ww w . j a v a2 s . co m if (bucket == null) { throw new AmazonServiceException("bucket not found, " + bucketName); } AccessControlList res = createAllPermission(); return res; }
From source file:com.upplication.s3fs.util.AmazonS3ClientMock.java
License:Open Source License
@Override public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey) throws AmazonClientException { S3Element element = find(sourceBucketName, sourceKey); if (element != null) { S3Object objectSource = element.getS3Object(); // copy object with S3Object resObj = new S3Object(); resObj.setBucketName(destinationBucketName); resObj.setKey(destinationKey);//from w w w . jav a 2 s . c o m resObj.setObjectContent(objectSource.getObjectContent()); resObj.setObjectMetadata(objectSource.getObjectMetadata()); resObj.setRedirectLocation(objectSource.getRedirectLocation()); // copy permission AccessControlList permission = new AccessControlList(); permission.setOwner(element.getPermission().getOwner()); permission.grantAllPermissions(element.getPermission().getGrants().toArray(new Grant[0])); S3Element elementResult = new S3Element(resObj, permission, sourceKey.endsWith("/")); // TODO: add should replace existing objects.get(find(destinationBucketName)).remove(elementResult); objects.get(find(destinationBucketName)).add(elementResult); return new CopyObjectResult(); } throw new AmazonServiceException("object source not found"); }
From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.java
License:Open Source License
public static String allocateSecurityGroup(AWSAllocation aws) { String groupId;/*from ww w .jav a 2 s . c om*/ SecurityGroup group; // use the security group provided in the description properties String sgId = getFromCustomProperties(aws.child.description, AWSConstants.AWS_SECURITY_GROUP_ID); if (sgId != null) { return sgId; } // if the group doesn't exist an exception is thrown. We won't throw a // missing group exception // we will continue and create the group try { group = getSecurityGroup(aws.amazonEC2Client); if (group != null) { return group.getGroupId(); } } catch (AmazonServiceException t) { if (!t.getMessage().contains(DEFAULT_SECURITY_GROUP_NAME)) { throw t; } } // get the subnet cidr from the subnet provided in description properties (if any) String subnet = getSubnetFromDescription(aws); // if no subnet provided then get the default one for the default vpc if (subnet == null) { subnet = getDefaultVPCSubnet(aws); } // no subnet is not an option... if (subnet == null) { throw new AmazonServiceException("default VPC not found"); } try { // create the security group for the the vpc // provided in the description properties (if any) String vpcId = getFromCustomProperties(aws.child.description, AWSConstants.AWS_VPC_ID); groupId = createSecurityGroup(aws.amazonEC2Client, vpcId); updateIngressRules(aws.amazonEC2Client, groupId, getDefaultRules(subnet)); } catch (AmazonServiceException t) { if (t.getMessage().contains(DEFAULT_SECURITY_GROUP_NAME)) { return getSecurityGroup(aws.amazonEC2Client).getGroupId(); } else { throw t; } } return groupId; }
From source file:edu.si.services.beans.cameratrap.AmazonS3ClientMock.java
License:Apache License
@Override public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) throws AmazonClientException, AmazonServiceException { if ("nonExistingBucket".equals(listObjectsRequest.getBucketName()) && !nonExistingBucketCreated) { AmazonServiceException ex = new AmazonServiceException("Unknown bucket"); ex.setStatusCode(404);// w w w. j a va2 s. c om throw ex; } ObjectListing objectListing = new ObjectListing(); for (int index = 0; index < objects.size(); index++) { if (objects.get(index).getBucketName().equals(listObjectsRequest.getBucketName())) { S3ObjectSummary s3ObjectSummary = new S3ObjectSummary(); s3ObjectSummary.setBucketName(objects.get(index).getBucketName()); s3ObjectSummary.setKey(objects.get(index).getKey()); objectListing.getObjectSummaries().add(s3ObjectSummary); } } return objectListing; }