Search in sources :

Example 1 with InvalidDestinationException

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

the class MessageProducerTest method anonymousSenderSendToUnknownQueue.

@Test
public void anonymousSenderSendToUnknownQueue() 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(null);
            sender.send(invalidDestination, 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 2 with InvalidDestinationException

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

the class DurableSubscribtionTest method unsubscribeTwice.

@Test
public void unsubscribeTwice() throws Exception {
    Topic topic = createTopic(getTestName());
    Connection connection = getConnection();
    String subscriptionName = getTestName() + "_sub";
    try {
        Session subscriberSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
        TopicSubscriber subscriber = subscriberSession.createDurableSubscriber(topic, subscriptionName);
        MessageProducer publisher = subscriberSession.createProducer(topic);
        connection.start();
        publisher.send(subscriberSession.createTextMessage("Test"));
        subscriberSession.commit();
        Message message = subscriber.receive(getReceiveTimeout());
        assertTrue("TextMessage should be received", message instanceof TextMessage);
        assertEquals("Unexpected message", "Test", ((TextMessage) message).getText());
        subscriberSession.commit();
        subscriber.close();
        subscriberSession.unsubscribe(subscriptionName);
        try {
            subscriberSession.unsubscribe(subscriptionName);
            fail("expected InvalidDestinationException when unsubscribing from unknown subscription");
        } catch (InvalidDestinationException e) {
        // PASS
        } catch (Exception e) {
            fail("expected InvalidDestinationException when unsubscribing from unknown subscription, got: " + e);
        }
    } finally {
        connection.close();
    }
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) JMSException(javax.jms.JMSException) InvalidDestinationException(javax.jms.InvalidDestinationException) Session(javax.jms.Session) TopicSession(javax.jms.TopicSession) Test(org.junit.Test)

Example 3 with InvalidDestinationException

use of javax.jms.InvalidDestinationException in project nifi by apache.

the class GetJMSTopic method handleSubscriptions.

@OnScheduled
public void handleSubscriptions(final ProcessContext context) throws IOException, JMSException {
    boolean usingDurableSubscription = context.getProperty(DURABLE_SUBSCRIPTION).asBoolean();
    final Properties persistedProps = getSubscriptionPropertiesFromFile();
    final Properties currentProps = getSubscriptionPropertiesFromContext(context);
    if (persistedProps == null) {
        if (usingDurableSubscription) {
            // properties have not yet been persisted.
            persistSubscriptionInfo(context);
        }
        return;
    }
    // decrypt the passwords so the persisted and current properties can be compared...
    // we can modify this properties instance since the unsubscribe method will reload
    // the properties from disk
    decryptPassword(persistedProps, context);
    decryptPassword(currentProps, context);
    // check if current values are the same as the persisted values.
    boolean same = true;
    for (final Map.Entry<Object, Object> entry : persistedProps.entrySet()) {
        final Object key = entry.getKey();
        final Object value = entry.getValue();
        final Object curVal = currentProps.get(key);
        if (value == null && curVal == null) {
            continue;
        }
        if (value == null || curVal == null) {
            same = false;
            break;
        }
        if (SUBSCRIPTION_NAME_PROPERTY.equals(key)) {
            // ignore the random UUID part of the subscription name
            if (!JmsFactory.clientIdPrefixEquals(value.toString(), curVal.toString())) {
                same = false;
                break;
            }
        } else if (!value.equals(curVal)) {
            same = false;
            break;
        }
    }
    if (same && usingDurableSubscription) {
        // properties are the same.
        return;
    }
    // unsubscribe from the old subscription.
    try {
        unsubscribe(context);
    } catch (final InvalidDestinationException e) {
        getLogger().warn("Failed to unsubscribe from subscription due to {}; subscription does not appear to be active, so ignoring it", new Object[] { e });
    }
    // we've now got a new subscription, so we must persist that new info before we create the subscription.
    if (usingDurableSubscription) {
        persistSubscriptionInfo(context);
    } else {
        // remove old subscription info if it was persisted
        try {
            Files.delete(getSubscriptionPath());
        } catch (Exception ignore) {
        }
    }
}
Also used : InvalidDestinationException(javax.jms.InvalidDestinationException) JmsProperties(org.apache.nifi.processors.standard.util.JmsProperties) Properties(java.util.Properties) Map(java.util.Map) ProcessException(org.apache.nifi.processor.exception.ProcessException) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 4 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, String message, String messageType, long timeToLive, int deliveryMode, int priority, boolean ignoreInvalidDestinationException, Map properties) throws NamingException, JMSException, SenderException {
    TextMessage msg = createTextMessage(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;
        } else {
            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 it = properties.keySet().iterator(); it.hasNext(); ) {
            String key = (String) it.next();
            Object value = properties.get(key);
            log.debug("setting property [" + name + "] to value [" + value + "]");
            msg.setObjectProperty(key, value);
        }
    }
    String result = send(mp, msg, ignoreInvalidDestinationException);
    mp.close();
    return result;
}
Also used : TopicSession(javax.jms.TopicSession) Iterator(java.util.Iterator) InvalidDestinationException(javax.jms.InvalidDestinationException) INamedObject(nl.nn.adapterframework.core.INamedObject) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) SenderException(nl.nn.adapterframework.core.SenderException) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) QueueSession(javax.jms.QueueSession)

Example 5 with InvalidDestinationException

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

the class ActiveMQSession method internalCreateSharedConsumer.

/**
 * This is an internal method for shared consumers
 */
private ActiveMQMessageConsumer internalCreateSharedConsumer(final ActiveMQDestination dest, final String subscriptionName, String selectorString, ConsumerDurability durability) throws JMSException {
    try {
        if (dest.isQueue()) {
            // createSharedConsumer only accepts Topics by declaration
            throw new RuntimeException("Internal error: createSharedConsumer is only meant for Topics");
        }
        if (subscriptionName == null) {
            throw ActiveMQJMSClientBundle.BUNDLE.invalidSubscriptionName();
        }
        selectorString = "".equals(selectorString) ? null : selectorString;
        SimpleString coreFilterString = null;
        if (selectorString != null) {
            coreFilterString = new SimpleString(SelectorTranslator.convertToActiveMQFilterString(selectorString));
        }
        ClientConsumer consumer;
        SimpleString autoDeleteQueueName = null;
        AddressQuery response = session.addressQuery(dest.getSimpleAddress());
        if (!response.isExists() && !response.isAutoCreateAddresses()) {
            throw ActiveMQJMSClientBundle.BUNDLE.destinationDoesNotExist(dest.getSimpleAddress());
        }
        SimpleString queueName;
        if (dest.isTemporary() && durability == ConsumerDurability.DURABLE) {
            throw new InvalidDestinationException("Cannot create a durable subscription on a temporary topic");
        }
        queueName = ActiveMQDestination.createQueueNameForSubscription(durability == ConsumerDurability.DURABLE, connection.getClientID(), subscriptionName);
        try {
            if (durability == ConsumerDurability.DURABLE) {
                createSharedQueue(dest, RoutingType.MULTICAST, queueName, coreFilterString, true, response.getDefaultMaxConsumers(), response.isDefaultPurgeOnNoConsumers(), response.isDefaultExclusive(), response.isDefaultLastValueQueue());
            } else {
                createSharedQueue(dest, RoutingType.MULTICAST, queueName, coreFilterString, false, response.getDefaultMaxConsumers(), response.isDefaultPurgeOnNoConsumers(), response.isDefaultExclusive(), response.isDefaultLastValueQueue());
            }
        } catch (ActiveMQQueueExistsException ignored) {
        // We ignore this because querying and then creating the queue wouldn't be idempotent
        // we could also add a parameter to ignore existence what would require a bigger work around to avoid
        // compatibility.
        }
        consumer = session.createConsumer(queueName, null, false);
        ActiveMQMessageConsumer jbc = new ActiveMQMessageConsumer(options, connection, this, consumer, false, dest, selectorString, autoDeleteQueueName);
        consumers.add(jbc);
        return jbc;
    } catch (ActiveMQException e) {
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    }
}
Also used : AddressQuery(org.apache.activemq.artemis.api.core.client.ClientSession.AddressQuery) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer)

Aggregations

InvalidDestinationException (javax.jms.InvalidDestinationException)36 Test (org.junit.Test)19 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)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)9 MessageProducer (javax.jms.MessageProducer)8 Queue (javax.jms.Queue)8 TextMessage (javax.jms.TextMessage)7 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 TopicSession (javax.jms.TopicSession)6 IllegalStateException (javax.jms.IllegalStateException)5 TopicConnection (javax.jms.TopicConnection)5 QueueSession (javax.jms.QueueSession)4 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)4 AddressQuery (org.apache.activemq.artemis.api.core.client.ClientSession.AddressQuery)4 MessageConsumer (javax.jms.MessageConsumer)3 IOException (java.io.IOException)2