Search in sources :

Example 36 with InvalidDestinationException

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

the class QueueSenderTest method sendToUnknownQueue.

@Test
public void sendToUnknownQueue() throws Exception {
    QueueConnection connection = ((QueueConnection) getConnectionBuilder().build());
    try {
        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue invalidDestination = session.createQueue("unknown");
        try {
            QueueSender sender = session.createSender(invalidDestination);
            sender.send(session.createMessage());
            fail("Exception not thrown");
        } catch (InvalidDestinationException e) {
        // PASS
        }
    } finally {
        connection.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) InvalidDestinationException(javax.jms.InvalidDestinationException) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 37 with InvalidDestinationException

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

the class QueueSenderTest method anonymousSenderSendToUnknownQueue.

@Test
public void anonymousSenderSendToUnknownQueue() throws Exception {
    QueueConnection connection = ((QueueConnection) getConnectionBuilder().setSyncPublish(true).build());
    try {
        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue invalidDestination = session.createQueue("unknown");
        try {
            QueueSender sender = session.createSender(null);
            sender.send(invalidDestination, session.createMessage());
            fail("Exception not thrown");
        } catch (InvalidDestinationException e) {
        // PASS
        }
    } finally {
        connection.close();
    }
}
Also used : QueueConnection(javax.jms.QueueConnection) QueueSender(javax.jms.QueueSender) InvalidDestinationException(javax.jms.InvalidDestinationException) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession) Test(org.junit.Test)

Example 38 with InvalidDestinationException

use of javax.jms.InvalidDestinationException in project rabbitmq-jms-client by rabbitmq.

the class RMQMessageProducer method internalSend.

private void internalSend(RMQDestination destination, Message message, int deliveryMode, int priority, long timeToLiveOrExpiration, MessageExpirationType messageExpirationType) throws JMSException {
    logger.trace("send/publish message({}) to destination({}) with properties deliveryMode({}), priority({}), timeToLive({})", message, destination, deliveryMode, priority, timeToLiveOrExpiration);
    this.sendingContextConsumer.accept(new SendingContext(destination, message));
    if (destination == null)
        destination = this.destination;
    if (destination == null)
        throw new InvalidDestinationException("No destination supplied, or implied.");
    if (deliveryMode != javax.jms.DeliveryMode.PERSISTENT)
        deliveryMode = javax.jms.DeliveryMode.NON_PERSISTENT;
    /* Normalise message to internal form */
    RMQMessage rmqMessage = RMQMessage.normalise(message);
    /* Set known JMS message properties that need to be set during this call */
    long currentTime = System.currentTimeMillis();
    long expiration;
    long ttl;
    if (messageExpirationType == MessageExpirationType.TTL) {
        expiration = timeToLiveOrExpiration == 0L ? 0L : currentTime + timeToLiveOrExpiration;
        ttl = timeToLiveOrExpiration;
    } else {
        expiration = timeToLiveOrExpiration;
        ttl = timeToLiveOrExpiration - currentTime;
    }
    rmqMessage.setJMSDeliveryMode(deliveryMode);
    rmqMessage.setJMSPriority(priority);
    rmqMessage.setJMSExpiration(expiration);
    rmqMessage.setJMSDestination(destination);
    rmqMessage.setJMSTimestamp(currentTime);
    rmqMessage.generateInternalID();
    /* Now send it */
    if (destination.isAmqp()) {
        sendAMQPMessage(destination, rmqMessage, message, deliveryMode, priority, ttl);
    } else {
        sendJMSMessage(destination, rmqMessage, message, deliveryMode, priority, ttl);
    }
}
Also used : InvalidDestinationException(javax.jms.InvalidDestinationException)

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