List of usage examples for com.amazonaws AmazonServiceException AmazonServiceException
public AmazonServiceException(String errorMessage)
From source file:org.flite.mock.amazonaws.sqs.AmazonSQSMock.java
License:Open Source License
public ReceiveMessageResult receiveMessage(final ReceiveMessageRequest request) throws AmazonServiceException, AmazonClientException { if (request == null) { throw new AmazonClientException("Null ReceiveMessageRequest"); }/* w ww . j ava2 s. c om*/ final String queueUrl = request.getQueueUrl(); checkURLForException(queueUrl); // Per documentation throws OverLimitException, but in my testing, // they actually only throw AmazonServiceException final Integer max = request.getMaxNumberOfMessages(); if (max == null || max < 1 || max > 10) { throw new AmazonServiceException("MaxNumberOfMessages must be a value between [1,10]"); } final ReceiveMessageResult result = new ReceiveMessageResult(); int received = 0; boolean avail = true; while (received < request.getMaxNumberOfMessages() && avail) { try { final Message msg = allQueues.get(queueUrl).remove(0); received++; msg.setReceiptHandle(RECEIPT_ID_PREFIX + incrementer.getAndIncrement()); retrievedMessages.get(queueUrl).put(msg.getReceiptHandle(), msg); result.withMessages(msg); } catch (Exception ex) { avail = false; } } return result; }
From source file:org.flite.mock.amazonaws.sqs.AmazonSQSMock.java
License:Open Source License
public void deleteQueue(final DeleteQueueRequest request) throws AmazonServiceException, AmazonClientException { if (request == null) { throw new AmazonClientException("Null DeleteQueueRequest"); }/*w w w .j a v a2 s . co m*/ final String queueUrl = request.getQueueUrl(); checkURLForException(queueUrl); if (!allQueues.containsKey(queueUrl)) { throw new AmazonServiceException("Queue Not Found: " + queueUrl); } allQueues.remove(queueUrl); if (retrievedMessages.containsKey(queueUrl)) { retrievedMessages.remove(queueUrl); } }
From source file:org.flite.mock.amazonaws.sqs.AmazonSQSMock.java
License:Open Source License
private static void checkStringForExceptionMarker(final String str) { final String src = StringUtils.isBlank(str) ? "" : str.toLowerCase(); if (src.contains(MARKER_CLIENT_EXCEPTION)) { throw new AmazonClientException("Forced AmazonClientException"); }/*from w w w . j a v a 2 s . co m*/ if (src.contains(MARKER_SERVICE_EXCEPTION)) { throw new AmazonServiceException("Forced AmazonServiceException"); } }
From source file:org.weakref.s3fs.util.AmazonS3ClientMock.java
License:Apache License
@Override public AccessControlList getObjectAcl(String bucketName, String key) throws AmazonClientException, AmazonServiceException { S3Element elem = find(bucketName, key); if (elem != null) { return elem.getPermission(); } else {// w w w .java 2 s . c om throw new AmazonServiceException("key not found, " + key); } }
From source file:org.weakref.s3fs.util.AmazonS3ClientMock.java
License:Apache License
@Override public AccessControlList getBucketAcl(String bucketName) throws AmazonClientException, AmazonServiceException { Bucket bucket = find(bucketName);/* w w w . j a v a 2s .c o m*/ if (bucket == null) { throw new AmazonServiceException("bucket not found, " + bucketName); } AccessControlList res = createAllPermission(); return res; }
From source file:org.weakref.s3fs.util.AmazonS3ClientMock.java
License:Apache License
@Override public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, String destinationBucketName, String destinationKey) throws AmazonClientException, AmazonServiceException { 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 ww . j a va2 s . com resObj.setObjectContent(objectSource.getObjectContent()); resObj.setObjectMetadata(objectSource.getObjectMetadata()); resObj.setRedirectLocation(objectSource.getRedirectLocation()); // copy perission AccessControlList permission = new AccessControlList(); permission.setOwner(element.getPermission().getOwner()); permission.grantAllPermissions(element.getPermission().getGrants().toArray(new Grant[0])); // maybe not exists key TODO objects.get(find(destinationBucketName)) .add(new S3Element(resObj, permission, sourceKey.endsWith("/"))); return new CopyObjectResult(); } throw new AmazonServiceException("object source not found"); }