javax.jms.IllegalStateException Java Examples
The following examples show how to use
javax.jms.IllegalStateException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActiveMQRASession.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Rollback * * @throws JMSException Failed to close session. */ @Override public void rollback() throws JMSException { if (cri.getType() == ActiveMQRAConnectionFactory.XA_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) { throw new TransactionInProgressException("XA connection"); } lock(); try { Session session = getSessionInternal(); if (cri.isTransacted() == false) { throw new IllegalStateException("Session is not transacted"); } if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("Rollback session " + this); } session.rollback(); } finally { unlock(); } }
Example #2
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testRuntimeExceptionFromSendSerializableBody() throws JMSException { JMSProducer producer = context.createProducer(); MockJMSConnection connection = (MockJMSConnection) context.getConnection(); connection.addConnectionListener(new MockJMSDefaultConnectionListener() { @Override public void onMessageSend(MockJMSSession session, Message message) throws JMSException { throw new IllegalStateException("Send Failed"); } }); try { producer.send(context.createTemporaryQueue(), UUID.randomUUID()); fail("Should have thrown an exception"); } catch (IllegalStateRuntimeException isre) {} }
Example #3
Source File: MockJMSConnection.java From pooled-jms with Apache License 2.0 | 6 votes |
@Override public void setClientID(String clientID) throws JMSException { checkClosedOrFailed(); if (explicitClientID) { throw new IllegalStateException("The clientID has already been set"); } if (clientID == null || clientID.isEmpty()) { throw new InvalidClientIDException("Cannot have a null or empty clientID"); } if (connected.get()) { throw new IllegalStateException("Cannot set the client id once connected."); } setClientID(clientID, true); // We weren't connected if we got this far, we should now connect to ensure the // configured clientID is valid. initialize(); }
Example #4
Source File: JmsPoolQueueSenderTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testGetQueue() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); QueueSender sender = session.createSender(queue); assertNotNull(sender.getQueue()); assertSame(queue, sender.getQueue()); sender.close(); try { sender.getQueue(); fail("Cannot read topic on closed sender"); } catch (IllegalStateException ise) {} }
Example #5
Source File: JmsPoolQueueSenderTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testGetTopicSubscriber() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); JmsPoolQueueSender sender = (JmsPoolQueueSender) session.createSender(queue); assertNotNull(sender.getQueueSender()); assertTrue(sender.getQueueSender() instanceof MockJMSQueueSender); sender.close(); try { sender.getQueueSender(); fail("Cannot read state on closed sender"); } catch (IllegalStateException ise) {} }
Example #6
Source File: JmsPoolMessageConsumerTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testReceive() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); Session session = connection.createSession(); Queue queue = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(queue, "Color = Red"); assertNull(consumer.receive()); consumer.close(); try { consumer.receive(); fail("Should not be able to interact with closed consumer"); } catch (IllegalStateException ise) {} }
Example #7
Source File: JmsPoolMessageConsumerTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testReceiveNoWait() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); Session session = connection.createSession(); Queue queue = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(queue, "Color = Red"); assertNull(consumer.receiveNoWait()); consumer.close(); try { consumer.receiveNoWait(); fail("Should not be able to interact with closed consumer"); } catch (IllegalStateException ise) {} }
Example #8
Source File: JmsPoolMessageConsumerTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testReceiveTimed() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); Session session = connection.createSession(); Queue queue = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(queue, "Color = Red"); assertNull(consumer.receive(1)); consumer.close(); try { consumer.receive(1); fail("Should not be able to interact with closed consumer"); } catch (IllegalStateException ise) {} }
Example #9
Source File: JmsPoolMessageConsumerTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testGetMessageSelector() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); Session session = connection.createSession(); Queue queue = session.createTemporaryQueue(); MessageConsumer consumer = session.createConsumer(queue, "Color = Red"); assertNotNull(consumer.getMessageSelector()); assertEquals("Color = Red", consumer.getMessageSelector()); consumer.close(); try { consumer.getMessageSelector(); fail("Should not be able to interact with closed consumer"); } catch (IllegalStateException ise) {} }
Example #10
Source File: JmsPoolConnectionTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testSetClientIDTwiceWithSameID() throws Exception { Connection connection = cf.createConnection(); // test: call setClientID("newID") twice // this should be tolerated and not result in an exception connection.setClientID("newID"); try { connection.setClientID("newID"); connection.start(); connection.close(); } catch (IllegalStateException ise) { LOG.error("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage()); fail("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage()); } finally { cf.stop(); } LOG.debug("Test finished."); }
Example #11
Source File: ActiveMQRASessionFactoryImpl.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Create a XA queue session * * @return The XA queue session * @throws JMSException Thrown if an error occurs */ @Override public XAQueueSession createXAQueueSession() throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("createXAQueueSession()"); } checkClosed(); if (type == ActiveMQRAConnectionFactory.CONNECTION || type == ActiveMQRAConnectionFactory.TOPIC_CONNECTION || type == ActiveMQRAConnectionFactory.XA_TOPIC_CONNECTION) { throw new IllegalStateException("Can not get a topic session from a queue connection"); } return allocateConnection(type); }
Example #12
Source File: JmsPoolConnectionTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testSetClientIDAfterConnectionStart() throws Exception { Connection connection = cf.createConnection(); // test: try to call setClientID() after start() // should result in an exception try { connection.start(); connection.setClientID("newID3"); fail("Calling setClientID() after start() mut raise a JMSException."); } catch (IllegalStateException ise) { LOG.debug("Correctly received " + ise); } finally { connection.close(); cf.stop(); } LOG.debug("Test finished."); }
Example #13
Source File: JmsQueueBrowserTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testGetQueue() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); QueueBrowser browser = session.createBrowser(queue); assertNotNull(browser.getQueue()); browser.close(); browser.close(); try { browser.getQueue(); fail("Should not be able to use a closed browser"); } catch (IllegalStateException ise) { } }
Example #14
Source File: JmsQueueBrowserTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testGetQueueBrowser() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); JmsPoolQueueBrowser browser = (JmsPoolQueueBrowser) session.createBrowser(queue); assertNotNull(browser.getQueueBrowser()); browser.close(); try { browser.getQueueBrowser(); fail("Should not be able to use a closed browser"); } catch (IllegalStateException ise) { } }
Example #15
Source File: JmsQueueBrowserTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testGetMessageSelector() throws JMSException { JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection(); QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createTemporaryQueue(); QueueBrowser browser = session.createBrowser(queue, "color = red"); assertNotNull(browser.getMessageSelector()); assertEquals("color = red", browser.getMessageSelector()); browser.close(); try { browser.getMessageSelector(); fail("Should not be able to use a closed browser"); } catch (IllegalStateException ise) { } }
Example #16
Source File: ActiveMQSession.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void deleteTemporaryQueue(final ActiveMQDestination tempQueue) throws JMSException { if (!tempQueue.isTemporary()) { throw new InvalidDestinationException("Not a temporary queue " + tempQueue); } try { QueueQuery response = session.queueQuery(tempQueue.getSimpleAddress()); if (!response.isExists()) { throw new InvalidDestinationException("Cannot delete temporary queue " + tempQueue.getName() + " does not exist"); } if (response.getConsumerCount() > 0) { throw new IllegalStateException("Cannot delete temporary queue " + tempQueue.getName() + " since it has subscribers"); } SimpleString address = tempQueue.getSimpleAddress(); session.deleteQueue(address); connection.removeTemporaryQueue(address); } catch (ActiveMQException e) { throw JMSExceptionHelper.convertFromActiveMQException(e); } }
Example #17
Source File: ActiveMQRASession.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Unsubscribe * * @param name The name * @throws JMSException Thrown if an error occurs */ @Override public void unsubscribe(final String name) throws JMSException { if (cri.getType() == ActiveMQRAConnectionFactory.QUEUE_CONNECTION || cri.getType() == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION) { throw new IllegalStateException("Cannot unsubscribe for javax.jms.QueueSession"); } lock(); try { Session session = getSessionInternal(); if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("unsubscribe " + session + " name=" + name); } session.unsubscribe(name); } finally { unlock(); } }
Example #18
Source File: ActiveMQRASessionFactoryImpl.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Create a XA topic session * * @return The XA topic session * @throws JMSException Thrown if an error occurs */ @Override public XATopicSession createXATopicSession() throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("createXATopicSession()"); } checkClosed(); if (type == ActiveMQRAConnectionFactory.CONNECTION || type == ActiveMQRAConnectionFactory.QUEUE_CONNECTION || type == ActiveMQRAConnectionFactory.XA_QUEUE_CONNECTION) { throw new IllegalStateException("Can not get a topic session from a queue connection"); } return allocateConnection(type); }
Example #19
Source File: ActiveMQRASession.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Get the XA resource and ensure that it is open * * @return The XA Resource * @throws JMSException Thrown if an error occurs * @throws IllegalStateException The session is closed */ XAResource getXAResourceInternal() throws JMSException { if (mc == null) { throw new IllegalStateException("The session is closed"); } try { XAResource xares = mc.getXAResource(); if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("getXAResourceInternal " + xares + " for " + this); } return xares; } catch (ResourceException e) { JMSException jmse = new JMSException("Unable to get XA Resource"); jmse.initCause(e); throw jmse; } }
Example #20
Source File: PooledConnectionTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testSetClientIDAfterConnectionStart() throws Exception { LOG.debug("running testRepeatedSetClientIDCalls()"); ConnectionFactory cf = createPooledConnectionFactory(); Connection conn = cf.createConnection(); // test: try to call setClientID() after start() // should result in an exception try { conn.start(); conn.setClientID("newID3"); fail("Calling setClientID() after start() must raise a JMSException."); } catch (IllegalStateException ise) { LOG.debug("Correctly received " + ise); } finally { conn.close(); ((JmsPoolConnectionFactory) cf).stop(); } LOG.debug("Test finished."); }
Example #21
Source File: PooledConnectionTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testSetClientIDTwiceWithSameID() throws Exception { // test: call setClientID("newID") twice // this should be tolerated and not result in an exception Connection connection = cf.createConnection(); connection.setClientID("newID"); try { connection.setClientID("newID"); connection.start(); connection.close(); } catch (IllegalStateException ise) { LOG.error("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage()); fail("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage()); } finally { cf.stop(); } LOG.debug("Test finished."); }
Example #22
Source File: PooledConnectionTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testSetClientIDTwiceWithDifferentID() throws Exception { LOG.debug("running testRepeatedSetClientIDCalls()"); JmsPoolConnectionFactory cf = createPooledConnectionFactory(); Connection conn = cf.createConnection(); // test: call setClientID() twice with different IDs // this should result in an IllegalStateException conn.setClientID("newID1"); try { conn.setClientID("newID2"); fail("calling Connection.setClientID() twice with different clientID must raise an IllegalStateException"); } catch (IllegalStateException ise) { LOG.debug("Correctly received " + ise); } finally { cf.stop(); } LOG.debug("Test finished."); }
Example #23
Source File: ActiveMQSession.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public MessageConsumer createSharedDurableConsumer(Topic topic, String name, String messageSelector) throws JMSException { if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) { throw new IllegalStateException("Cannot create a shared durable consumer on a QueueSession"); } checkTopic(topic); ActiveMQTopic localTopic; if (topic instanceof ActiveMQTopic) { localTopic = (ActiveMQTopic) topic; } else { localTopic = new ActiveMQTopic(topic.getTopicName()); } return internalCreateSharedConsumer(localTopic, name, messageSelector, ConsumerDurability.DURABLE); }
Example #24
Source File: CommitRollbackTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Test public void testCommitOnClosedConnection() throws Exception { Session transactedSession; Connection connection = getConnection(); try { transactedSession = connection.createSession(true, Session.SESSION_TRANSACTED); } finally { connection.close(); } assertNotNull("Session cannot be null", transactedSession); try { transactedSession.commit(); fail("Commit on closed connection should throw IllegalStateException!"); } catch (IllegalStateException e) { // passed } }
Example #25
Source File: CommitRollbackTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Test public void testRollbackOnClosedSession() throws Exception { Connection connection = getConnection(); try { Session transactedSession = connection.createSession(true, Session.SESSION_TRANSACTED); transactedSession.close(); try { transactedSession.rollback(); fail("Rollback on closed session should throw IllegalStateException!"); } catch (IllegalStateException e) { // passed } } finally { connection.close(); } }
Example #26
Source File: CommitRollbackTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Test public void testGetTransactedOnClosedSession() throws Exception { Connection connection = getConnection(); try { Session transactedSession = connection.createSession(true, Session.SESSION_TRANSACTED); transactedSession.close(); try { transactedSession.getTransacted(); fail("According to Sun TCK invocation of Session#getTransacted on closed session should throw IllegalStateException!"); } catch (IllegalStateException e) { // passed } } finally { connection.close(); } }
Example #27
Source File: ActiveMQRASessionFactoryImpl.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Create a connection consumer -- throws IllegalStateException * * @param destination The destination * @param name The name * @param pool The session pool * @param maxMessages The number of max messages * @return The connection consumer * @throws JMSException Thrown if an error occurs */ @Override public ConnectionConsumer createConnectionConsumer(final Destination destination, final String name, final ServerSessionPool pool, final int maxMessages) throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("createConnectionConsumer(" + destination + ", " + name + ", " + pool + ", " + maxMessages + ")"); } throw new IllegalStateException(ISE); }
Example #28
Source File: OpenWireConnection.java From activemq-artemis with Apache License 2.0 | 6 votes |
private Transaction lookupTX(TransactionId txID, AMQSession session, boolean remove) throws IllegalStateException { if (txID == null) { return null; } Xid xid = null; Transaction transaction; if (txID.isXATransaction()) { xid = OpenWireUtil.toXID(txID); transaction = remove ? server.getResourceManager().removeTransaction(xid) : server.getResourceManager().getTransaction(xid); } else { transaction = remove ? txMap.remove(txID) : txMap.get(txID); } if (transaction == null) { return null; } if (session != null && transaction.getProtocolData() != session) { transaction.setProtocolData(session); } return transaction; }
Example #29
Source File: ChangeSessionDeliveryModeTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * test following condition- which are defined by JMS Spec 1.1: * MessageConsumers cannot use a MessageListener and receive() from the same * session * * @throws Exception */ public void testDoChangeSessionDeliveryMode() throws Exception { Destination destination = createDestination("foo.bar"); Connection connection = createConnection(); connection.start(); Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer1 = consumerSession.createConsumer(destination); consumer1.setMessageListener(this); MessageConsumer consumer2 = consumerSession.createConsumer(destination); try { consumer2.receive(10); fail("Did not receive expected exception."); } catch (JMSException e) { assertTrue(e instanceof IllegalStateException); } }
Example #30
Source File: DurableSubscriptionTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testUnsubscribeWithActiveConsumer() throws Exception { Connection conn = createConnection(); conn.setClientID("zeke"); Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); TopicSubscriber dursub = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "dursub0"); try { s.unsubscribe("dursub0"); ProxyAssertSupport.fail(); } catch (IllegalStateException e) { // Ok - it is illegal to ubscribe a subscription if it has active consumers } dursub.close(); s.unsubscribe("dursub0"); }