Search in sources :

Example 1 with ActiveMQAMQPInternalErrorException

use of org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException in project activemq-artemis by apache.

the class ProtonServerSenderContext method initialise.

/**
 * create the actual underlying ActiveMQ Artemis Server Consumer
 */
@SuppressWarnings("unchecked")
@Override
public void initialise() throws Exception {
    super.initialise();
    Source source = (Source) sender.getRemoteSource();
    SimpleString queue = null;
    String selector = null;
    final Map<Symbol, Object> supportedFilters = new HashMap<>();
    // Match the settlement mode of the remote instead of relying on the default of MIXED.
    sender.setSenderSettleMode(sender.getRemoteSenderSettleMode());
    // We don't currently support SECOND so enforce that the answer is anlways FIRST
    sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);
    if (source != null) {
        // We look for message selectors on every receiver, while in other cases we might only
        // consume the filter depending on the subscription type.
        Map.Entry<Symbol, DescribedType> filter = AmqpSupport.findFilter(source.getFilter(), AmqpSupport.JMS_SELECTOR_FILTER_IDS);
        if (filter != null) {
            selector = filter.getValue().getDescribed().toString();
            // Validate the Selector.
            try {
                SelectorParser.parse(selector);
            } catch (FilterException e) {
                throw new ActiveMQAMQPException(AmqpError.INVALID_FIELD, "Invalid filter", ActiveMQExceptionType.INVALID_FILTER_EXPRESSION);
            }
            supportedFilters.put(filter.getKey(), filter.getValue());
        }
    }
    if (source == null) {
        // Attempt to recover a previous subscription happens when a link reattach happens on a
        // subscription queue
        String clientId = getClientId();
        String pubId = sender.getName();
        global = hasRemoteDesiredCapability(sender, GLOBAL);
        queue = createQueueName(connection.isUseCoreSubscriptionNaming(), clientId, pubId, true, global, false);
        QueueQueryResult result = sessionSPI.queueQuery(queue, RoutingType.MULTICAST, false);
        multicast = true;
        routingTypeToUse = RoutingType.MULTICAST;
        // the lifetime policy and capabilities of the new subscription.
        if (result.isExists()) {
            source = new org.apache.qpid.proton.amqp.messaging.Source();
            source.setAddress(queue.toString());
            source.setDurable(TerminusDurability.UNSETTLED_STATE);
            source.setExpiryPolicy(TerminusExpiryPolicy.NEVER);
            source.setDistributionMode(COPY);
            source.setCapabilities(TOPIC);
            SimpleString filterString = result.getFilterString();
            if (filterString != null) {
                selector = filterString.toString();
                boolean noLocal = false;
                String remoteContainerId = sender.getSession().getConnection().getRemoteContainer();
                String noLocalFilter = MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString() + "<>'" + remoteContainerId + "'";
                if (selector.endsWith(noLocalFilter)) {
                    if (selector.length() > noLocalFilter.length()) {
                        noLocalFilter = " AND " + noLocalFilter;
                        selector = selector.substring(0, selector.length() - noLocalFilter.length());
                    } else {
                        selector = null;
                    }
                    noLocal = true;
                }
                if (noLocal) {
                    supportedFilters.put(AmqpSupport.NO_LOCAL_NAME, AmqpNoLocalFilter.NO_LOCAL);
                }
                if (selector != null && !selector.trim().isEmpty()) {
                    supportedFilters.put(AmqpSupport.JMS_SELECTOR_NAME, new AmqpJmsSelectorFilter(selector));
                }
            }
            sender.setSource(source);
        } else {
            throw new ActiveMQAMQPNotFoundException("Unknown subscription link: " + sender.getName());
        }
    } else if (source.getDynamic()) {
        // if dynamic we have to create the node (queue) and set the address on the target, the
        // node is temporary and  will be deleted on closing of the session
        queue = SimpleString.toSimpleString(java.util.UUID.randomUUID().toString());
        tempQueueName = queue;
        try {
            sessionSPI.createTemporaryQueue(queue, RoutingType.ANYCAST);
        // protonSession.getServerSession().createQueue(queue, queue, null, true, false);
        } catch (Exception e) {
            throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.errorCreatingTemporaryQueue(e.getMessage());
        }
        source.setAddress(queue.toString());
    } else {
        SimpleString addressToUse;
        SimpleString queueNameToUse = null;
        shared = hasCapabilities(SHARED, source);
        global = hasCapabilities(GLOBAL, source);
        // find out if we have an address made up of the address and queue name, if yes then set queue name
        if (CompositeAddress.isFullyQualified(source.getAddress())) {
            CompositeAddress compositeAddress = CompositeAddress.getQueueName(source.getAddress());
            addressToUse = new SimpleString(compositeAddress.getAddress());
            queueNameToUse = new SimpleString(compositeAddress.getQueueName());
        } else {
            addressToUse = new SimpleString(source.getAddress());
        }
        // check to see if the client has defined how we act
        boolean clientDefined = hasCapabilities(TOPIC, source) || hasCapabilities(QUEUE, source);
        if (clientDefined) {
            multicast = hasCapabilities(TOPIC, source);
            AddressQueryResult addressQueryResult = null;
            try {
                addressQueryResult = sessionSPI.addressQuery(addressToUse, multicast ? RoutingType.MULTICAST : RoutingType.ANYCAST, true);
            } catch (ActiveMQSecurityException e) {
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingConsumer(e.getMessage());
            } catch (ActiveMQAMQPException e) {
                throw e;
            } catch (Exception e) {
                throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
            }
            if (!addressQueryResult.isExists()) {
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.sourceAddressDoesntExist();
            }
            Set<RoutingType> routingTypes = addressQueryResult.getRoutingTypes();
            // if the client defines 1 routing type and the broker another then throw an exception
            if (multicast && !routingTypes.contains(RoutingType.MULTICAST)) {
                throw new ActiveMQAMQPIllegalStateException("Address " + addressToUse + " is not configured for topic support");
            } else if (!multicast && !routingTypes.contains(RoutingType.ANYCAST)) {
                throw new ActiveMQAMQPIllegalStateException("Address " + addressToUse + " is not configured for queue support");
            }
        } else {
            // if not we look up the address
            AddressQueryResult addressQueryResult = null;
            try {
                addressQueryResult = sessionSPI.addressQuery(addressToUse, defaultRoutingType, true);
            } catch (ActiveMQSecurityException e) {
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingConsumer(e.getMessage());
            } catch (ActiveMQAMQPException e) {
                throw e;
            } catch (Exception e) {
                throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
            }
            if (!addressQueryResult.isExists()) {
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.sourceAddressDoesntExist();
            }
            Set<RoutingType> routingTypes = addressQueryResult.getRoutingTypes();
            if (routingTypes.contains(RoutingType.MULTICAST) && routingTypes.size() == 1) {
                multicast = true;
            } else {
                // todo add some checks if both routing types are supported
                multicast = false;
            }
        }
        routingTypeToUse = multicast ? RoutingType.MULTICAST : RoutingType.ANYCAST;
        // messages to, however there has to be a queue bound to it so we need to check this.
        if (multicast) {
            Map.Entry<Symbol, DescribedType> filter = AmqpSupport.findFilter(source.getFilter(), AmqpSupport.NO_LOCAL_FILTER_IDS);
            if (filter != null) {
                String remoteContainerId = sender.getSession().getConnection().getRemoteContainer();
                String noLocalFilter = MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString() + "<>'" + remoteContainerId + "'";
                if (selector != null) {
                    selector += " AND " + noLocalFilter;
                } else {
                    selector = noLocalFilter;
                }
                supportedFilters.put(filter.getKey(), filter.getValue());
            }
            queue = getMatchingQueue(queueNameToUse, addressToUse, RoutingType.MULTICAST);
            SimpleString simpleStringSelector = SimpleString.toSimpleString(selector);
            // if the address specifies a broker configured queue then we always use this, treat it as a queue
            if (queue != null) {
                multicast = false;
            } else if (TerminusDurability.UNSETTLED_STATE.equals(source.getDurable()) || TerminusDurability.CONFIGURATION.equals(source.getDurable())) {
                // if we are a subscription and durable create a durable queue using the container
                // id and link name
                String clientId = getClientId();
                String pubId = sender.getName();
                queue = createQueueName(connection.isUseCoreSubscriptionNaming(), clientId, pubId, shared, global, false);
                QueueQueryResult result = sessionSPI.queueQuery(queue, routingTypeToUse, false);
                if (result.isExists()) {
                    // filter value, selector or address then we must recreate the queue (JMS semantics).
                    if (!Objects.equals(result.getFilterString(), simpleStringSelector) || (sender.getSource() != null && !sender.getSource().getAddress().equals(result.getAddress().toString()))) {
                        if (result.getConsumerCount() == 0) {
                            sessionSPI.deleteQueue(queue);
                            sessionSPI.createUnsharedDurableQueue(addressToUse, RoutingType.MULTICAST, queue, simpleStringSelector);
                        } else {
                            throw new ActiveMQAMQPIllegalStateException("Unable to recreate subscription, consumers already exist");
                        }
                    }
                } else {
                    if (shared) {
                        sessionSPI.createSharedDurableQueue(addressToUse, RoutingType.MULTICAST, queue, simpleStringSelector);
                    } else {
                        sessionSPI.createUnsharedDurableQueue(addressToUse, RoutingType.MULTICAST, queue, simpleStringSelector);
                    }
                }
            } else {
                // otherwise we are a volatile subscription
                isVolatile = true;
                if (shared && sender.getName() != null) {
                    queue = createQueueName(connection.isUseCoreSubscriptionNaming(), getClientId(), sender.getName(), shared, global, isVolatile);
                    try {
                        sessionSPI.createSharedVolatileQueue(addressToUse, RoutingType.MULTICAST, queue, simpleStringSelector);
                    } catch (ActiveMQQueueExistsException e) {
                    // this is ok, just means its shared
                    }
                } else {
                    queue = SimpleString.toSimpleString(java.util.UUID.randomUUID().toString());
                    tempQueueName = queue;
                    try {
                        sessionSPI.createTemporaryQueue(addressToUse, queue, RoutingType.MULTICAST, simpleStringSelector);
                    } catch (Exception e) {
                        throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.errorCreatingTemporaryQueue(e.getMessage());
                    }
                }
            }
        } else {
            if (queueNameToUse != null) {
                SimpleString matchingAnycastQueue = getMatchingQueue(queueNameToUse, addressToUse, RoutingType.ANYCAST);
                if (matchingAnycastQueue != null) {
                    queue = matchingAnycastQueue;
                } else {
                    throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.sourceAddressDoesntExist();
                }
            } else {
                SimpleString matchingAnycastQueue = sessionSPI.getMatchingQueue(addressToUse, RoutingType.ANYCAST);
                if (matchingAnycastQueue != null) {
                    queue = matchingAnycastQueue;
                } else {
                    queue = addressToUse;
                }
            }
        }
        if (queue == null) {
            throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.sourceAddressNotSet();
        }
        try {
            if (!sessionSPI.queueQuery(queue, routingTypeToUse, !multicast).isExists()) {
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.sourceAddressDoesntExist();
            }
        } catch (ActiveMQAMQPNotFoundException e) {
            throw e;
        } catch (Exception e) {
            throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
        }
    }
    // We need to update the source with any filters we support otherwise the client
    // is free to consider the attach as having failed if we don't send back what we
    // do support or if we send something we don't support the client won't know we
    // have not honored what it asked for.
    source.setFilter(supportedFilters.isEmpty() ? null : supportedFilters);
    boolean browseOnly = !multicast && source.getDistributionMode() != null && source.getDistributionMode().equals(COPY);
    try {
        brokerConsumer = (Consumer) sessionSPI.createSender(this, queue, multicast ? null : selector, browseOnly);
    } catch (ActiveMQAMQPResourceLimitExceededException e1) {
        throw new ActiveMQAMQPResourceLimitExceededException(e1.getMessage());
    } catch (ActiveMQSecurityException e) {
        throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingConsumer(e.getMessage());
    } catch (Exception e) {
        throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.errorCreatingConsumer(e.getMessage());
    }
}
Also used : ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) Set(java.util.Set) HashMap(java.util.HashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) Source(org.apache.qpid.proton.amqp.messaging.Source) CompositeAddress(org.apache.activemq.artemis.utils.CompositeAddress) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) ActiveMQAMQPIllegalStateException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException) AddressQueryResult(org.apache.activemq.artemis.core.server.AddressQueryResult) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) FilterException(org.apache.activemq.artemis.selector.filter.FilterException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) ActiveMQAMQPIllegalStateException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) Source(org.apache.qpid.proton.amqp.messaging.Source) DescribedType(org.apache.qpid.proton.amqp.DescribedType) FilterException(org.apache.activemq.artemis.selector.filter.FilterException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ActiveMQAMQPInternalErrorException

use of org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException in project activemq-artemis by apache.

the class ProtonServerSenderContext method close.

/*
    * close the session
    */
@Override
public void close(ErrorCondition condition) throws ActiveMQAMQPException {
    closed = true;
    if (condition != null) {
        sender.setCondition(condition);
    }
    protonSession.removeSender(sender);
    connection.lock();
    try {
        sender.close();
    } finally {
        connection.unlock();
    }
    connection.flush();
    try {
        sessionSPI.closeSender(brokerConsumer);
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
        throw new ActiveMQAMQPInternalErrorException(e.getMessage());
    }
}
Also used : ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) FilterException(org.apache.activemq.artemis.selector.filter.FilterException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) ActiveMQAMQPIllegalStateException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException)

Example 3 with ActiveMQAMQPInternalErrorException

use of org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException in project activemq-artemis by apache.

the class AMQPSessionCallback method closeSender.

public void closeSender(final Object brokerConsumer) throws Exception {
    final ServerConsumer consumer = ((ServerConsumer) brokerConsumer);
    final CountDownLatch latch = new CountDownLatch(1);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                consumer.close(false);
                latch.countDown();
            } catch (Exception e) {
            }
        }
    };
    // Due to the nature of proton this could be happening within flushes from the queue-delivery (depending on how it happened on the protocol)
    // to avoid deadlocks the close has to be done outside of the main thread on an executor
    // otherwise you could get a deadlock
    Executor executor = protonSPI.getExeuctor();
    if (executor != null) {
        executor.execute(runnable);
    } else {
        runnable.run();
    }
    try {
        // a short timeout will do.. 1 second is already long enough
        if (!latch.await(1, TimeUnit.SECONDS)) {
            logger.debug("Could not close consumer on time");
        }
    } catch (InterruptedException e) {
        throw new ActiveMQAMQPInternalErrorException("Unable to close consumers for queue: " + consumer.getQueue());
    }
    consumer.getQueue().recheckRefCount(serverSession.getSessionContext());
}
Also used : ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) Executor(java.util.concurrent.Executor) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) ActiveMQAddressExistsException(org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException)

Example 4 with ActiveMQAMQPInternalErrorException

use of org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException in project activemq-artemis by apache.

the class ProtonServerSenderContext method close.

/*
    * close the session
    */
@Override
public void close(boolean remoteLinkClose) throws ActiveMQAMQPException {
    try {
        closed = true;
        sessionSPI.closeSender(brokerConsumer);
        // any durable resources for say pub subs
        if (remoteLinkClose) {
            Source source = (Source) sender.getSource();
            if (source != null && source.getAddress() != null && multicast) {
                SimpleString queueName = SimpleString.toSimpleString(source.getAddress());
                QueueQueryResult result = sessionSPI.queueQuery(queueName, routingTypeToUse, false);
                if (result.isExists() && source.getDynamic()) {
                    sessionSPI.deleteQueue(queueName);
                } else {
                    if (source.getDurable() == TerminusDurability.NONE && tempQueueName != null && (source.getExpiryPolicy() == TerminusExpiryPolicy.LINK_DETACH || source.getExpiryPolicy() == TerminusExpiryPolicy.SESSION_END)) {
                        sessionSPI.removeTemporaryQueue(tempQueueName);
                    } else {
                        String clientId = getClientId();
                        String pubId = sender.getName();
                        if (pubId.contains("|")) {
                            pubId = pubId.split("\\|")[0];
                        }
                        SimpleString queue = createQueueName(connection.isUseCoreSubscriptionNaming(), clientId, pubId, shared, global, isVolatile);
                        result = sessionSPI.queueQuery(queue, multicast ? RoutingType.MULTICAST : RoutingType.ANYCAST, false);
                        // only delete if it isn't volatile and has no consumers
                        if (result.isExists() && !isVolatile && result.getConsumerCount() == 0) {
                            sessionSPI.deleteQueue(queue);
                        }
                    }
                }
            } else if (source != null && source.getDynamic() && (source.getExpiryPolicy() == TerminusExpiryPolicy.LINK_DETACH || source.getExpiryPolicy() == TerminusExpiryPolicy.SESSION_END)) {
                try {
                    sessionSPI.removeTemporaryQueue(SimpleString.toSimpleString(source.getAddress()));
                } catch (Exception e) {
                // ignore on close, its temp anyway and will be removed later
                }
            }
        }
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
        throw new ActiveMQAMQPInternalErrorException(e.getMessage());
    }
}
Also used : ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Source(org.apache.qpid.proton.amqp.messaging.Source) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) FilterException(org.apache.activemq.artemis.selector.filter.FilterException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) ActiveMQAMQPIllegalStateException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException)

Example 5 with ActiveMQAMQPInternalErrorException

use of org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException in project activemq-artemis by apache.

the class ProtonServerReceiverContext method initialise.

@Override
public void initialise() throws Exception {
    super.initialise();
    org.apache.qpid.proton.amqp.messaging.Target target = (org.apache.qpid.proton.amqp.messaging.Target) receiver.getRemoteTarget();
    // Match the settlement mode of the remote instead of relying on the default of MIXED.
    receiver.setSenderSettleMode(receiver.getRemoteSenderSettleMode());
    // We don't currently support SECOND so enforce that the answer is anlways FIRST
    receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST);
    RoutingType defRoutingType;
    if (target != null) {
        if (target.getDynamic()) {
            // if dynamic we have to create the node (queue) and set the address on the target, the node is temporary and
            // will be deleted on closing of the session
            address = SimpleString.toSimpleString(sessionSPI.tempQueueName());
            defRoutingType = getRoutingType(target.getCapabilities(), address);
            try {
                sessionSPI.createTemporaryQueue(address, defRoutingType);
            } catch (ActiveMQSecurityException e) {
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingTempDestination(e.getMessage());
            } catch (Exception e) {
                throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
            }
            expiryPolicy = target.getExpiryPolicy() != null ? target.getExpiryPolicy() : TerminusExpiryPolicy.LINK_DETACH;
            target.setAddress(address.toString());
        } else {
            // the target will have an address unless the remote is requesting an anonymous
            // relay in which case the address in the incoming message's to field will be
            // matched on receive of the message.
            address = SimpleString.toSimpleString(target.getAddress());
            if (address != null && !address.isEmpty()) {
                defRoutingType = getRoutingType(target.getCapabilities(), address);
                try {
                    if (!sessionSPI.bindingQuery(address, defRoutingType)) {
                        throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.addressDoesntExist();
                    }
                } catch (ActiveMQAMQPNotFoundException e) {
                    throw e;
                } catch (Exception e) {
                    log.debug(e.getMessage(), e);
                    throw new ActiveMQAMQPInternalErrorException(e.getMessage(), e);
                }
                try {
                    sessionSPI.check(address, CheckType.SEND, new SecurityAuth() {

                        @Override
                        public String getUsername() {
                            String username = null;
                            SASLResult saslResult = connection.getSASLResult();
                            if (saslResult != null) {
                                username = saslResult.getUser();
                            }
                            return username;
                        }

                        @Override
                        public String getPassword() {
                            String password = null;
                            SASLResult saslResult = connection.getSASLResult();
                            if (saslResult != null) {
                                if (saslResult instanceof PlainSASLResult) {
                                    password = ((PlainSASLResult) saslResult).getPassword();
                                }
                            }
                            return password;
                        }

                        @Override
                        public RemotingConnection getRemotingConnection() {
                            return connection.connectionCallback.getProtonConnectionDelegate();
                        }
                    });
                } catch (ActiveMQSecurityException e) {
                    throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.securityErrorCreatingProducer(e.getMessage());
                }
            }
        }
        Symbol[] remoteDesiredCapabilities = receiver.getRemoteDesiredCapabilities();
        if (remoteDesiredCapabilities != null) {
            List<Symbol> list = Arrays.asList(remoteDesiredCapabilities);
            if (list.contains(AmqpSupport.DELAYED_DELIVERY)) {
                receiver.setOfferedCapabilities(new Symbol[] { AmqpSupport.DELAYED_DELIVERY });
            }
        }
    }
    flow(amqpCredits, minCreditRefresh);
}
Also used : ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) Symbol(org.apache.qpid.proton.amqp.Symbol) SecurityAuth(org.apache.activemq.artemis.core.security.SecurityAuth) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) PlainSASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) SASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.SASLResult) PlainSASLResult(org.apache.activemq.artemis.protocol.amqp.sasl.PlainSASLResult) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Aggregations

ActiveMQAMQPException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException)5 ActiveMQAMQPInternalErrorException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException)5 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)4 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)4 ActiveMQAMQPNotFoundException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException)4 ActiveMQAMQPResourceLimitExceededException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 ActiveMQAMQPIllegalStateException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException)3 FilterException (org.apache.activemq.artemis.selector.filter.FilterException)3 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)2 Symbol (org.apache.qpid.proton.amqp.Symbol)2 Source (org.apache.qpid.proton.amqp.messaging.Source)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executor (java.util.concurrent.Executor)1 ActiveMQAddressExistsException (org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)1