35
35
import com .amazonaws .services .sqs .model .DeleteMessageBatchRequest ;
36
36
import com .amazonaws .services .sqs .model .DeleteMessageBatchResult ;
37
37
import com .amazonaws .services .sqs .model .DeleteMessageRequest ;
38
+ import com .amazonaws .services .sqs .model .CreateQueueRequest ;
38
39
import com .amazonaws .services .sqs .model .GetQueueUrlRequest ;
39
40
import com .amazonaws .services .sqs .model .GetQueueUrlResult ;
40
41
import com .amazonaws .services .sqs .model .QueueDoesNotExistException ;
47
48
* This is a JMS Wrapper of AmazonSQSClient. This class changes all
48
49
* AmazonServiceException and AmazonClientException into
49
50
* JMSException/JMSSecurityException.
50
- *
51
- * @author jinsrhee
52
51
*/
53
52
public class AmazonSQSClientJMSWrapper {
54
53
private static final Log LOG = LogFactory .getLog (AmazonSQSClientJMSWrapper .class );
55
54
56
55
private static final Set <String > SECURITY_EXCEPTION_ERROR_CODES ;
57
56
static {
57
+ /**
58
+ * List of exceptions that can classified as security. These exceptions
59
+ * are not thrown during connection-set-up rather after the service
60
+ * calls of the AmazonSQSClient
61
+ */
58
62
SECURITY_EXCEPTION_ERROR_CODES = new HashSet <String >();
59
63
SECURITY_EXCEPTION_ERROR_CODES .add ("MissingClientTokenId" );
60
64
SECURITY_EXCEPTION_ERROR_CODES .add ("InvalidClientTokenId" );
@@ -63,7 +67,13 @@ public class AmazonSQSClientJMSWrapper {
63
67
}
64
68
65
69
private final AmazonSQS amazonSQSClient ;
66
-
70
+
71
+ /**
72
+ * @param amazonSQSClient
73
+ * The AWS SDK Client for SQS.
74
+ * @throws JMSException
75
+ * if the client is null
76
+ */
67
77
public AmazonSQSClientJMSWrapper (AmazonSQS amazonSQSClient ) throws JMSException {
68
78
if (amazonSQSClient == null ) {
69
79
throw new JMSException ("Amazon SQS client cannot be null" );
@@ -75,11 +85,18 @@ public AmazonSQSClientJMSWrapper(AmazonSQS amazonSQSClient) throws JMSException
75
85
* If one uses any other AWS SDK operations other than explicitly listed
76
86
* here, the exceptions thrown by those operations will not be wrapped as
77
87
* JMSExceptions.
88
+ * @return amazonSQSClient
78
89
*/
79
90
public AmazonSQS getAmazonSQSClient () {
80
91
return amazonSQSClient ;
81
92
}
82
93
94
+ /**
95
+ * @param endpoint
96
+ * The endpoint (ex: "sqs.us-east-1.amazonaws.com") of the region
97
+ * specific AWS endpoint this client will communicate with.
98
+ * @throws JMSException
99
+ */
83
100
public void setEndpoint (String endpoint ) throws JMSException {
84
101
try {
85
102
amazonSQSClient .setEndpoint (endpoint );
@@ -89,6 +106,13 @@ public void setEndpoint(String endpoint) throws JMSException {
89
106
}
90
107
}
91
108
109
+ /**
110
+ * @param region
111
+ * The region this client will communicate with. See
112
+ * {@link Region#getRegion(com.amazonaws.regions.Regions)} for
113
+ * accessing a given region.
114
+ * @throws JMSException
115
+ */
92
116
public void setRegion (Region region ) throws JMSException {
93
117
try {
94
118
amazonSQSClient .setRegion (region );
@@ -98,22 +122,41 @@ public void setRegion(Region region) throws JMSException {
98
122
}
99
123
}
100
124
125
+ /**
126
+ * @param deleteMessageRequest
127
+ * Container for the necessary parameters to execute the
128
+ * deleteMessage service method on AmazonSQS.
129
+ * @throws JMSException
130
+ */
101
131
public void deleteMessage (DeleteMessageRequest deleteMessageRequest ) throws JMSException {
102
132
try {
103
133
amazonSQSClient .deleteMessage (deleteMessageRequest );
104
134
} catch (AmazonClientException e ) {
105
135
throw handleException (e , "deleteMessage" );
106
136
}
107
137
}
108
-
138
+
139
+ /**
140
+ * @param deleteMessageBatchRequest
141
+ * Container for the necessary parameters to execute the
142
+ * deleteMessageBatch service method on AmazonSQS. This is the
143
+ * batch version of deleteMessage. Max batch size is 10.
144
+ * @throws JMSException
145
+ */
109
146
public DeleteMessageBatchResult deleteMessageBatch (DeleteMessageBatchRequest deleteMessageBatchRequest ) throws JMSException {
110
147
try {
111
148
return amazonSQSClient .deleteMessageBatch (deleteMessageBatchRequest );
112
149
} catch (AmazonClientException e ) {
113
150
throw handleException (e , "deleteMessageBatch" );
114
151
}
115
152
}
116
-
153
+
154
+ /**
155
+ * @param sendMessageRequest
156
+ * Container for the necessary parameters to execute the
157
+ * sendMessage service method on AmazonSQS.
158
+ * @throws JMSException
159
+ */
117
160
public SendMessageResult sendMessage (SendMessageRequest sendMessageRequest ) throws JMSException {
118
161
try {
119
162
return amazonSQSClient .sendMessage (sendMessageRequest );
@@ -141,11 +184,25 @@ public boolean queueExists(String queueName) throws JMSException {
141
184
throw handleException (e , "getQueueUrl" );
142
185
}
143
186
}
144
-
187
+
188
+ /**
189
+ * @param queueName
190
+ * @return The response from the GetQueueUrl service method, as returned by
191
+ * AmazonSQS, which will include queue`s URL
192
+ * @throws JMSException
193
+ */
145
194
public GetQueueUrlResult getQueueUrl (String queueName ) throws JMSException {
146
195
return getQueueUrl (new GetQueueUrlRequest (queueName ));
147
196
}
148
-
197
+
198
+ /**
199
+ * @param getQueueUrlRequest
200
+ * Container for the necessary parameters to execute the
201
+ * getQueueUrl service method on AmazonSQS.
202
+ * @return The response from the GetQueueUrl service method, as returned by
203
+ * AmazonSQS, which will include queue`s URL
204
+ * @throws JMSException
205
+ */
149
206
public GetQueueUrlResult getQueueUrl (GetQueueUrlRequest getQueueUrlRequest ) throws JMSException {
150
207
try {
151
208
return amazonSQSClient .getQueueUrl (getQueueUrlRequest );
@@ -154,30 +211,80 @@ public GetQueueUrlResult getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) thro
154
211
}
155
212
}
156
213
214
+ /**
215
+ * This function creates the queue with the default queue attributes.
216
+ *
217
+ * @param queueName
218
+ * @return The response from the createQueue service method, as returned by
219
+ * AmazonSQS. This call creates a new queue, or returns the URL of
220
+ * an existing one.
221
+ * @throws JMSException
222
+ */
157
223
public CreateQueueResult createQueue (String queueName ) throws JMSException {
158
224
try {
159
225
return amazonSQSClient .createQueue (queueName );
160
226
} catch (AmazonClientException e ) {
161
227
throw handleException (e , "createQueue" );
162
228
}
163
229
}
164
-
165
- public void changeMessageVisibility (ChangeMessageVisibilityRequest changeMessageVisibilityRequest ) throws JMSException {
230
+
231
+ /**
232
+ * @param createQueueRequest
233
+ * Container for the necessary parameters to execute the
234
+ * createQueue service method on AmazonSQS.
235
+ * @return The response from the createQueue service method, as returned by
236
+ * AmazonSQS. This call creates a new queue, or returns the URL of
237
+ * an existing one.
238
+ * @throws JMSException
239
+ */
240
+ public CreateQueueResult createQueue (CreateQueueRequest createQueueRequest ) throws JMSException {
166
241
try {
167
- amazonSQSClient .changeMessageVisibility ( changeMessageVisibilityRequest );
242
+ return amazonSQSClient .createQueue ( createQueueRequest );
168
243
} catch (AmazonClientException e ) {
169
- throw handleException (e , "changeMessageVisibility " );
244
+ throw handleException (e , "createQueue " );
170
245
}
171
246
}
172
247
248
+ /**
249
+ * @param receiveMessageRequest
250
+ * Container for the necessary parameters to execute the
251
+ * receiveMessage service method on AmazonSQS.
252
+ * @return The response from the ReceiveMessage service method, as returned
253
+ * by AmazonSQS.
254
+ * @throws JMSException
255
+ */
173
256
public ReceiveMessageResult receiveMessage (ReceiveMessageRequest receiveMessageRequest ) throws JMSException {
174
257
try {
175
258
return amazonSQSClient .receiveMessage (receiveMessageRequest );
176
259
} catch (AmazonClientException e ) {
177
260
throw handleException (e , "receiveMessage" );
178
261
}
179
262
}
180
-
263
+
264
+ /**
265
+ * @param changeMessageVisibilityRequest
266
+ * Container for the necessary parameters to execute the
267
+ * changeMessageVisibility service method on AmazonSQS.
268
+ * @return The response from the changeMessageVisibility service method, as
269
+ * returned by AmazonSQS.
270
+ * @throws JMSException
271
+ */
272
+ public void changeMessageVisibility (ChangeMessageVisibilityRequest changeMessageVisibilityRequest ) throws JMSException {
273
+ try {
274
+ amazonSQSClient .changeMessageVisibility (changeMessageVisibilityRequest );
275
+ } catch (AmazonClientException e ) {
276
+ throw handleException (e , "changeMessageVisibility" );
277
+ }
278
+ }
279
+
280
+ /**
281
+ * @param changeMessageVisibilityBatchRequest
282
+ * Container for the necessary parameters to execute the
283
+ * changeMessageVisibilityBatch service method on AmazonSQS.
284
+ * @return The response from the changeMessageVisibilityBatch service
285
+ * method, as returned by AmazonSQS.
286
+ * @throws JMSException
287
+ */
181
288
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch (ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest )
182
289
throws JMSException {
183
290
try {
@@ -188,19 +295,20 @@ public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(ChangeMes
188
295
}
189
296
190
297
/**
191
- * Create generic error message for AmazonServiceException.
192
- * Message include ActionCall, RequestId, HTTPStatusCode, AmazonErrorCode.
298
+ * Create generic error message for AmazonServiceException. Message include
299
+ * ActionCall, RequestId, HTTPStatusCode, AmazonErrorCode.
193
300
*/
194
301
private String logAndGetAmazonServiceException (AmazonServiceException ase , String action ) {
195
- String errorMessage = "AmazonServiceException: " + action + ". RequestId: " + ase .getRequestId () + "\n HTTPStatusCode: "
196
- + ase .getStatusCode () + " AmazonErrorCode: " + ase .getErrorCode ();
302
+ String errorMessage = "AmazonServiceException: " + action + ". RequestId: " + ase .getRequestId () +
303
+ "\n HTTPStatusCode: " + ase .getStatusCode () + " AmazonErrorCode: " +
304
+ ase .getErrorCode ();
197
305
LOG .error (errorMessage , ase );
198
306
return errorMessage ;
199
307
}
200
308
201
309
/**
202
- * Create generic error message for AmazonClientException.
203
- * Message include ActionCall.
310
+ * Create generic error message for AmazonClientException. Message include
311
+ * ActionCall.
204
312
*/
205
313
private String logAndGetAmazonClientException (AmazonClientException ace , String action ) {
206
314
String errorMessage = "AmazonClientException: " + action + "." ;
0 commit comments