String username = getCurrentUser();
if (!(Utils.isAdmin(username) || isMessageBoxOwner(messageBoxId, username) ||
authorizationHandler.isUserAuthorized(username,
messageBoxId,
MessageBoxConstants.SQS_OPERATION_RECEIVE_MESSAGE))) {
throw new MessageBoxException("AccessDenied");
}
if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxId)) {
throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
}
try {
List<Message> jmsMessageList = JMSQueueHandler.browse(messageBoxId);
MessageDetails[] messageDetailsArray = new MessageDetails[jmsMessageList.size()];
int index = 0;
for (Message jmsMessage : jmsMessageList) {
messageDetailsArray[index++] = jmsMessageToMessageDetails(jmsMessage);
}
return messageDetailsArray;
} catch (JMSQueueHandlerException e) {
throw new MessageBoxException("InternalError", e);
}
}