Search in sources :

Example 16 with MessageDestination

use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.

the class ServerSessionDelegate method getDestinationForMessage.

private MessageDestination getDestinationForMessage(ServerSession ssn, MessageTransfer xfr) {
    NamedAddressSpace addressSpace = getAddressSpace(ssn);
    MessageDestination destination;
    if (xfr.hasDestination()) {
        destination = addressSpace.getAttainedMessageDestination(xfr.getDestination());
        if (destination == null) {
            destination = addressSpace.getDefaultDestination();
        } else {
            Header header = xfr.getHeader();
            DeliveryProperties delvProps;
            if (header == null) {
                delvProps = new DeliveryProperties();
                header = new Header(delvProps, null, null);
                xfr.setHeader(header);
            } else if (header.getDeliveryProperties() == null) {
                delvProps = new DeliveryProperties();
                header = new Header(delvProps, header.getMessageProperties(), header.getNonStandardProperties());
                xfr.setHeader(header);
            } else {
                delvProps = header.getDeliveryProperties();
            }
            if (delvProps.getExchange() == null && !xfr.getDestination().equals(delvProps.getRoutingKey())) {
                delvProps.setExchange(xfr.getDestination());
            }
        }
    } else if (xfr.getHeader() != null && xfr.getHeader().getDeliveryProperties() != null && xfr.getHeader().getDeliveryProperties().getExchange() != null) {
        destination = addressSpace.getAttainedMessageDestination(xfr.getHeader().getDeliveryProperties().getExchange());
    } else {
        destination = addressSpace.getDefaultDestination();
    }
    return destination;
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace)

Example 17 with MessageDestination

use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.

the class ManagementNode method sendResponse.

private void sendResponse(final InternalMessage message, final InternalMessage response) {
    String replyTo = message.getMessageHeader().getReplyTo();
    response.setInitialRoutingAddress(replyTo);
    final MessageDestination responseDestination = getResponseDestination(replyTo);
    RoutingResult<InternalMessage> result = responseDestination.route(response, replyTo, InstanceProperties.EMPTY);
    result.send(new AutoCommitTransaction(_addressSpace.getMessageStore()), null);
}
Also used : AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) MessageDestination(org.apache.qpid.server.message.MessageDestination) InternalMessage(org.apache.qpid.server.message.internal.InternalMessage)

Example 18 with MessageDestination

use of org.apache.qpid.server.message.MessageDestination 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 19 with MessageDestination

use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.

the class MessageConverter_0_10_to_0_8 method convertContentHeaderProperties.

public static BasicContentHeaderProperties convertContentHeaderProperties(MessageTransferMessage messageTransferMessage, NamedAddressSpace addressSpace) {
    BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    Header header = messageTransferMessage.getHeader();
    DeliveryProperties deliveryProps = header.getDeliveryProperties();
    MessageProperties messageProps = header.getMessageProperties();
    if (deliveryProps != null) {
        if (deliveryProps.hasDeliveryMode()) {
            props.setDeliveryMode((deliveryProps.getDeliveryMode() == MessageDeliveryMode.PERSISTENT ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT));
        }
        if (deliveryProps.hasTtl()) {
            props.setExpiration(messageTransferMessage.getArrivalTime() + deliveryProps.getTtl());
        } else if (deliveryProps.hasExpiration()) {
            props.setExpiration(deliveryProps.getExpiration());
        }
        if (deliveryProps.hasPriority()) {
            props.setPriority((byte) deliveryProps.getPriority().getValue());
        }
        if (deliveryProps.hasTimestamp()) {
            props.setTimestamp(deliveryProps.getTimestamp());
        } else {
            props.setTimestamp(messageTransferMessage.getArrivalTime());
        }
    }
    if (messageProps != null) {
        if (messageProps.hasAppId()) {
            try {
                props.setAppId(new AMQShortString(messageProps.getAppId()));
            } catch (IllegalArgumentException e) {
            // pass
            }
        }
        if (messageProps.hasContentType()) {
            props.setContentType(messageProps.getContentType());
        }
        if (messageProps.hasCorrelationId()) {
            try {
                props.setCorrelationId(new AMQShortString(messageProps.getCorrelationId()));
            } catch (IllegalArgumentException e) {
                throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of 'correlationId' failed.", e);
            }
        }
        if (messageProps.hasContentEncoding()) {
            props.setEncoding(messageProps.getContentEncoding());
        }
        if (messageProps.hasMessageId()) {
            // Add prefix 'ID:' to workaround broken 0-8..0-9-1 Qpid JMS client
            props.setMessageId("ID:" + messageProps.getMessageId().toString());
        }
        if (messageProps.hasReplyTo()) {
            ReplyTo replyTo = messageProps.getReplyTo();
            String exchangeName = replyTo.getExchange();
            String routingKey = replyTo.getRoutingKey();
            if (exchangeName == null) {
                exchangeName = "";
            }
            if (!"".equals(exchangeName) || (routingKey != null && !"".equals(routingKey))) {
                MessageDestination destination = addressSpace.getAttainedMessageDestination(exchangeName);
                Exchange<?> exchange = destination instanceof Exchange ? (Exchange<?>) destination : null;
                String exchangeClass = exchange == null ? ExchangeDefaults.DIRECT_EXCHANGE_CLASS : exchange.getType();
                String routingKeyOption = routingKey == null ? "" : "?routingkey='" + routingKey + "'";
                final String replyToBindingUrl = String.format("%s://%s//%s", exchangeClass, exchangeName, routingKeyOption);
                try {
                    props.setReplyTo(replyToBindingUrl);
                } catch (IllegalArgumentException e) {
                    throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because conversion of 'reply-to' failed.", e);
                }
            }
        }
        if (messageProps.hasUserId()) {
            try {
                props.setUserId(new AMQShortString(messageProps.getUserId()));
            } catch (IllegalArgumentException e) {
            // ignore
            }
        }
        if (messageProps.hasApplicationHeaders()) {
            Map<String, Object> appHeaders = new HashMap<String, Object>(messageProps.getApplicationHeaders());
            if (messageProps.getApplicationHeaders().containsKey("x-jms-type")) {
                String jmsType = String.valueOf(appHeaders.remove("x-jms-type"));
                try {
                    props.setType(jmsType);
                } catch (IllegalArgumentException e) {
                    throw new MessageConversionException("Could not convert message from 0-10 to 0-8 because x-jms-type conversion failed.", e);
                }
            }
            FieldTable ft = new FieldTable();
            for (Map.Entry<String, Object> entry : appHeaders.entrySet()) {
                String headerName = entry.getKey();
                try {
                    ft.put(AMQShortString.validValueOf(headerName), entry.getValue());
                } catch (AMQPInvalidClassException e) {
                    throw new MessageConversionException(String.format("Could not convert message from 0-10 to 0-8 because conversion of application header '%s' failed.", headerName), e);
                }
            }
            props.setHeaders(ft);
        }
    }
    return props;
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) MessageDestination(org.apache.qpid.server.message.MessageDestination) AMQPInvalidClassException(org.apache.qpid.server.protocol.v0_8.AMQPInvalidClassException) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) HashMap(java.util.HashMap) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) Exchange(org.apache.qpid.server.model.Exchange) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with MessageDestination

use of org.apache.qpid.server.message.MessageDestination 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)

Aggregations

MessageDestination (org.apache.qpid.server.message.MessageDestination)40 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)11 Queue (org.apache.qpid.server.model.Queue)11 Exchange (org.apache.qpid.server.model.Exchange)10 HashMap (java.util.HashMap)6 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)6 Map (java.util.Map)5 AlternateBinding (org.apache.qpid.server.model.AlternateBinding)5 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)5 AccessControlException (java.security.AccessControlException)4 HashSet (java.util.HashSet)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 RoutingResult (org.apache.qpid.server.message.RoutingResult)4 Binding (org.apache.qpid.server.model.Binding)4 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)4 Set (java.util.Set)3 TopicExchangeResult (org.apache.qpid.server.exchange.topic.TopicExchangeResult)3 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)3 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)3 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)3