use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class ActiveMQMessage method setJMSReplyTo.
@Override
public void setJMSReplyTo(final Destination dest) throws JMSException {
if (dest == null) {
MessageUtil.setJMSReplyTo(message, (String) null);
replyTo = null;
} else {
if (dest instanceof ActiveMQDestination == false) {
throw new InvalidDestinationException("Foreign destination " + dest);
}
String prefix = "";
if (dest instanceof ActiveMQTemporaryQueue) {
prefix = TEMP_QUEUE_QUALIFED_PREFIX;
} else if (dest instanceof ActiveMQQueue) {
prefix = QUEUE_QUALIFIED_PREFIX;
} else if (dest instanceof ActiveMQTemporaryTopic) {
prefix = TEMP_TOPIC_QUALIFED_PREFIX;
} else if (dest instanceof ActiveMQTopic) {
prefix = TOPIC_QUALIFIED_PREFIX;
}
ActiveMQDestination jbd = (ActiveMQDestination) dest;
MessageUtil.setJMSReplyTo(message, prefix + jbd.getAddress());
replyTo = jbd;
}
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class ActiveMQMessageProducer method doSendx.
private void doSendx(ActiveMQDestination destination, final Message jmsMessage, final int deliveryMode, final int priority, final long timeToLive, CompletionListener completionListener) throws JMSException {
jmsMessage.setJMSDeliveryMode(deliveryMode);
jmsMessage.setJMSPriority(priority);
if (timeToLive == 0) {
jmsMessage.setJMSExpiration(0);
} else {
jmsMessage.setJMSExpiration(System.currentTimeMillis() + timeToLive);
}
if (!disableMessageTimestamp) {
jmsMessage.setJMSTimestamp(System.currentTimeMillis());
} else {
jmsMessage.setJMSTimestamp(0);
}
SimpleString address = null;
if (destination == null) {
if (defaultDestination == null) {
throw new UnsupportedOperationException("Destination must be specified on send with an anonymous producer");
}
destination = defaultDestination;
} else {
if (defaultDestination != null) {
if (!destination.equals(defaultDestination)) {
throw new UnsupportedOperationException("Where a default destination is specified " + "for the sender and a destination is " + "specified in the arguments to the send, " + "these destinations must be equal");
}
}
address = destination.getSimpleAddress();
if (!connection.containsKnownDestination(address)) {
try {
ClientSession.AddressQuery query = clientSession.addressQuery(address);
if (!query.isExists()) {
if (destination.isQueue() && query.isAutoCreateQueues()) {
clientSession.createAddress(address, RoutingType.ANYCAST, true);
if (destination.isTemporary()) {
// TODO is it right to use the address for the queue name here?
clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
} else {
createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
}
} else if (!destination.isQueue() && query.isAutoCreateAddresses()) {
clientSession.createAddress(address, RoutingType.MULTICAST, true);
} else if ((destination.isQueue() && !query.isAutoCreateQueues()) || (!destination.isQueue() && !query.isAutoCreateAddresses())) {
throw new InvalidDestinationException("Destination " + address + " does not exist");
}
} else {
ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
if (queueQuery.isExists()) {
connection.addKnownDestination(address);
} else if (destination.isQueue() && query.isAutoCreateQueues()) {
if (destination.isTemporary()) {
clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
} else {
createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
}
}
}
} catch (ActiveMQQueueExistsException e) {
// The queue was created by another client/admin between the query check and send create queue packet
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
}
}
}
ActiveMQMessage activeMQJmsMessage;
boolean foreign = false;
// First convert from foreign message if appropriate
if (!(jmsMessage instanceof ActiveMQMessage)) {
if (jmsMessage instanceof BytesMessage) {
activeMQJmsMessage = new ActiveMQBytesMessage((BytesMessage) jmsMessage, clientSession);
} else if (jmsMessage instanceof MapMessage) {
activeMQJmsMessage = new ActiveMQMapMessage((MapMessage) jmsMessage, clientSession);
} else if (jmsMessage instanceof ObjectMessage) {
activeMQJmsMessage = new ActiveMQObjectMessage((ObjectMessage) jmsMessage, clientSession, options);
} else if (jmsMessage instanceof StreamMessage) {
activeMQJmsMessage = new ActiveMQStreamMessage((StreamMessage) jmsMessage, clientSession);
} else if (jmsMessage instanceof TextMessage) {
activeMQJmsMessage = new ActiveMQTextMessage((TextMessage) jmsMessage, clientSession);
} else {
activeMQJmsMessage = new ActiveMQMessage(jmsMessage, clientSession);
}
// Set the destination on the original message
jmsMessage.setJMSDestination(destination);
foreign = true;
} else {
activeMQJmsMessage = (ActiveMQMessage) jmsMessage;
}
if (!disableMessageID) {
// Generate a JMS id
UUID uid = UUIDGenerator.getInstance().generateUUID();
activeMQJmsMessage.getCoreMessage().setUserID(uid);
activeMQJmsMessage.resetMessageID(null);
}
if (foreign) {
jmsMessage.setJMSMessageID(activeMQJmsMessage.getJMSMessageID());
}
activeMQJmsMessage.setJMSDestination(destination);
try {
activeMQJmsMessage.doBeforeSend();
} catch (Exception e) {
JMSException je = new JMSException(e.getMessage());
je.initCause(e);
throw je;
}
if (defaultDeliveryDelay > 0) {
activeMQJmsMessage.setJMSDeliveryTime(System.currentTimeMillis() + defaultDeliveryDelay);
}
ClientMessage coreMessage = activeMQJmsMessage.getCoreMessage();
coreMessage.putStringProperty(ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME, connID);
coreMessage.setRoutingType(destination.isQueue() ? RoutingType.ANYCAST : RoutingType.MULTICAST);
try {
/**
* Using a completionListener requires wrapping using a {@link CompletionListenerWrapper},
* so we avoid it if we can.
*/
if (completionListener != null) {
clientProducer.send(address, coreMessage, new CompletionListenerWrapper(completionListener, jmsMessage, this));
} else {
clientProducer.send(address, coreMessage);
}
} catch (ActiveMQInterruptedException e) {
JMSException jmsException = new JMSException(e.getMessage());
jmsException.initCause(e);
throw jmsException;
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
} catch (java.lang.IllegalStateException e) {
JMSException je = new IllegalStateException(e.getMessage());
je.setStackTrace(e.getStackTrace());
je.initCause(e);
throw je;
}
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class JMSExceptionHelper method convertFromActiveMQException.
public static JMSException convertFromActiveMQException(final ActiveMQException me) {
JMSException je;
switch(me.getType()) {
case CONNECTION_TIMEDOUT:
je = new JMSException(me.getMessage());
break;
case ILLEGAL_STATE:
je = new javax.jms.IllegalStateException(me.getMessage());
break;
case INTERNAL_ERROR:
je = new JMSException(me.getMessage());
break;
case INVALID_FILTER_EXPRESSION:
je = new InvalidSelectorException(me.getMessage());
break;
case NOT_CONNECTED:
je = new JMSException(me.getMessage());
break;
case OBJECT_CLOSED:
je = new javax.jms.IllegalStateException(me.getMessage());
break;
case QUEUE_DOES_NOT_EXIST:
je = new InvalidDestinationException(me.getMessage());
break;
case QUEUE_EXISTS:
je = new InvalidDestinationException(me.getMessage());
break;
case SECURITY_EXCEPTION:
je = new JMSSecurityException(me.getMessage());
break;
case UNSUPPORTED_PACKET:
je = new javax.jms.IllegalStateException(me.getMessage());
break;
case TRANSACTION_ROLLED_BACK:
je = new javax.jms.TransactionRolledBackException(me.getMessage());
break;
default:
je = new JMSException(me.getMessage());
}
je.setStackTrace(me.getStackTrace());
je.initCause(me);
return je;
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class AmqpSupport method convertToException.
// ----- Utility Methods --------------------------------------------------//
/**
* Given an ErrorCondition instance create a new Exception that best matches
* the error type.
*
* @param errorCondition The ErrorCondition returned from the remote peer.
* @return a new Exception instance that best matches the ErrorCondition value.
*/
public static Exception convertToException(ErrorCondition errorCondition) {
Exception remoteError = null;
if (errorCondition != null && errorCondition.getCondition() != null) {
Symbol error = errorCondition.getCondition();
String message = extractErrorMessage(errorCondition);
if (error.equals(AmqpError.UNAUTHORIZED_ACCESS)) {
remoteError = new JMSSecurityException(message);
} else if (error.equals(AmqpError.RESOURCE_LIMIT_EXCEEDED)) {
remoteError = new ResourceAllocationException(message);
} else if (error.equals(AmqpError.NOT_FOUND)) {
remoteError = new InvalidDestinationException(message);
} else if (error.equals(TransactionErrors.TRANSACTION_ROLLBACK)) {
remoteError = new TransactionRolledBackException(message);
} else if (error.equals(ConnectionError.REDIRECT)) {
remoteError = createRedirectException(error, message, errorCondition);
} else if (error.equals(AmqpError.INVALID_FIELD)) {
Map<?, ?> info = errorCondition.getInfo();
if (info != null && CONTAINER_ID.equals(info.get(INVALID_FIELD))) {
remoteError = new InvalidClientIDException(message);
} else {
remoteError = new JMSException(message);
}
} else {
remoteError = new JMSException(message);
}
} else {
remoteError = new JMSException("Unknown error from remote peer");
}
return remoteError;
}
use of javax.jms.InvalidDestinationException in project activemq-artemis by apache.
the class SimpleOpenWireTest method testTempQueueSendAfterConnectionClose.
@Test
public void testTempQueueSendAfterConnectionClose() throws Exception {
Connection connection1 = null;
Connection connection2 = null;
try {
connection1 = factory.createConnection();
connection2 = factory.createConnection();
connection1.start();
connection2.start();
Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue tempQueue = session1.createTemporaryQueue();
Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session2.createProducer(tempQueue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage m = session2.createTextMessage("Hello temp queue");
producer.send(m);
MessageConsumer consumer = session1.createConsumer(tempQueue);
TextMessage received = (TextMessage) consumer.receive(5000);
assertNotNull(received);
assertEquals("Hello temp queue", received.getText());
// close first connection, let temp queue die
connection1.close();
waitForBindings(this.server, tempQueue.getQueueName(), true, 0, 0, 5000);
// send again
try {
producer.send(m);
fail("Send should fail since temp destination should not exist anymore.");
} catch (InvalidDestinationException e) {
// ignore
}
} finally {
if (connection1 != null) {
connection1.close();
}
if (connection2 != null) {
connection2.close();
}
}
}
Aggregations