Search in sources :

Example 21 with IllegalStateException

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

the class DurableSubscriptionTest method testSubscribeWithActiveSubscription.

@Test
public void testSubscribeWithActiveSubscription() throws Exception {
    Connection conn = createConnection();
    conn.setClientID("zeke");
    Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber dursub1 = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "dursub1");
    try {
        s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "dursub1");
        ProxyAssertSupport.fail();
    } catch (IllegalStateException e) {
    // Ok - it is illegal to have more than one active subscriber on a subscrtiption at any one time
    }
    dursub1.close();
    s.unsubscribe("dursub1");
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) IllegalStateException(javax.jms.IllegalStateException) Connection(javax.jms.Connection) Session(javax.jms.Session) Test(org.junit.Test)

Example 22 with IllegalStateException

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

the class SecurityTest method testSetClientIDAfterOp.

/*
    * Try setting client ID after an operation has been performed on the connection
    */
@Test
public void testSetClientIDAfterOp() throws Exception {
    Connection conn = createConnection();
    conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
        conn.setClientID("myID");
        ProxyAssertSupport.fail();
    } catch (IllegalStateException e) {
    // Expected
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) Connection(javax.jms.Connection) Test(org.junit.Test)

Example 23 with IllegalStateException

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

the class SecurityTest method testSetClientIDPreConf.

/**
 * Try setting client ID on preconfigured connection - should throw exception
 */
@Test
public void testSetClientIDPreConf() throws Exception {
    Connection conn = null;
    try {
        ActiveMQServerTestCase.deployConnectionFactory("dilbert-id", "preConfcf", "preConfcf");
        ConnectionFactory cf = (ConnectionFactory) getInitialContext().lookup("preConfcf");
        conn = cf.createConnection("guest", "guest");
        conn.setClientID("myID");
        ProxyAssertSupport.fail();
    } catch (IllegalStateException e) {
    // Expected
    } finally {
        if (conn != null) {
            conn.close();
        }
        ActiveMQServerTestCase.undeployConnectionFactory("preConfcf");
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) Connection(javax.jms.Connection) Test(org.junit.Test)

Example 24 with IllegalStateException

use of javax.jms.IllegalStateException in project spring-framework by spring-projects.

the class MessageListenerAdapterTests method testFailsIfNoDefaultListenerMethodNameIsSupplied.

@Test
public void testFailsIfNoDefaultListenerMethodNameIsSupplied() throws Exception {
    final TextMessage message = mock(TextMessage.class);
    given(message.getText()).willReturn(TEXT);
    final MessageListenerAdapter adapter = new MessageListenerAdapter() {

        @Override
        protected void handleListenerException(Throwable ex) {
            assertTrue(ex instanceof IllegalStateException);
        }
    };
    adapter.setDefaultListenerMethod(null);
    adapter.onMessage(message);
}
Also used : IllegalStateException(javax.jms.IllegalStateException) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 25 with IllegalStateException

use of javax.jms.IllegalStateException in project karaf by apache.

the class ConnectionPool method createSession.

public Session createSession(boolean transacted, int ackMode) throws JMSException {
    SessionKey key = new SessionKey(transacted, ackMode);
    PooledSession session;
    try {
        session = sessionPool.borrowObject(key);
    } catch (Exception e) {
        IllegalStateException illegalStateException = new IllegalStateException(e.toString());
        illegalStateException.initCause(e);
        throw illegalStateException;
    }
    return session;
}
Also used : IllegalStateException(javax.jms.IllegalStateException) IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException)

Aggregations

IllegalStateException (javax.jms.IllegalStateException)44 Session (javax.jms.Session)19 Connection (javax.jms.Connection)12 QueueSession (javax.jms.QueueSession)12 Test (org.junit.Test)12 TopicSession (javax.jms.TopicSession)11 XAQueueSession (javax.jms.XAQueueSession)11 XATopicSession (javax.jms.XATopicSession)11 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)11 JMSException (javax.jms.JMSException)10 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 InvalidDestinationException (javax.jms.InvalidDestinationException)5 IOException (java.io.IOException)4 Queue (javax.jms.Queue)3 QueueBrowser (javax.jms.QueueBrowser)3 TopicSubscriber (javax.jms.TopicSubscriber)3 QueueQuery (org.apache.activemq.artemis.api.core.client.ClientSession.QueueQuery)3 RMQJMSException (com.rabbitmq.jms.util.RMQJMSException)2 TemporaryQueue (javax.jms.TemporaryQueue)2