Package org.wso2.carbon.messagebox

Examples of org.wso2.carbon.messagebox.MessageBoxException


    public SQSMessage putMessage(String messageBoxID, SQSMessage sqsMessage)
            throws MessageBoxException {
        // Check permissions to send messages
        if (!authorizationHandler.isAuthorized(
                messageBoxID, MessageBoxConstants.SQS_OPERATION_SEND_MESSAGE)) {
            throw new MessageBoxException("AccessDenied");
        }

        if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxID)) {
            throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
        }

        try {
            // Push message into JMS queue
            JMSQueueHandler.pushMessage(messageBoxID, sqsMessage,
                                        sqsMessage.getAttribute().
                                                get(MessageBoxConstants.SQS_MESSAGE_ATTRIBUTE_SENDER_ID));
            queueManager.setQueueUpdatedTime(JMSQueueHandler.getJMSQueueName(messageBoxID));
            return sqsMessage;
        } catch (JMSQueueHandlerException e) {
            throw new MessageBoxException("InternalError", e);
        }
    }
View Full Code Here


                                           long visibilityTimeout, Map<String, String> attributes)
            throws MessageBoxException {
        // Check permission to receive messages
        if (!authorizationHandler.isAuthorized(
                messageBoxId, MessageBoxConstants.SQS_OPERATION_RECEIVE_MESSAGE)) {
            throw new MessageBoxException("AccessDenied");
        }

        if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxId)) {
            throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
        }
        if (visibilityTimeout == 0) {
            visibilityTimeout = registryMessageBoxHandler.getMessageBoxDetails(messageBoxId).
                    getDefaultVisibilityTimeout();
        }

        try {
            List<SQSMessage> sqsMessageList = new ArrayList<SQSMessage>();
            // Fetch messages
            while (0 < maximumNumberOfMessages) {
                // Create and store lock
                MessageLock messageLock = JMSQueueHandler.popMessage(messageBoxId, visibilityTimeout);
                if (messageLock == null) {
                    break;
                }
                messageLock.setLockStore(getMessageLocks());
                getMessageLocks().put(messageLock.getReceiptHandle(), messageLock);

                // Create and store SQS message
                SQSMessage sqsMessage = jmsMessageToSQSMessage(messageLock.getJmsMessage());
                sqsMessage.setReceiptHandle(messageLock.getReceiptHandle());

                // set visibility timeout of message as default visibility timeout of messageBox
                if (sqsMessage.getDefaultVisibilityTimeout() == 0) {
                    MessageBoxDetails messageBoxDetails =
                            registryMessageBoxHandler.getMessageBoxDetails(messageBoxId);
                    sqsMessage.setDefaultVisibilityTimeout(
                            messageBoxDetails.getDefaultVisibilityTimeout());
                }
                sqsMessage.setDefaultVisibilityTimeout(visibilityTimeout);

                sqsMessageList.add(sqsMessage);

                maximumNumberOfMessages--;
            }
            queueManager.setQueueUpdatedTime(JMSQueueHandler.getJMSQueueName(messageBoxId));
            return sqsMessageList;
        } catch (JMSQueueHandlerException e) {
            throw new MessageBoxException("InternalError", e);
        }
    }
View Full Code Here

    public void deleteMessage(String messageBoxId, String receiptHandler)
            throws MessageBoxException {
        // Check permission to receive messages
        if (!authorizationHandler.isAuthorized(
                messageBoxId, MessageBoxConstants.SQS_OPERATION_DELETE_MESSAGE)) {
            throw new MessageBoxException("AccessDenied");
        }

        if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxId)) {
            throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
        }

        // Delete message
        try {
            MessageLock messageLock = getMessageLocks().get(receiptHandler);
            if (messageLock != null) {
                messageLock.deleteMessage();
                queueManager.setQueueUpdatedTime(JMSQueueHandler.getJMSQueueName(messageBoxId));
            }
        } catch (MessageLockException e) {
            throw new MessageBoxException("InternalError", e);
        }
    }
View Full Code Here

    public void changeVisibility(String messageBoxId, String receiptHandler,
                                 long extension) throws MessageBoxException {
        // Check permission to change message visibility
        if (!authorizationHandler.isAuthorized(
                messageBoxId, MessageBoxConstants.SQS_OPERATION_CHANGE_MESSAGE_VISIBILITY)) {
            throw new MessageBoxException("AccessDenied");
        }

        if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxId)) {
            throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
        }

        // Accumulate visibility timeout
        try {
            MessageLock messageLock = getMessageLocks().get(receiptHandler);
            if (null != messageLock) {
                messageLock.changeMessageVisibility(extension);
                JMSQueueHandler.setVisibilityTimeoutStringProperty(messageLock.getVisibilityTimeout(),
                                                                   messageLock.getJmsMessage());
                queueManager.setQueueUpdatedTime(JMSQueueHandler.getJMSQueueName(messageBoxId));
            }
        } catch (MessageLockException e) {
            throw new MessageBoxException("ExceedVisibilityTimeout", e);
        } catch (JMSQueueHandlerException e) {
            throw new MessageBoxException("ExceedVisibilityTimeout", e);
        }
    }
View Full Code Here

    public Map<String, String> getMessageBoxAttributes(String messageBoxId)
            throws MessageBoxException {
        // Check permissions to get message box attributes
        if (!authorizationHandler.isAuthorized(
                messageBoxId, MessageBoxConstants.SQS_OPERATION_GET_QUEUE_ATTRIBUTES)) {
            throw new MessageBoxException("AccessDenied");
        }

        if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxId)) {
            throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
        }

        Map<String, String> attributeMap = new HashMap<String, String>();

        MessageBoxDetails messageBoxDetails =
View Full Code Here

    public void setMessageBoxAttributes(String messageBoxId, Map<String, String> attributes)
            throws MessageBoxException {
        // Only an admin or the owner can set message box attributes
        String username = getCurrentUser();
        if (!Utils.isAdmin(username) && !isMessageBoxOwner(messageBoxId, username)) {
            throw new MessageBoxException("AccessDenied");
        }

        if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxId)) {
            throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
        }

        registryMessageBoxHandler.setMessageBoxDetails(messageBoxId, attributes);
        queueManager.setQueueUpdatedTime(JMSQueueHandler.getJMSQueueName(messageBoxId));
    }
View Full Code Here

    public void removePermission(String messageBoxId, String permissionLabelName)
            throws MessageBoxException {
        // Check permission to remove permissions on message box
        String username = getCurrentUser();
        if (!Utils.isAdmin(username) && !isMessageBoxOwner(messageBoxId, username)) {
            throw new MessageBoxException("AccessDenied");
        }

        if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxId)) {
            throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
        }

        // Get permissions before removing from registry
        PermissionLabel removedPermissionLabel = registryMessageBoxHandler.getPermission(
                messageBoxId, permissionLabelName);
View Full Code Here

                              String permissionLabelName, List<String> sharedUsers)
            throws MessageBoxException {
        // Only an admin or the owner can add permissions on message box
        String username = getCurrentUser();
        if (!Utils.isAdmin(username) && !isMessageBoxOwner(messageBoxId, username)) {
            throw new MessageBoxException("AccessDenied");
        }

        if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxId)) {
            throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
        }
        sharedUsers = registryMessageBoxHandler.getSharedUsers(sharedUsers.toArray(
                new String[sharedUsers.size()]));
        PermissionLabel permissionLabel =
                new PermissionLabel(permissionLabelName, sharedUsers, operationsList);
View Full Code Here

                count = managedQueue.getMessageCount();
            }

            return count;
        } catch (MalformedObjectNameException e) {
            throw new MessageBoxException(e);
        } catch (IOException e) {
            throw new MessageBoxException(e);
        }
    }
View Full Code Here

                            MessageBoxConstants.JMS_MESSAGE_PROPERTY_RECEIVED_COUNT));
            return sqsMessage;
        } catch (JMSException e) {
            String error = "Failed to convert JMS Message to SQSMessage";
            log.error(error);
            throw new MessageBoxException(error, e);
        }
    }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.messagebox.MessageBoxException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.