Search in sources :

Example 81 with TemporaryQueue

use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.

the class AuthenticationTest method assertPlainConnectivity.

private void assertPlainConnectivity(final int port, final String mechanism) throws Exception {
    final Connection connection = getConnectionBuilder().setPort(port).setUsername(USER).setPassword(USER_PASSWORD).setSaslMechanisms(mechanism).build();
    try {
        final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final TemporaryQueue queue = session.createTemporaryQueue();
        assertNotNull("Temporary queue was not created", queue);
    } finally {
        connection.close();
    }
    try {
        getConnectionBuilder().setPort(port).setUsername(USER).setPassword("invalid" + USER_PASSWORD).setSaslMechanisms(mechanism).build();
        fail("Connection is established for invalid password");
    } catch (JMSException e) {
    // pass
    }
    try {
        getConnectionBuilder().setPort(port).setUsername("invalid" + AuthenticationTest.USER).setPassword(USER_PASSWORD).setSaslMechanisms(mechanism).build();
        fail("Connection is established for invalid user name");
    } catch (JMSException e) {
    // pass
    }
}
Also used : Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Example 82 with TemporaryQueue

use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.

the class TemporaryQueueTest method testConsumeFromAnotherConnectionUsingTemporaryQueueName.

@Test
public void testConsumeFromAnotherConnectionUsingTemporaryQueueName() throws Exception {
    final Connection connection = getConnection();
    try {
        final Connection connection2 = getConnection();
        try {
            final Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            final Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
            final TemporaryQueue queue = session1.createTemporaryQueue();
            assertNotNull("Temporary queue cannot be null", queue);
            try {
                session2.createConsumer(session2.createQueue(queue.getQueueName()));
                fail("Expected a JMSException when subscribing to a temporary queue created on a different session");
            } catch (JMSException je) {
            // pass
            }
        } finally {
            connection2.close();
        }
    } finally {
        connection.close();
    }
}
Also used : Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) Session(javax.jms.Session) Test(org.junit.Test)

Example 83 with TemporaryQueue

use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.

the class TemporaryQueueTest method testConsumeFromAnotherConnectionProhibited.

@Test
public void testConsumeFromAnotherConnectionProhibited() throws Exception {
    final Connection connection = getConnection();
    try {
        final Connection connection2 = getConnection();
        try {
            final Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            final Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
            final TemporaryQueue queue = session1.createTemporaryQueue();
            assertNotNull("Temporary queue cannot be null", queue);
            try {
                session2.createConsumer(queue);
                fail("Expected a JMSException when subscribing to a temporary queue created on a different session");
            } catch (JMSException je) {
            // pass
            }
        } finally {
            connection2.close();
        }
    } finally {
        connection.close();
    }
}
Also used : Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) Session(javax.jms.Session) Test(org.junit.Test)

Example 84 with TemporaryQueue

use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.

the class TemporaryQueueTest method testExplicitTemporaryQueueDeletion.

@Test
public void testExplicitTemporaryQueueDeletion() throws Exception {
    int numberOfQueuesBeforeTest = getQueueCount();
    final Connection connection = getConnection();
    try {
        final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final TemporaryQueue queue = session.createTemporaryQueue();
        assertNotNull("Temporary queue cannot be null", queue);
        final MessageConsumer consumer = session.createConsumer(queue);
        connection.start();
        try {
            queue.delete();
            fail("Expected JMSException : should not be able to delete while there are active consumers");
        } catch (JMSException je) {
        // pass
        }
        int numberOfQueuesAfterQueueDelete = getQueueCount();
        assertEquals("Unexpected number of queue", 1, numberOfQueuesAfterQueueDelete - numberOfQueuesBeforeTest);
        consumer.close();
        // Now deletion should succeed.
        queue.delete();
        try {
            session.createConsumer(queue);
            fail("Exception not thrown");
        } catch (JMSException je) {
        // pass
        }
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) Session(javax.jms.Session) Test(org.junit.Test)

Example 85 with TemporaryQueue

use of javax.jms.TemporaryQueue in project qpid-broker-j by apache.

the class TemporaryQueueTest method delete.

@Test
public void delete() throws Exception {
    Connection connection = getConnectionBuilder().setSyncPublish(true).build();
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TemporaryQueue queue = session.createTemporaryQueue();
        MessageProducer producer = session.createProducer(queue);
        try {
            producer.send(session.createTextMessage("hello"));
        } catch (JMSException e) {
            fail("Send to temporary queue should succeed");
        }
        try {
            queue.delete();
        } catch (JMSException e) {
            fail("temporary queue should be deletable");
        }
        try {
            producer.send(session.createTextMessage("hello"));
            fail("Send to deleted temporary queue should not succeed");
        } catch (JMSException e) {
        // pass
        }
    } finally {
        connection.close();
    }
}
Also used : Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

TemporaryQueue (javax.jms.TemporaryQueue)91 Session (javax.jms.Session)56 Test (org.junit.Test)47 Connection (javax.jms.Connection)45 MessageProducer (javax.jms.MessageProducer)38 MessageConsumer (javax.jms.MessageConsumer)35 Message (javax.jms.Message)27 JMSException (javax.jms.JMSException)25 TextMessage (javax.jms.TextMessage)24 JMSContext (javax.jms.JMSContext)13 BytesMessage (javax.jms.BytesMessage)10 Destination (javax.jms.Destination)8 Queue (javax.jms.Queue)8 ConnectionFactory (javax.jms.ConnectionFactory)7 ObjectMessage (javax.jms.ObjectMessage)7 JMSConsumer (javax.jms.JMSConsumer)6 TemporaryTopic (javax.jms.TemporaryTopic)6 HashMap (java.util.HashMap)5 MapMessage (javax.jms.MapMessage)5 StreamMessage (javax.jms.StreamMessage)5