Search in sources :

Example 31 with InvalidDestinationException

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

the class InvalidDestinationTest method invalidDestinationExceptionTests.

@Test
public void invalidDestinationExceptionTests() throws Exception {
    Destination invalidDestination = null;
    Topic invalidTopic = null;
    Connection conn = cf.createConnection();
    try {
        Session session = conn.createSession();
        try {
            session.createDurableSubscriber(invalidTopic, "InvalidDestinationException");
        } catch (InvalidDestinationException e) {
        // pass
        } catch (Exception e) {
            fail("Expected InvalidDestinationException, received " + e);
        }
        try {
            session.createDurableSubscriber(invalidTopic, "InvalidDestinationException", "lastMessage = TRUE", false);
        } catch (InvalidDestinationException e) {
        // pass
        } catch (Exception e) {
            fail("Expected InvalidDestinationException, received " + e);
        }
        System.out.println("Testing Session.createDurableConsumer(Topic, String) for InvalidDestinationException");
        try {
            session.createDurableConsumer(invalidTopic, "InvalidDestinationException");
        } catch (InvalidDestinationException e) {
        // pass
        } catch (Exception e) {
            fail("Expected InvalidDestinationException, received " + e);
        }
        try {
            session.createDurableConsumer(invalidTopic, "InvalidDestinationException", "lastMessage = TRUE", false);
        } catch (InvalidDestinationException e) {
        // pass
        } catch (Exception e) {
            fail("Expected InvalidDestinationException, received " + e);
        }
        try {
            session.createSharedConsumer(invalidTopic, "InvalidDestinationException");
        } catch (InvalidDestinationException e) {
        // pass
        } catch (Exception e) {
            fail("Expected InvalidDestinationException, received " + e);
        }
        try {
            session.createSharedConsumer(invalidTopic, "InvalidDestinationException", "lastMessage = TRUE");
        } catch (InvalidDestinationException e) {
        // pass
        } catch (Exception e) {
            fail("Expected InvalidDestinationException, received " + e);
        }
        try {
            session.createSharedDurableConsumer(invalidTopic, "InvalidDestinationException");
        } catch (InvalidDestinationException e) {
        // pass
        } catch (Exception e) {
            fail("Expected InvalidDestinationException, received " + e);
        }
        try {
            session.createSharedDurableConsumer(invalidTopic, "InvalidDestinationException", "lastMessage = TRUE");
        } catch (InvalidDestinationException e) {
        // pass
        } catch (Exception e) {
            fail("Expected InvalidDestinationException, received " + e);
        }
    } finally {
        conn.close();
    }
}
Also used : Destination(javax.jms.Destination) Connection(javax.jms.Connection) InvalidDestinationException(javax.jms.InvalidDestinationException) Topic(javax.jms.Topic) InvalidDestinationException(javax.jms.InvalidDestinationException) InvalidDestinationRuntimeException(javax.jms.InvalidDestinationRuntimeException) Session(javax.jms.Session) Test(org.junit.Test)

Example 32 with InvalidDestinationException

use of javax.jms.InvalidDestinationException in project iaf by ibissource.

the class JMSFacade method send.

public String send(Session session, Destination dest, javax.jms.Message message, boolean ignoreInvalidDestinationException) throws NamingException, JMSException {
    try {
        if (useJms102()) {
            if (dest instanceof Topic) {
                return sendByTopic((TopicSession) session, (Topic) dest, message);
            }
            return sendByQueue((QueueSession) session, (Queue) dest, message);
        }
        MessageProducer mp = session.createProducer(dest);
        mp.send(message);
        mp.close();
        return message.getJMSMessageID();
    } catch (InvalidDestinationException e) {
        if (ignoreInvalidDestinationException) {
            log.warn("queue [" + dest + "] doesn't exist");
            return null;
        }
        throw e;
    }
}
Also used : InvalidDestinationException(javax.jms.InvalidDestinationException) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic)

Example 33 with InvalidDestinationException

use of javax.jms.InvalidDestinationException in project iaf by ibissource.

the class JMSFacade method send.

public String send(Session session, Destination dest, String correlationId, Message message, String messageType, long timeToLive, int deliveryMode, int priority, boolean ignoreInvalidDestinationException, Map<String, Object> properties) throws NamingException, JMSException, SenderException, IOException {
    javax.jms.Message msg = createMessage(session, correlationId, message);
    MessageProducer mp;
    try {
        if (useJms102()) {
            if ((session instanceof TopicSession) && (dest instanceof Topic)) {
                mp = getTopicPublisher((TopicSession) session, (Topic) dest);
            } else {
                if ((session instanceof QueueSession) && (dest instanceof Queue)) {
                    mp = getQueueSender((QueueSession) session, (Queue) dest);
                } else {
                    throw new SenderException("classes of Session [" + session.getClass().getName() + "] and Destination [" + dest.getClass().getName() + "] do not match (Queue vs Topic)");
                }
            }
        } else {
            mp = session.createProducer(dest);
        }
    } catch (InvalidDestinationException e) {
        if (ignoreInvalidDestinationException) {
            log.warn("queue [" + dest + "] doesn't exist");
            return null;
        }
        throw e;
    }
    if (messageType != null) {
        msg.setJMSType(messageType);
    }
    if (deliveryMode > 0) {
        msg.setJMSDeliveryMode(deliveryMode);
        mp.setDeliveryMode(deliveryMode);
    }
    if (priority >= 0) {
        msg.setJMSPriority(priority);
        mp.setPriority(priority);
    }
    if (timeToLive > 0) {
        mp.setTimeToLive(timeToLive);
    }
    if (properties != null) {
        for (Iterator<String> it = properties.keySet().iterator(); it.hasNext(); ) {
            String key = it.next();
            Object value = properties.get(key);
            if (value instanceof Message) {
                value = ((Message) value).asString();
            }
            msg.setObjectProperty(key, value);
        }
    }
    String result = send(mp, msg, ignoreInvalidDestinationException);
    mp.close();
    return result;
}
Also used : TopicSession(javax.jms.TopicSession) Message(nl.nn.adapterframework.stream.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) SenderException(nl.nn.adapterframework.core.SenderException) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession)

Example 34 with InvalidDestinationException

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

the class MessageProducerTest method produceToUnknownQueue.

@Test
public void produceToUnknownQueue() throws Exception {
    assumeThat("QPID-7818", getProtocol(), is(not(equalTo(Protocol.AMQP_0_10))));
    Connection connection = getConnectionBuilder().setSyncPublish(true).build();
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue invalidDestination = session.createQueue("unknown");
        try {
            MessageProducer sender = session.createProducer(invalidDestination);
            sender.send(session.createMessage());
            fail("Exception not thrown");
        } catch (InvalidDestinationException e) {
        // PASS
        } catch (JMSException e) {
            assertThat("Allowed for the Qpid JMS AMQP 0-x client", getProtocol(), is(not(equalTo(Protocol.AMQP_1_0))));
        // PASS
        }
    } finally {
        connection.close();
    }
}
Also used : Connection(javax.jms.Connection) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Example 35 with InvalidDestinationException

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

the class DurableSubscribtionTest method testDurableSubscribeWithTemporaryTopic.

@Test
public void testDurableSubscribeWithTemporaryTopic() throws Exception {
    assumeThat("Not investigated - fails on AMQP 1.0", getProtocol(), is(not(equalTo(Protocol.AMQP_1_0))));
    Connection connection = getConnection();
    try {
        connection.start();
        Session ssn = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = ssn.createTemporaryTopic();
        try {
            ssn.createDurableSubscriber(topic, "test");
            fail("expected InvalidDestinationException");
        } catch (InvalidDestinationException ex) {
        // this is expected
        }
        try {
            ssn.createDurableSubscriber(topic, "test", null, false);
            fail("expected InvalidDestinationException");
        } catch (InvalidDestinationException ex) {
        // this is expected
        }
    } finally {
        connection.close();
    }
}
Also used : Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) InvalidDestinationException(javax.jms.InvalidDestinationException) Topic(javax.jms.Topic) Session(javax.jms.Session) TopicSession(javax.jms.TopicSession) 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