Search in sources :

Example 21 with InvalidDestinationException

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

the class JmsTempDestinationTest method testTempDestOnlyConsumedByLocalConn.

/**
 * Make sure Temp destination can only be consumed by local connection
 *
 * @throws JMSException
 */
@Test
public void testTempDestOnlyConsumedByLocalConn() throws JMSException {
    connection.start();
    Session tempSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue queue = tempSession.createTemporaryQueue();
    MessageProducer producer = tempSession.createProducer(queue);
    producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    TextMessage message = tempSession.createTextMessage("First");
    producer.send(message);
    // temp destination should not be consume when using another connection
    Connection otherConnection = factory.createConnection();
    connections.add(otherConnection);
    Session otherSession = otherConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue otherQueue = otherSession.createTemporaryQueue();
    MessageConsumer consumer = otherSession.createConsumer(otherQueue);
    Message msg = consumer.receive(3000);
    Assert.assertNull(msg);
    // destination from another connection
    try {
        consumer = otherSession.createConsumer(queue);
        Assert.fail("Send should fail since temp destination should be used from another connection");
    } catch (InvalidDestinationException e) {
        Assert.assertTrue("failed to throw an exception", true);
    }
    // should be able to consume temp destination from the same connection
    consumer = tempSession.createConsumer(queue);
    msg = consumer.receive(3000);
    Assert.assertNotNull(msg);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 22 with InvalidDestinationException

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

the class AmqpFullyQualifiedNameTest method testFQQNTopicWhenQueueDoesNotExist.

@Test
public void testFQQNTopicWhenQueueDoesNotExist() throws Exception {
    Exception e = null;
    String queueName = "testQueue";
    Connection connection = createConnection(false);
    try {
        connection.setClientID("FQQNconn");
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(multicastAddress.toString() + "::" + queueName);
        session.createConsumer(topic);
    } catch (InvalidDestinationException ide) {
        e = ide;
    } finally {
        connection.close();
    }
    assertNotNull(e);
    assertTrue(e.getMessage().contains("Queue: '" + queueName + "' does not exist"));
}
Also used : Connection(javax.jms.Connection) InvalidDestinationException(javax.jms.InvalidDestinationException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Topic(javax.jms.Topic) InvalidDestinationException(javax.jms.InvalidDestinationException) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 23 with InvalidDestinationException

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

the class AmqpFullyQualifiedNameTest method testConsumeQueueToFQQNWrongQueueAttachedToAnotherAddress.

@Test
public void testConsumeQueueToFQQNWrongQueueAttachedToAnotherAddress() throws Exception {
    // Create 2 Queues: address1::queue1, address2::queue2
    String address1 = "a1";
    String address2 = "a2";
    String queue1 = "q1";
    String queue2 = "q2";
    server.createQueue(SimpleString.toSimpleString(address1), RoutingType.ANYCAST, SimpleString.toSimpleString(queue1), null, true, false, -1, false, true);
    server.createQueue(SimpleString.toSimpleString(address2), RoutingType.ANYCAST, SimpleString.toSimpleString(queue2), null, true, false, -1, false, true);
    Exception e = null;
    // Wrong FQQN.  Attempt to subscribe to a queue belonging to a different address than given in the FQQN.
    String wrongFQQN = address1 + "::" + queue2;
    Connection connection = createConnection(false);
    try {
        connection.setClientID("FQQNconn");
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        javax.jms.Queue queue = session.createQueue(wrongFQQN);
        session.createConsumer(queue);
    } catch (InvalidDestinationException ide) {
        e = ide;
    } finally {
        connection.close();
    }
    assertNotNull(e);
    assertTrue(e.getMessage().contains("Queue: '" + queue2 + "' does not exist for address '" + address1 + "'"));
}
Also used : Connection(javax.jms.Connection) InvalidDestinationException(javax.jms.InvalidDestinationException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 24 with InvalidDestinationException

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

the class AmqpFullyQualifiedNameTest method testQueueSpecial.

/**
 * Broker should return exception if no address is passed in FQQN.
 * @throws Exception
 */
@Test
public void testQueueSpecial() throws Exception {
    server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ1, null, true, false, -1, false, true);
    Connection connection = createConnection();
    Exception expectedException = null;
    try {
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // ::queue ok!
        String specialName = CompositeAddress.toFullQN(new SimpleString(""), anycastQ1).toString();
        javax.jms.Queue q1 = session.createQueue(specialName);
        session.createConsumer(q1);
    } catch (InvalidDestinationException e) {
        expectedException = e;
    }
    assertNotNull(expectedException);
    assertTrue(expectedException.getMessage().contains("Queue: 'q1' does not exist for address ''"));
}
Also used : Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 25 with InvalidDestinationException

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

the class MessageProducerTest method testCreateProducerOnInexistentDestination.

@Test
public void testCreateProducerOnInexistentDestination() throws Exception {
    getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false));
    getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false));
    Connection pconn = createConnection();
    try {
        Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        try {
            ps.createProducer(ActiveMQJMSClient.createTopic("NoSuchTopic"));
            ProxyAssertSupport.fail("should throw exception");
        } catch (InvalidDestinationException e) {
        // OK
        }
    } finally {
        pconn.close();
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Connection(javax.jms.Connection) InvalidDestinationException(javax.jms.InvalidDestinationException) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

InvalidDestinationException (javax.jms.InvalidDestinationException)38 Test (org.junit.Test)20 Session (javax.jms.Session)18 Connection (javax.jms.Connection)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)13 JMSException (javax.jms.JMSException)11 Topic (javax.jms.Topic)11 MessageProducer (javax.jms.MessageProducer)10 Queue (javax.jms.Queue)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)9 TextMessage (javax.jms.TextMessage)8 TopicSession (javax.jms.TopicSession)7 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 IllegalStateException (javax.jms.IllegalStateException)5 QueueSession (javax.jms.QueueSession)5 TopicConnection (javax.jms.TopicConnection)5 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)4 AddressQuery (org.apache.activemq.artemis.api.core.client.ClientSession.AddressQuery)4 BytesMessage (javax.jms.BytesMessage)3 MessageConsumer (javax.jms.MessageConsumer)3