public boolean doAction(User user, AsyncContext asyncContext) throws Exception {
HttpServletRequest request = (HttpServletRequest)asyncContext.getRequest();
HttpServletResponse response = (HttpServletResponse)asyncContext.getResponse();
CQSQueue queue = CQSCache.getCachedQueue(user, request);
Map<String, String> idMap = new HashMap<String, String>();
List<String> idList = new ArrayList<String>();
List<CQSBatchResultErrorEntry> failedList = new ArrayList<CQSBatchResultErrorEntry>();
int index = 1;
String suppliedId = request.getParameter(this.actionName + CQSConstants.REQUEST_ENTRY + index + ".Id");
String receiptHandle = request.getParameter(this.actionName + CQSConstants.REQUEST_ENTRY + index + "." + CQSConstants.RECEIPT_HANDLE);
while (suppliedId != null && receiptHandle != null) {
if (!Util.isValidId(suppliedId)) {
throw new CMBException(CQSErrorCodes.InvalidBatchEntryId, "Id " + suppliedId + " is invalid. Only alphanumeric, hyphen, and underscore are allowed. It can be at most " + CMBProperties.getInstance().getCQSMaxMessageSuppliedIdLength() + " letters long.");
}
if (idList.contains(suppliedId)) {
throw new CMBException(CQSErrorCodes.BatchEntryIdsNotDistinct, "You supplied same identifier for two messages");
}
idList.add(suppliedId);
if (receiptHandle.isEmpty()) {
failedList.add(new CQSBatchResultErrorEntry(suppliedId, true, "EmptyValue", "No Value Found for " + this.actionName + CQSConstants.REQUEST_ENTRY + index + "." + CQSConstants.RECEIPT_HANDLE));
} else {
idMap.put(suppliedId, receiptHandle);
}
index++;
suppliedId = request.getParameter(this.actionName + CQSConstants.REQUEST_ENTRY + index + ".Id");
receiptHandle = request.getParameter(this.actionName + CQSConstants.REQUEST_ENTRY + index + "." + CQSConstants.RECEIPT_HANDLE);
}
if (idMap.size() == 0) {
throw new CMBException(CMBErrorCodes.InvalidQueryParameter, "Both user supplied message Id and receiptHandle are required");
}
for (Map.Entry<String, String> entry : idMap.entrySet()) {
receiptHandle = entry.getValue();
PersistenceFactory.getCQSMessagePersistence().deleteMessage(queue.getRelativeUrl(), receiptHandle);
}
String out = CQSMessagePopulator.getDeleteMessageBatchResponse(new ArrayList<String>(idMap.keySet()), failedList);
writeResponse(out, response);