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;
}
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) {
}
}
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
}
}
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
}
}
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);
}
}
}
}
Aggregations