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();
}
}
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();
}
}
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) {
}
}
}
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;
}
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);
}
}
Aggregations