List of usage examples for com.amazonaws AmazonClientException AmazonClientException
public AmazonClientException(Throwable t)
From source file:com.amazon.kinesis.streaming.agent.AgentAWSCredentialsProvider.java
License:Open Source License
public AWSCredentials getCredentials() { String accessKeyId = config.accessKeyId(); String secretKey = config.secretKey(); if (!Strings.isNullOrEmpty(accessKeyId) && !Strings.isNullOrEmpty(secretKey)) { LOGGER.debug("Loading credentials from agent config"); return new BasicAWSCredentials(accessKeyId, secretKey); }/*from w ww .j a va 2 s .c o m*/ throw new AmazonClientException("Unable to load credentials from agent config. Missing entries: " + (Strings.isNullOrEmpty(accessKeyId) ? AgentConfiguration.CONFIG_ACCESS_KEY : "") + " " + (Strings.isNullOrEmpty(secretKey) ? AgentConfiguration.CONFIG_SECRET_KEY : "")); }
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
/** * <p>//w ww . j a v a2 s .co m * Delivers a message to the specified queue and uploads the message payload * to Amazon S3 if necessary. * </p> * <p> * <b>IMPORTANT:</b> The following list shows the characters (in Unicode) * allowed in your message, according to the W3C XML specification. For more * information, go to http://www.w3.org/TR/REC-xml/#charsets If you send any * characters not included in the list, your request will be rejected. #x9 | * #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF] * </p> * * <b>IMPORTANT:</b> The input object may be modified by the method. </p> * * @param sendMessageRequest * Container for the necessary parameters to execute the * SendMessage service method on AmazonSQS. * * @return The response from the SendMessage service method, as returned by * AmazonSQS. * * @throws InvalidMessageContentsException * @throws UnsupportedOperationException * * @throws AmazonClientException * If any internal errors are encountered inside the client * while attempting to make the request or handle the response. * For example if a network connection is not available. * @throws AmazonServiceException * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server * side issue. */ public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) { if (sendMessageRequest == null) { String errorMessage = "sendMessageRequest cannot be null."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } sendMessageRequest.getRequestClientOptions().appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); if (!clientConfiguration.isLargePayloadSupportEnabled()) { return super.sendMessage(sendMessageRequest); } if (sendMessageRequest.getMessageBody() == null || "".equals(sendMessageRequest.getMessageBody())) { String errorMessage = "messageBody cannot be null or empty."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } if (clientConfiguration.isAlwaysThroughS3() || isLarge(sendMessageRequest)) { sendMessageRequest = storeMessageInS3(sendMessageRequest); } return super.sendMessage(sendMessageRequest); }
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
/** * <p>/*from w w w. j av a2 s . c o m*/ * Retrieves one or more messages, with a maximum limit of 10 messages, from * the specified queue. Downloads the message payloads from Amazon S3 when * necessary. Long poll support is enabled by using the * <code>WaitTimeSeconds</code> parameter. For more information, see <a * href= * "http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html" * > Amazon SQS Long Poll </a> in the <i>Amazon SQS Developer Guide</i> . * </p> * <p> * Short poll is the default behavior where a weighted random set of * machines is sampled on a <code>ReceiveMessage</code> call. This means * only the messages on the sampled machines are returned. If the number of * messages in the queue is small (less than 1000), it is likely you will * get fewer messages than you requested per <code>ReceiveMessage</code> * call. If the number of messages in the queue is extremely small, you * might not receive any messages in a particular * <code>ReceiveMessage</code> response; in which case you should repeat the * request. * </p> * <p> * For each message returned, the response includes the following: * </p> * * <ul> * <li> * <p> * Message body * </p> * </li> * <li> * <p> * MD5 digest of the message body. For information about MD5, go to <a * href="http://www.faqs.org/rfcs/rfc1321.html"> * http://www.faqs.org/rfcs/rfc1321.html </a> . * </p> * </li> * <li> * <p> * Message ID you received when you sent the message to the queue. * </p> * </li> * <li> * <p> * Receipt handle. * </p> * </li> * <li> * <p> * Message attributes. * </p> * </li> * <li> * <p> * MD5 digest of the message attributes. * </p> * </li> * * </ul> * <p> * The receipt handle is the identifier you must provide when deleting the * message. For more information, see <a href= * "http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/ImportantIdentifiers.html" * > Queue and Message Identifiers </a> in the <i>Amazon SQS Developer * Guide</i> . * </p> * <p> * You can provide the <code>VisibilityTimeout</code> parameter in your * request, which will be applied to the messages that Amazon SQS returns in * the response. If you do not include the parameter, the overall visibility * timeout for the queue is used for the returned messages. For more * information, see <a href= * "http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html" * > Visibility Timeout </a> in the <i>Amazon SQS Developer Guide</i> . * </p> * <p> * <b>NOTE:</b> Going forward, new attributes might be added. If you are * writing code that calls this action, we recommend that you structure your * code so that it can handle new attributes gracefully. * </p> * * @param receiveMessageRequest * Container for the necessary parameters to execute the * ReceiveMessage service method on AmazonSQS. * * @return The response from the ReceiveMessage service method, as returned * by AmazonSQS. * * @throws OverLimitException * * @throws AmazonClientException * If any internal errors are encountered inside the client * while attempting to make the request or handle the response. * For example if a network connection is not available. * @throws AmazonServiceException * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server * side issue. */ public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) { if (receiveMessageRequest == null) { String errorMessage = "receiveMessageRequest cannot be null."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } receiveMessageRequest.getRequestClientOptions() .appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); if (!clientConfiguration.isLargePayloadSupportEnabled()) { return super.receiveMessage(receiveMessageRequest); } receiveMessageRequest.getMessageAttributeNames().add(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); ReceiveMessageResult receiveMessageResult = super.receiveMessage(receiveMessageRequest); List<Message> messages = receiveMessageResult.getMessages(); for (Message message : messages) { // for each received message check if they are stored in S3. MessageAttributeValue largePayloadAttributeValue = message.getMessageAttributes() .get(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); if (largePayloadAttributeValue != null) { String messageBody = message.getBody(); // read the S3 pointer from the message body JSON string. MessageS3Pointer s3Pointer = readMessageS3PointerFromJSON(messageBody); String s3MsgBucketName = s3Pointer.getS3BucketName(); String s3MsgKey = s3Pointer.getS3Key(); String origMsgBody = getTextFromS3(s3MsgBucketName, s3MsgKey); LOG.info("S3 object read, Bucket name: " + s3MsgBucketName + ", Object key: " + s3MsgKey + "."); message.setBody(origMsgBody); // remove the additional attribute before returning the message // to user. message.getMessageAttributes().remove(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); // Embed s3 object pointer in the receipt handle. String modifiedReceiptHandle = embedS3PointerInReceiptHandle(message.getReceiptHandle(), s3MsgBucketName, s3MsgKey); message.setReceiptHandle(modifiedReceiptHandle); } } return receiveMessageResult; }
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
/** * <p>/* w w w .ja va 2s .c om*/ * Deletes the specified message from the specified queue and deletes the * message payload from Amazon S3 when necessary. You specify the message by * using the message's <code>receipt handle</code> and not the * <code>message ID</code> you received when you sent the message. Even if * the message is locked by another reader due to the visibility timeout * setting, it is still deleted from the queue. If you leave a message in * the queue for longer than the queue's configured retention period, Amazon * SQS automatically deletes it. * </p> * <p> * <b>NOTE:</b> The receipt handle is associated with a specific instance of * receiving the message. If you receive a message more than once, the * receipt handle you get each time you receive the message is different. * When you request DeleteMessage, if you don't provide the most recently * received receipt handle for the message, the request will still succeed, * but the message might not be deleted. * </p> * <p> * <b>IMPORTANT:</b> It is possible you will receive a message even after * you have deleted it. This might happen on rare occasions if one of the * servers storing a copy of the message is unavailable when you request to * delete the message. The copy remains on the server and might be returned * to you again on a subsequent receive request. You should create your * system to be idempotent so that receiving a particular message more than * once is not a problem. * </p> * * @param deleteMessageRequest * Container for the necessary parameters to execute the * DeleteMessage service method on AmazonSQS. * * * @throws ReceiptHandleIsInvalidException * @throws InvalidIdFormatException * * @throws AmazonClientException * If any internal errors are encountered inside the client * while attempting to make the request or handle the response. * For example if a network connection is not available. * @throws AmazonServiceException * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server * side issue. */ public void deleteMessage(DeleteMessageRequest deleteMessageRequest) { if (deleteMessageRequest == null) { String errorMessage = "deleteMessageRequest cannot be null."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } deleteMessageRequest.getRequestClientOptions() .appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); if (!clientConfiguration.isLargePayloadSupportEnabled()) { super.deleteMessage(deleteMessageRequest); return; } String receiptHandle = deleteMessageRequest.getReceiptHandle(); String origReceiptHandle = receiptHandle; if (isS3ReceiptHandle(receiptHandle)) { deleteMessagePayloadFromS3(receiptHandle); origReceiptHandle = getOrigReceiptHandle(receiptHandle); } deleteMessageRequest.setReceiptHandle(origReceiptHandle); super.deleteMessage(deleteMessageRequest); }
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
/** * <p>/*from ww w . j a v a 2 s. com*/ * Delivers up to ten messages to the specified queue. This is a batch * version of SendMessage. The result of the send action on each message is * reported individually in the response. Uploads message payloads to Amazon * S3 when necessary. * </p> * <p> * If the <code>DelaySeconds</code> parameter is not specified for an entry, * the default for the queue is used. * </p> * <p> * <b>IMPORTANT:</b>The following list shows the characters (in Unicode) * that are allowed in your message, according to the W3C XML specification. * For more information, go to http://www.faqs.org/rfcs/rfc1321.html. If you * send any characters that are not included in the list, your request will * be rejected. #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | * [#x10000 to #x10FFFF] * </p> * <p> * <b>IMPORTANT:</b> Because the batch request can result in a combination * of successful and unsuccessful actions, you should check for batch errors * even when the call returns an HTTP status code of 200. * </p> * <b>IMPORTANT:</b> The input object may be modified by the method. </p> * <p> * <b>NOTE:</b>Some API actions take lists of parameters. These lists are * specified using the param.n notation. Values of n are integers starting * from 1. For example, a parameter list with two elements looks like this: * </p> * <p> * <code>&Attribute.1=this</code> * </p> * <p> * <code>&Attribute.2=that</code> * </p> * * @param sendMessageBatchRequest * Container for the necessary parameters to execute the * SendMessageBatch service method on AmazonSQS. * * @return The response from the SendMessageBatch service method, as * returned by AmazonSQS. * * @throws BatchEntryIdsNotDistinctException * @throws TooManyEntriesInBatchRequestException * @throws BatchRequestTooLongException * @throws UnsupportedOperationException * @throws InvalidBatchEntryIdException * @throws EmptyBatchRequestException * * @throws AmazonClientException * If any internal errors are encountered inside the client * while attempting to make the request or handle the response. * For example if a network connection is not available. * @throws AmazonServiceException * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server * side issue. */ public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) { if (sendMessageBatchRequest == null) { String errorMessage = "sendMessageBatchRequest cannot be null."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } sendMessageBatchRequest.getRequestClientOptions() .appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); if (!clientConfiguration.isLargePayloadSupportEnabled()) { return super.sendMessageBatch(sendMessageBatchRequest); } List<SendMessageBatchRequestEntry> batchEntries = sendMessageBatchRequest.getEntries(); int index = 0; for (SendMessageBatchRequestEntry entry : batchEntries) { if (clientConfiguration.isAlwaysThroughS3() || isLarge(entry)) { batchEntries.set(index, storeMessageInS3(entry)); } ++index; } return super.sendMessageBatch(sendMessageBatchRequest); }
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
/** * <p>//from w w w . ja v a2 s.co m * Deletes up to ten messages from the specified queue. This is a batch * version of DeleteMessage. The result of the delete action on each message * is reported individually in the response. Also deletes the message * payloads from Amazon S3 when necessary. * </p> * <p> * <b>IMPORTANT:</b> Because the batch request can result in a combination * of successful and unsuccessful actions, you should check for batch errors * even when the call returns an HTTP status code of 200. * </p> * <p> * <b>NOTE:</b>Some API actions take lists of parameters. These lists are * specified using the param.n notation. Values of n are integers starting * from 1. For example, a parameter list with two elements looks like this: * </p> * <p> * <code>&Attribute.1=this</code> * </p> * <p> * <code>&Attribute.2=that</code> * </p> * * @param deleteMessageBatchRequest * Container for the necessary parameters to execute the * DeleteMessageBatch service method on AmazonSQS. * * @return The response from the DeleteMessageBatch service method, as * returned by AmazonSQS. * * @throws BatchEntryIdsNotDistinctException * @throws TooManyEntriesInBatchRequestException * @throws InvalidBatchEntryIdException * @throws EmptyBatchRequestException * * @throws AmazonClientException * If any internal errors are encountered inside the client * while attempting to make the request or handle the response. * For example if a network connection is not available. * @throws AmazonServiceException * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server * side issue. */ public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest deleteMessageBatchRequest) { if (deleteMessageBatchRequest == null) { String errorMessage = "deleteMessageBatchRequest cannot be null."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } deleteMessageBatchRequest.getRequestClientOptions() .appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); if (!clientConfiguration.isLargePayloadSupportEnabled()) { return super.deleteMessageBatch(deleteMessageBatchRequest); } for (DeleteMessageBatchRequestEntry entry : deleteMessageBatchRequest.getEntries()) { String receiptHandle = entry.getReceiptHandle(); String origReceiptHandle = receiptHandle; if (isS3ReceiptHandle(receiptHandle)) { deleteMessagePayloadFromS3(receiptHandle); origReceiptHandle = getOrigReceiptHandle(receiptHandle); } entry.setReceiptHandle(origReceiptHandle); } return super.deleteMessageBatch(deleteMessageBatchRequest); }
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
/** * <p>// w w w . j a v a 2 s . com * Deletes the messages in a queue specified by the <b>queue URL</b> . * </p> * <p> * <b>IMPORTANT:</b>When you use the PurgeQueue API, the deleted messages in * the queue cannot be retrieved. * </p> * <p> * <b>IMPORTANT:</b> This does not delete the message payloads from Amazon S3. * </p> * <p> * When you purge a queue, the message deletion process takes up to 60 * seconds. All messages sent to the queue before calling * <code>PurgeQueue</code> will be deleted; messages sent to the queue while * it is being purged may be deleted. While the queue is being purged, * messages sent to the queue before <code>PurgeQueue</code> was called may * be received, but will be deleted within the next minute. * </p> * * @param purgeQueueRequest * Container for the necessary parameters to execute the * PurgeQueue service method on AmazonSQS. * * * @throws PurgeQueueInProgressException * @throws QueueDoesNotExistException * * @throws AmazonClientException * If any internal errors are encountered inside the client * while attempting to make the request or handle the response. * For example if a network connection is not available. * @throws AmazonServiceException * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server * side issue. */ public void purgeQueue(PurgeQueueRequest purgeQueueRequest) throws AmazonServiceException, AmazonClientException { LOG.warn("Calling purgeQueue deletes SQS messages without deleting their payload from S3."); if (purgeQueueRequest == null) { String errorMessage = "purgeQueueRequest cannot be null."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } purgeQueueRequest.getRequestClientOptions().appendUserAgent(SQSExtendedClientConstants.USER_AGENT_HEADER); super.purgeQueue(purgeQueueRequest); }
From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java
License:Open Source License
private void checkMessageAttributes(Map<String, MessageAttributeValue> messageAttributes) { int msgAttributesSize = getMsgAttributesSize(messageAttributes); if (msgAttributesSize > clientConfiguration.getMessageSizeThreshold()) { String errorMessage = "Total size of Message attributes is " + msgAttributesSize + " bytes which is larger than the threshold of " + clientConfiguration.getMessageSizeThreshold() + " Bytes. Consider including the payload in the message body instead of message attributes."; LOG.error(errorMessage);/*from w w w . ja v a 2 s . c o m*/ throw new AmazonClientException(errorMessage); } int messageAttributesNum = messageAttributes.size(); if (messageAttributesNum > SQSExtendedClientConstants.MAX_ALLOWED_ATTRIBUTES) { String errorMessage = "Number of message attributes [" + messageAttributesNum + "] exceeds the maximum allowed for large-payload messages [" + SQSExtendedClientConstants.MAX_ALLOWED_ATTRIBUTES + "]."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } MessageAttributeValue largePayloadAttributeValue = messageAttributes .get(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); if (largePayloadAttributeValue != null) { String errorMessage = "Message attribute name " + SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME + " is reserved for use by SQS extended client."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } }
From source file:com.amazon.sqs.javamessaging.ExtendedClientConfiguration.java
License:Open Source License
/** * Enables support for large-payload messages. * * @param s3//from www .j a va 2s . c o m * Amazon S3 client which is going to be used for storing * large-payload messages. * @param s3BucketName * Name of the bucket which is going to be used for storing * large-payload messages. The bucket must be already created and * configured in s3. */ public void setLargePayloadSupportEnabled(AmazonS3 s3, String s3BucketName) { if (s3 == null || s3BucketName == null) { String errorMessage = "S3 client and/or S3 bucket name cannot be null."; LOG.error(errorMessage); throw new AmazonClientException(errorMessage); } if (isLargePayloadSupportEnabled()) { LOG.warn("Large-payload support is already enabled. Overwriting AmazonS3Client and S3BucketName."); } this.s3 = s3; this.s3BucketName = s3BucketName; largePayloadSupport = true; LOG.info("Large-payload support enabled."); }
From source file:com.boundary.aws.dynamodb.QueryDynamoDB.java
License:Open Source License
/** * The only information needed to create a client are security credentials * consisting of the AWS Access Key ID and Secret Access Key. All other * configuration, such as the service endpoints, are performed * automatically. Client parameters, such as proxies, can be specified in an * optional ClientConfiguration object when constructing a client. * * @see com.amazonaws.auth.BasicAWSCredentials * @see com.amazonaws.auth.ProfilesConfigFile * @see com.amazonaws.ClientConfiguration *///from w w w. ja v a 2s . c o m private static void init() throws Exception { /* * The ProfileCredentialsProvider will return your [default] credential * profile by reading from the credentials file located at * (/Users/davidg/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider("default").getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file." + e); } dynamoDB = new AmazonDynamoDBClient(credentials); Region usWest1 = Region.getRegion(Regions.US_WEST_1); dynamoDB.setRegion(usWest1); }