Search in sources :

Example 46 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_8Test method testReplyToConversionWhenExchangeIsSpecified.

@Test
public void testReplyToConversionWhenExchangeIsSpecified() throws IOException {
    final String replyTo = "myTestExchange";
    final Exchange exchange = mock(Exchange.class);
    when(exchange.getName()).thenReturn(replyTo);
    when(exchange.getType()).thenReturn(ExchangeDefaults.FANOUT_EXCHANGE_CLASS);
    doReturn(exchange).when(_namedAddressSpace).getAttainedMessageDestination(eq(replyTo), anyBoolean());
    Properties properties = new Properties();
    properties.setReplyTo(replyTo);
    Message_1_0 message = createTestMessage(properties);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties convertedProperties = convertedMessage.getContentHeaderBody().getProperties();
    assertEquals("Unexpected reply-to", "fanout://" + replyTo + "//", convertedProperties.getReplyToAsString());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage) Test(org.junit.Test)

Example 47 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_10Test method testReplyToConversionWhenExchangeAndRoutingKeyAreSpecified.

@Test
public void testReplyToConversionWhenExchangeAndRoutingKeyAreSpecified() throws IOException {
    final String exchangeName = "testExchnageName";
    final String routingKey = "testRoutingKey";
    final String replyTo = String.format("%s/%s", exchangeName, routingKey);
    final Exchange exchange = mock(Exchange.class);
    when(exchange.getName()).thenReturn(exchangeName);
    doReturn(exchange).when(_namedAddressSpace).getAttainedMessageDestination(eq(exchangeName), anyBoolean());
    Properties properties = new Properties();
    properties.setReplyTo(replyTo);
    Message_1_0 message = createTestMessage(properties);
    MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    final ReplyTo convertedReplyTo = convertedMessage.getHeader().getMessageProperties().getReplyTo();
    assertEquals("Unexpected exchange", exchangeName, convertedReplyTo.getExchange());
    assertEquals("Unexpected routing key", routingKey, convertedReplyTo.getRoutingKey());
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) Test(org.junit.Test)

Example 48 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10 method getReplyTo.

private ReplyTo getReplyTo(final NamedAddressSpace addressSpace, final String origReplyTo) {
    DestinationAddress destinationAddress = new DestinationAddress(addressSpace, origReplyTo);
    MessageDestination messageDestination = destinationAddress.getMessageDestination();
    return new ReplyTo(ensureStr8("reply-to[\"exchange\"]", messageDestination instanceof Exchange ? messageDestination.getName() : ""), ensureStr8("reply-to[\"routing-key\"]", messageDestination instanceof Queue ? messageDestination.getName() : destinationAddress.getRoutingKey()));
}
Also used : ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) Exchange(org.apache.qpid.server.model.Exchange) MessageDestination(org.apache.qpid.server.message.MessageDestination) Queue(org.apache.qpid.server.model.Queue) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 49 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class AMQChannel method receiveExchangeDeclare.

@Override
public void receiveExchangeDeclare(final AMQShortString exchangeName, final AMQShortString type, final boolean passive, final boolean durable, final boolean autoDelete, final boolean internal, final boolean nowait, final FieldTable arguments) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] ExchangeDeclare[" + " exchange: " + exchangeName + " type: " + type + " passive: " + passive + " durable: " + durable + " autoDelete: " + autoDelete + " internal: " + internal + " nowait: " + nowait + " arguments: " + arguments + " ]");
    }
    final MethodRegistry methodRegistry = _connection.getMethodRegistry();
    final AMQMethodBody declareOkBody = methodRegistry.createExchangeDeclareOkBody();
    Exchange<?> exchange;
    NamedAddressSpace virtualHost = _connection.getAddressSpace();
    if (isDefaultExchange(exchangeName)) {
        if (!AMQShortString.createAMQShortString(ExchangeDefaults.DIRECT_EXCHANGE_CLASS).equals(type)) {
            _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to redeclare default exchange: " + " of type " + ExchangeDefaults.DIRECT_EXCHANGE_CLASS + " to " + type + ".", getChannelId());
        } else if (!nowait) {
            sync();
            _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
        }
    } else {
        if (passive) {
            exchange = getExchange(exchangeName.toString());
            if (exchange == null) {
                closeChannel(ErrorCodes.NOT_FOUND, "Unknown exchange: '" + exchangeName + "'");
            } else if (!(type == null || type.length() == 0) && !exchange.getType().equals(type.toString())) {
                _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to redeclare exchange: '" + exchangeName + "' of type " + exchange.getType() + " to " + type + ".", getChannelId());
            } else if (!nowait) {
                sync();
                _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
            }
        } else {
            String name = exchangeName.toString();
            String typeString = type == null ? null : type.toString();
            try {
                Map<String, Object> attributes = new HashMap<String, Object>();
                if (arguments != null) {
                    attributes.putAll(FieldTable.convertToMap(arguments));
                }
                attributes.put(Exchange.NAME, name);
                attributes.put(Exchange.TYPE, typeString);
                attributes.put(Exchange.DURABLE, durable);
                attributes.put(Exchange.LIFETIME_POLICY, autoDelete ? LifetimePolicy.DELETE_ON_NO_LINKS : LifetimePolicy.PERMANENT);
                Object alternateExchange = attributes.remove(ALTERNATE_EXCHANGE);
                if (alternateExchange != null) {
                    String alternateExchangeName = String.valueOf(alternateExchange);
                    validateAlternateExchangeIsNotQueue(virtualHost, alternateExchangeName);
                    attributes.put(Exchange.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, alternateExchangeName));
                }
                validateAndSanitizeExchangeDeclareArguments(attributes);
                exchange = virtualHost.createMessageDestination(Exchange.class, attributes);
                if (!nowait) {
                    sync();
                    _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
                }
            } catch (ReservedExchangeNameException e) {
                Exchange existing = getExchange(name);
                if (existing == null || !existing.getType().equals(typeString)) {
                    _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to declare exchange: '" + exchangeName + "' which begins with reserved prefix.", getChannelId());
                } else if (!nowait) {
                    sync();
                    _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
                }
            } catch (AbstractConfiguredObject.DuplicateNameException e) {
                exchange = (Exchange<?>) e.getExisting();
                if (!exchange.getType().equals(typeString)) {
                    _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to redeclare exchange: '" + exchangeName + "' of type " + exchange.getType() + " to " + type + ".", getChannelId());
                } else {
                    if (!nowait) {
                        sync();
                        _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
                    }
                }
            } catch (NoFactoryForTypeException e) {
                _connection.sendConnectionClose(ErrorCodes.COMMAND_INVALID, "Unknown exchange type '" + e.getType() + "' for exchange '" + exchangeName + "'", getChannelId());
            } catch (AccessControlException e) {
                _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
            } catch (UnknownAlternateBindingException e) {
                final String message = String.format("Unknown alternate destination '%s'", e.getAlternateBindingName());
                _connection.sendConnectionClose(ErrorCodes.NOT_FOUND, message, getChannelId());
            } catch (IllegalArgumentException | IllegalConfigurationException e) {
                _connection.sendConnectionClose(ErrorCodes.INVALID_ARGUMENT, "Error creating exchange '" + exchangeName + "': " + e.getMessage(), getChannelId());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlException(java.security.AccessControlException) Exchange(org.apache.qpid.server.model.Exchange) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) NoFactoryForTypeException(org.apache.qpid.server.model.NoFactoryForTypeException) ReservedExchangeNameException(org.apache.qpid.server.virtualhost.ReservedExchangeNameException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)

Example 50 with Exchange

use of org.apache.qpid.server.model.Exchange in project qpid-broker-j by apache.

the class AMQChannel method validateAndSanitizeExchangeDeclareArguments.

private void validateAndSanitizeExchangeDeclareArguments(final Map<String, Object> attributes) {
    final ConfiguredObjectTypeRegistry typeRegistry = getModel().getTypeRegistry();
    final List<ConfiguredObjectAttribute<?, ?>> types = new ArrayList<>(typeRegistry.getAttributeTypes(Exchange.class).values());
    typeRegistry.getTypeSpecialisations(Exchange.class).forEach(type -> types.addAll(typeRegistry.getTypeSpecificAttributes(type)));
    final Set<String> unsupported = attributes.keySet().stream().filter(name -> types.stream().noneMatch(a -> Objects.equals(name, a.getName()) && !a.isDerived())).collect(Collectors.toSet());
    if (!unsupported.isEmpty()) {
        Exchange.BehaviourOnUnknownDeclareArgument unknownArgumentBehaviour = getConnection().getContextValue(Exchange.BehaviourOnUnknownDeclareArgument.class, Exchange.UNKNOWN_EXCHANGE_DECLARE_ARGUMENT_BEHAVIOUR_NAME);
        switch(unknownArgumentBehaviour) {
            case LOG:
                LOGGER.warn("Unsupported exchange declare arguments : {}", String.join(",", unsupported));
            // fall through
            case IGNORE:
                attributes.keySet().removeAll(unsupported);
                break;
            case FAIL:
            default:
                throw new IllegalArgumentException(String.format("Unsupported exchange declare arguments : %s", String.join(",", unsupported)));
        }
    }
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) AccessControlContext(java.security.AccessControlContext) MessageReference(org.apache.qpid.server.message.MessageReference) LoggerFactory(org.slf4j.LoggerFactory) ConsumerTarget(org.apache.qpid.server.consumer.ConsumerTarget) Collections2(com.google.common.collect.Collections2) MessageDestinationIsAlternateException(org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException) MessageStore(org.apache.qpid.server.store.MessageStore) ConsumerOption(org.apache.qpid.server.consumer.ConsumerOption) ExchangeDefaults(org.apache.qpid.server.exchange.ExchangeDefaults) AsyncAutoCommitTransaction(org.apache.qpid.server.txn.AsyncAutoCommitTransaction) ConfiguredObjectTypeRegistry(org.apache.qpid.server.model.ConfiguredObjectTypeRegistry) Map(java.util.Map) RejectType(org.apache.qpid.server.message.RejectType) QueueArgumentsConverter(org.apache.qpid.server.queue.QueueArgumentsConverter) EnumSet(java.util.EnumSet) Function(com.google.common.base.Function) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) Collection(java.util.Collection) Set(java.util.Set) ArrivalTimeFilter(org.apache.qpid.server.filter.ArrivalTimeFilter) AbstractAMQPSession(org.apache.qpid.server.session.AbstractAMQPSession) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) UUID(java.util.UUID) InstanceProperties(org.apache.qpid.server.message.InstanceProperties) PrivilegedAction(java.security.PrivilegedAction) FilterManagerFactory(org.apache.qpid.server.filter.FilterManagerFactory) RoutingResult(org.apache.qpid.server.message.RoutingResult) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) MessageDestination(org.apache.qpid.server.message.MessageDestination) MessageSource(org.apache.qpid.server.message.MessageSource) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException) ConfiguredObjectAttribute(org.apache.qpid.server.model.ConfiguredObjectAttribute) AccessController(java.security.AccessController) ReservedExchangeNameException(org.apache.qpid.server.virtualhost.ReservedExchangeNameException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ErrorCodes(org.apache.qpid.server.protocol.ErrorCodes) Queue(org.apache.qpid.server.model.Queue) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException) TransactionLogResource(org.apache.qpid.server.store.TransactionLogResource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LogMessage(org.apache.qpid.server.logging.LogMessage) HashMap(java.util.HashMap) ServerMessage(org.apache.qpid.server.message.ServerMessage) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) org.apache.qpid.server.protocol.v0_8.transport(org.apache.qpid.server.protocol.v0_8.transport) ExclusivityPolicy(org.apache.qpid.server.model.ExclusivityPolicy) Functions.hex(org.apache.qpid.server.transport.util.Functions.hex) Filterable(org.apache.qpid.server.filter.Filterable) MessageFilter(org.apache.qpid.server.filter.MessageFilter) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) MessageHandle(org.apache.qpid.server.store.MessageHandle) ExchangeMessages(org.apache.qpid.server.logging.messages.ExchangeMessages) LifetimePolicy(org.apache.qpid.server.model.LifetimePolicy) EventLoggerProvider(org.apache.qpid.server.logging.EventLoggerProvider) MessageInstance(org.apache.qpid.server.message.MessageInstance) StoredMessage(org.apache.qpid.server.store.StoredMessage) NoFactoryForTypeException(org.apache.qpid.server.model.NoFactoryForTypeException) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) Logger(org.slf4j.Logger) AMQPFilterTypes(org.apache.qpid.server.filter.AMQPFilterTypes) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) Action(org.apache.qpid.server.util.Action) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) Exchange(org.apache.qpid.server.model.Exchange) Broker(org.apache.qpid.server.model.Broker) Subject(javax.security.auth.Subject) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) Futures(com.google.common.util.concurrent.Futures) AMQInvalidArgumentException(org.apache.qpid.server.filter.AMQInvalidArgumentException) RequiredExchangeException(org.apache.qpid.server.virtualhost.RequiredExchangeException) Visitor(org.apache.qpid.server.protocol.v0_8.UnacknowledgedMessageMap.Visitor) FilterManager(org.apache.qpid.server.filter.FilterManager) Collections(java.util.Collections) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ChannelMessages(org.apache.qpid.server.logging.messages.ChannelMessages) AsyncCommand(org.apache.qpid.server.txn.AsyncCommand) ProtocolVersion(org.apache.qpid.server.protocol.ProtocolVersion) ConfiguredObjectAttribute(org.apache.qpid.server.model.ConfiguredObjectAttribute) ArrayList(java.util.ArrayList) ConfiguredObjectTypeRegistry(org.apache.qpid.server.model.ConfiguredObjectTypeRegistry)

Aggregations

Exchange (org.apache.qpid.server.model.Exchange)53 Test (org.junit.Test)29 HashMap (java.util.HashMap)24 ServerMessage (org.apache.qpid.server.message.ServerMessage)15 Queue (org.apache.qpid.server.model.Queue)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 MessageDestination (org.apache.qpid.server.message.MessageDestination)13 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)8 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)8 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)8 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)8 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)8 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)8 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)7 AccessControlException (java.security.AccessControlException)6 LinkedHashMap (java.util.LinkedHashMap)6 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)6 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)6 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)6 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)5