Search in sources :

Example 1 with InvalidSelectorException

use of javax.jms.InvalidSelectorException in project activemq-artemis by apache.

the class JMSExceptionHelper method convertFromActiveMQException.

public static JMSException convertFromActiveMQException(final ActiveMQException me) {
    JMSException je;
    switch(me.getType()) {
        case CONNECTION_TIMEDOUT:
            je = new JMSException(me.getMessage());
            break;
        case ILLEGAL_STATE:
            je = new javax.jms.IllegalStateException(me.getMessage());
            break;
        case INTERNAL_ERROR:
            je = new JMSException(me.getMessage());
            break;
        case INVALID_FILTER_EXPRESSION:
            je = new InvalidSelectorException(me.getMessage());
            break;
        case NOT_CONNECTED:
            je = new JMSException(me.getMessage());
            break;
        case OBJECT_CLOSED:
            je = new javax.jms.IllegalStateException(me.getMessage());
            break;
        case QUEUE_DOES_NOT_EXIST:
            je = new InvalidDestinationException(me.getMessage());
            break;
        case QUEUE_EXISTS:
            je = new InvalidDestinationException(me.getMessage());
            break;
        case SECURITY_EXCEPTION:
            je = new JMSSecurityException(me.getMessage());
            break;
        case UNSUPPORTED_PACKET:
            je = new javax.jms.IllegalStateException(me.getMessage());
            break;
        case TRANSACTION_ROLLED_BACK:
            je = new javax.jms.TransactionRolledBackException(me.getMessage());
            break;
        default:
            je = new JMSException(me.getMessage());
    }
    je.setStackTrace(me.getStackTrace());
    je.initCause(me);
    return je;
}
Also used : InvalidSelectorException(javax.jms.InvalidSelectorException) JMSSecurityException(javax.jms.JMSSecurityException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException)

Example 2 with InvalidSelectorException

use of javax.jms.InvalidSelectorException in project activemq-artemis by apache.

the class ConfigUsingDestinationOptionsTest method testInvalidSelectorConfig.

@Test(timeout = 60000)
public void testInvalidSelectorConfig() throws JMSException {
    ActiveMQQueue queue = new ActiveMQQueue("TEST.FOO?consumer.selector=test||1");
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
    Connection conn = factory.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQMessageConsumer cons;
    // JMS selector should be priority
    try {
        cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test||1");
        fail("Selector should be invalid" + cons);
    } catch (InvalidSelectorException e) {
    }
    // Test setting using JMS destinations
    try {
        cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
        fail("Selector should be invalid" + cons);
    } catch (InvalidSelectorException e) {
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) InvalidSelectorException(javax.jms.InvalidSelectorException) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) Connection(javax.jms.Connection) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Session(javax.jms.Session) Test(org.junit.Test)

Example 3 with InvalidSelectorException

use of javax.jms.InvalidSelectorException in project activemq-artemis by apache.

the class DurableSubscriptionTest method testInvalidSelectorException.

@Test
public void testInvalidSelectorException() throws Exception {
    Connection c = createConnection();
    c.setClientID("sofiavergara");
    Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
        s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "mysubscribption", "=TEST 'test'", true);
        ProxyAssertSupport.fail("this should fail");
    } catch (InvalidSelectorException e) {
    // OK
    }
}
Also used : InvalidSelectorException(javax.jms.InvalidSelectorException) Connection(javax.jms.Connection) Session(javax.jms.Session) Test(org.junit.Test)

Example 4 with InvalidSelectorException

use of javax.jms.InvalidSelectorException in project activemq-artemis by apache.

the class NonDurableSubscriberTest method testInvalidSelectorOnSubscription.

@Test
public void testInvalidSelectorOnSubscription() throws Exception {
    TopicConnection c = createTopicConnection();
    c.setClientID("something");
    TopicSession s = c.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
        s.createSubscriber(ActiveMQServerTestCase.topic1, "=TEST 'test'", false);
        ProxyAssertSupport.fail("this should fail");
    } catch (InvalidSelectorException e) {
    // OK
    }
}
Also used : TopicSession(javax.jms.TopicSession) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicConnection(javax.jms.TopicConnection) Test(org.junit.Test)

Example 5 with InvalidSelectorException

use of javax.jms.InvalidSelectorException in project jaffa-framework by jaffa-projects.

the class JmsBrowser method getPendingMessages.

/**
 * Returns the unconsumed messages in the input queue.
 *
 * @param queueName the queue name.
 * @param filter used for searching within the header information of the retrieved messages. The syntax for the filter will be based on a subset of the SQL92 conditional expression syntax.
 * @return the unconsumed messages in the input queue.
 * @throws FrameworkException in case any internal error occurs.
 * @throws ApplicationExceptions Indicates application error(s).
 */
public static Message[] getPendingMessages(String queueName, String filter) throws FrameworkException, ApplicationExceptions {
    Session session = null;
    try {
        List<Message> messages = new LinkedList<Message>();
        QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName);
        if (hasBrowseQueueAccess(queueInfo)) {
            // Obtain a Connection with the JMS provider
            Connection connection = JaffaConnectionFactory.obtainConnection();
            // Creates a Session from the Connection
            session = JmsClientHelper.obtainSession(connection, false);
            // Creates a QueueBrowser from the Session, using the filter, if supplied
            QueueBrowser qb = session.createBrowser(JmsClientHelper.obtainQueue(queueName), filter);
            if (log.isDebugEnabled())
                log.debug("QueueBrowser created for " + queueName + " with filter " + filter);
            // Check if the user can access all messages in the queue
            boolean browseAllMessagesAccess = hasBrowseAllMessagesAccess(queueInfo);
            if (log.isDebugEnabled())
                log.debug("browseAllMessages access to " + queueName + " is " + browseAllMessagesAccess);
            for (Enumeration e = qb.getEnumeration(); e.hasMoreElements(); ) {
                Message message = (Message) e.nextElement();
                // If this is an error queue, perform the check against the original queue
                if (queueInfo.isErrorQueue() && message.getStringProperty(HEADER_ORIGINAL_QUEUE_NAME) != null) {
                    String originalQueueName = message.getStringProperty(HEADER_ORIGINAL_QUEUE_NAME);
                    if (hasBrowseAllMessagesAccess(originalQueueName) || isMessageOwner(message))
                        messages.add(message);
                } else if (browseAllMessagesAccess || isMessageOwner(message)) {
                    messages.add(message);
                }
            }
            // Close the QueueBrowser
            qb.close();
        } else {
            if (log.isDebugEnabled())
                log.debug("No browseQueue access to " + queueName);
        }
        // Returns an array of Messages from the QueueBrowser's enumeration
        Message[] output = messages.toArray(new Message[messages.size()]);
        if (log.isDebugEnabled()) {
            StringBuilder buf = new StringBuilder("<output>");
            for (Message m : output) buf.append("<message>").append(m).append("</message>");
            buf.append("</output>");
            log.debug(output.length + " messages are being returned: " + buf.toString());
        }
        return output;
    } catch (InvalidSelectorException e) {
        if (log.isDebugEnabled())
            log.debug("Invalid filter: \"" + filter + '"', e);
        throw new ApplicationExceptions(new JaffaMessagingApplicationException(JaffaMessagingApplicationException.INVALID_SELECTOR));
    } catch (JMSException e) {
        log.error("Error in reading JMS Messages", e);
        throw new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.BROWSE_ERROR, new Object[] { queueName }, e);
    } finally {
        if (session != null) {
            try {
                session.close();
            } catch (JMSException e) {
                log.warn("Error in closing a JMS Session", e);
            }
        }
    }
}
Also used : QueueInfo(org.jaffa.modules.messaging.services.configdomain.QueueInfo) Enumeration(java.util.Enumeration) InvalidSelectorException(javax.jms.InvalidSelectorException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) LinkedList(java.util.LinkedList) QueueBrowser(javax.jms.QueueBrowser) Session(javax.jms.Session)

Aggregations

InvalidSelectorException (javax.jms.InvalidSelectorException)6 Connection (javax.jms.Connection)4 Session (javax.jms.Session)4 Test (org.junit.Test)4 JMSException (javax.jms.JMSException)2 Enumeration (java.util.Enumeration)1 LinkedList (java.util.LinkedList)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1 JMSSecurityException (javax.jms.JMSSecurityException)1 Message (javax.jms.Message)1 Queue (javax.jms.Queue)1 QueueBrowser (javax.jms.QueueBrowser)1 TextMessage (javax.jms.TextMessage)1 TopicConnection (javax.jms.TopicConnection)1 TopicSession (javax.jms.TopicSession)1 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)1 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1 QueueInfo (org.jaffa.modules.messaging.services.configdomain.QueueInfo)1