Search in sources :

Example 6 with InvalidDestinationException

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;
    }
}
Also used : InvalidDestinationException(javax.jms.InvalidDestinationException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 7 with InvalidDestinationException

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;
    }
}
Also used : IllegalStateException(javax.jms.IllegalStateException) MapMessage(javax.jms.MapMessage) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) BytesMessage(javax.jms.BytesMessage) JMSException(javax.jms.JMSException) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ObjectMessage(javax.jms.ObjectMessage) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) UUID(org.apache.activemq.artemis.utils.UUID) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) InvalidDestinationException(javax.jms.InvalidDestinationException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) InvalidDestinationException(javax.jms.InvalidDestinationException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) IllegalStateException(javax.jms.IllegalStateException) JMSException(javax.jms.JMSException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) StreamMessage(javax.jms.StreamMessage) TextMessage(javax.jms.TextMessage)

Example 8 with InvalidDestinationException

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;
}
Also used : InvalidSelectorException(javax.jms.InvalidSelectorException) JMSSecurityException(javax.jms.JMSSecurityException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSException(javax.jms.JMSException)

Example 9 with InvalidDestinationException

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;
}
Also used : Symbol(org.apache.qpid.proton.amqp.Symbol) JMSSecurityException(javax.jms.JMSSecurityException) InvalidClientIDException(javax.jms.InvalidClientIDException) InvalidDestinationException(javax.jms.InvalidDestinationException) TransactionRolledBackException(javax.jms.TransactionRolledBackException) JMSException(javax.jms.JMSException) ResourceAllocationException(javax.jms.ResourceAllocationException) Map(java.util.Map) IOException(java.io.IOException) ResourceAllocationException(javax.jms.ResourceAllocationException) InvalidClientIDException(javax.jms.InvalidClientIDException) JMSException(javax.jms.JMSException) InvalidDestinationException(javax.jms.InvalidDestinationException) JMSSecurityException(javax.jms.JMSSecurityException) TransactionRolledBackException(javax.jms.TransactionRolledBackException)

Example 10 with InvalidDestinationException

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();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) XAConnection(javax.jms.XAConnection) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) Connection(javax.jms.Connection) TopicConnection(javax.jms.TopicConnection) InvalidDestinationException(javax.jms.InvalidDestinationException) MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) XASession(javax.jms.XASession) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) TopicSession(javax.jms.TopicSession) QueueSession(javax.jms.QueueSession) 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