Search in sources :

Example 6 with DestinationAddress

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

the class MessageConverter_1_0_to_v0_8 method getReplyTo.

private AMQShortString getReplyTo(final Message_1_0 serverMsg, final NamedAddressSpace addressSpace) {
    final String replyTo = serverMsg.getMessageHeader().getReplyTo();
    if (replyTo != null) {
        DestinationAddress destinationAddress = new DestinationAddress(addressSpace, replyTo);
        MessageDestination messageDestination = destinationAddress.getMessageDestination();
        final String replyToBindingUrl;
        if (messageDestination instanceof Exchange) {
            Exchange<?> exchange = (Exchange<?>) messageDestination;
            final String routingKeyOption = "".equals(destinationAddress.getRoutingKey()) ? "" : String.format("?routingkey='%s'", destinationAddress.getRoutingKey());
            replyToBindingUrl = String.format("%s://%s//%s", exchange.getType(), exchange.getName(), routingKeyOption);
        } else if (messageDestination instanceof Queue) {
            replyToBindingUrl = String.format("%s:////%s", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, messageDestination.getName());
        } else {
            replyToBindingUrl = String.format("%s:////?routingkey='%s'", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, destinationAddress.getRoutingKey());
        }
        try {
            return AMQShortString.valueOf(replyToBindingUrl);
        } catch (IllegalArgumentException e) {
            throw new MessageConversionException("Could not convert message from 1.0 to 0-8 because conversion of 'reply-to' failed.", e);
        }
    }
    return null;
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessageDestination(org.apache.qpid.server.message.MessageDestination) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Queue(org.apache.qpid.server.model.Queue) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 7 with DestinationAddress

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

the class MessageConverter_1_0_to_v0_8 method createMessagePublishInfo.

private MessagePublishInfo createMessagePublishInfo(final MessageMetaData_1_0.MessageHeader_1_0 header, final NamedAddressSpace addressSpace) {
    final String to = header.getTo();
    final String subject = header.getSubject() == null ? "" : header.getSubject();
    final String exchangeName;
    final String routingKey;
    if (to != null && !"".equals(to)) {
        DestinationAddress destinationAddress = new DestinationAddress(addressSpace, to);
        MessageDestination messageDestination = destinationAddress.getMessageDestination();
        if (messageDestination instanceof Queue) {
            exchangeName = "";
            routingKey = messageDestination.getName();
        } else if (messageDestination instanceof Exchange) {
            exchangeName = messageDestination.getName();
            routingKey = "".equals(destinationAddress.getRoutingKey()) ? subject : destinationAddress.getRoutingKey();
        } else {
            exchangeName = "";
            routingKey = to;
        }
    } else {
        exchangeName = "";
        routingKey = subject;
    }
    return new MessagePublishInfo(convertToShortStringForProperty("to", exchangeName), false, false, convertToShortStringForProperty("to' or 'subject", routingKey));
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageDestination(org.apache.qpid.server.message.MessageDestination) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Queue(org.apache.qpid.server.model.Queue) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 8 with DestinationAddress

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

the class MessageConverter_Internal_to_v0_8 method getReplyTo.

private String getReplyTo(final InternalMessage serverMsg, final NamedAddressSpace addressSpace) {
    String replyTo = serverMsg.getMessageHeader().getReplyTo();
    if (replyTo != null) {
        DestinationAddress destinationAddress = new DestinationAddress(addressSpace, replyTo);
        MessageDestination messageDestination = destinationAddress.getMessageDestination();
        final String replyToBindingUrl;
        if (messageDestination instanceof Exchange) {
            Exchange<?> exchange = (Exchange<?>) messageDestination;
            final String routingKeyOption = "".equals(destinationAddress.getRoutingKey()) ? "" : String.format("?routingkey='%s'", destinationAddress.getRoutingKey());
            replyToBindingUrl = String.format("%s://%s//%s", exchange.getType(), exchange.getName(), routingKeyOption);
        } else if (messageDestination instanceof Queue) {
            replyToBindingUrl = String.format("%s:////%s", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, messageDestination.getName());
        } else {
            replyToBindingUrl = String.format("%s:////?routingkey='%s'", ExchangeDefaults.DIRECT_EXCHANGE_CLASS, destinationAddress.getRoutingKey());
        }
        return replyToBindingUrl;
    }
    return null;
}
Also used : 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 9 with DestinationAddress

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

the class Session_1_0 method getReceivingDestination.

public ReceivingDestination getReceivingDestination(final Link_1_0<?, ?> link, final Target target) throws AmqpErrorException {
    final ReceivingDestination destination;
    if (target != null) {
        if (Boolean.TRUE.equals(target.getDynamic())) {
            MessageDestination tempDestination = createDynamicDestination(link, target.getDynamicNodeProperties(), target.getCapabilities());
            if (tempDestination != null) {
                target.setAddress(_primaryDomain + tempDestination.getName());
            } else {
                throw new AmqpErrorException(AmqpError.INTERNAL_ERROR, "Cannot create dynamic destination");
            }
        }
        String addr = target.getAddress();
        if (addr == null || "".equals(addr.trim())) {
            destination = new AnonymousRelayDestination(getAddressSpace(), target, _connection.getEventLogger());
        } else {
            DestinationAddress destinationAddress = new DestinationAddress(getAddressSpace(), addr);
            MessageDestination messageDestination = destinationAddress.getMessageDestination();
            if (messageDestination != null) {
                destination = new NodeReceivingDestination(destinationAddress, target.getDurable(), target.getExpiryPolicy(), target.getCapabilities(), _connection.getEventLogger());
            } else {
                destination = null;
            }
        }
    } else {
        destination = null;
    }
    if (destination == null) {
        throw new AmqpErrorException(AmqpError.NOT_FOUND, String.format("Could not find destination for target '%s'", target));
    }
    return destination;
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 10 with DestinationAddress

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

the class MessageConverter_Internal_to_v0_10 method convertToAndInitialRoutingKey.

private void convertToAndInitialRoutingKey(final InternalMessage serverMsg, final DeliveryProperties deliveryProps, final NamedAddressSpace addressSpace) {
    String to = serverMsg.getTo();
    final String exchangeName;
    final String routingKey;
    if (to == null || "".equals(to)) {
        to = serverMsg.getInitialRoutingAddress();
    }
    if (to != null && !"".equals(to)) {
        DestinationAddress destinationAddress = new DestinationAddress(addressSpace, to);
        MessageDestination messageDestination = destinationAddress.getMessageDestination();
        if (messageDestination instanceof Queue) {
            exchangeName = "";
            routingKey = messageDestination.getName();
        } else if (messageDestination instanceof Exchange) {
            exchangeName = messageDestination.getName();
            routingKey = destinationAddress.getRoutingKey();
        } else {
            exchangeName = "";
            routingKey = to;
        }
    } else {
        exchangeName = "";
        routingKey = "";
    }
    deliveryProps.setRoutingKey(ensureStr8("to' or 'initialRoutingAddress", routingKey));
    deliveryProps.setExchange(ensureStr8("to' or 'initialRoutingAddress", exchangeName));
}
Also used : 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)

Aggregations

MessageDestination (org.apache.qpid.server.message.MessageDestination)11 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)11 Exchange (org.apache.qpid.server.model.Exchange)8 Queue (org.apache.qpid.server.model.Queue)8 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)2 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)2 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)2 RoutingResult (org.apache.qpid.server.message.RoutingResult)1 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)1 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)1