Search in sources :

Example 6 with ReplyTo

use of org.apache.qpid.server.protocol.v0_10.transport.ReplyTo in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_10Test method testReplyToConversionWhenReplyToCannotBeResolved.

public void testReplyToConversionWhenReplyToCannotBeResolved() throws IOException {
    final String replyTo = "direct://amq.direct//test?routingkey='test'";
    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", "", convertedReplyTo.getExchange());
    assertEquals("Unexpected routing key", replyTo, convertedReplyTo.getRoutingKey());
}
Also used : 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) Matchers.anyString(org.mockito.Matchers.anyString) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)

Example 7 with ReplyTo

use of org.apache.qpid.server.protocol.v0_10.transport.ReplyTo in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_10Test method testReplyToConversionWhenQueueIsSpecified.

public void testReplyToConversionWhenQueueIsSpecified() throws IOException {
    final String replyTo = "myTestQueue";
    final Queue queue = mock(Queue.class);
    when(queue.getName()).thenReturn(replyTo);
    when(_namedAddressSpace.getAttainedMessageDestination(replyTo)).thenReturn(queue);
    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", "", convertedReplyTo.getExchange());
    assertEquals("Unexpected routing key", replyTo, convertedReplyTo.getRoutingKey());
}
Also used : 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) Matchers.anyString(org.mockito.Matchers.anyString) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) Queue(org.apache.qpid.server.model.Queue)

Example 8 with ReplyTo

use of org.apache.qpid.server.protocol.v0_10.transport.ReplyTo in project qpid-broker-j by apache.

the class MessageConverter_0_8_to_0_10 method convertMetaData.

private MessageMetaData_0_10 convertMetaData(AMQMessage message_0_8) {
    DeliveryProperties deliveryProps = new DeliveryProperties();
    MessageProperties messageProps = new MessageProperties();
    int size = (int) message_0_8.getSize();
    BasicContentHeaderProperties properties = message_0_8.getContentHeaderBody().getProperties();
    final AMQShortString exchange = message_0_8.getMessagePublishInfo().getExchange();
    if (exchange != null) {
        deliveryProps.setExchange(exchange.toString());
    }
    deliveryProps.setExpiration(message_0_8.getExpiration());
    if (message_0_8.getExpiration() != 0) {
        deliveryProps.setTtl(message_0_8.getExpiration() - message_0_8.getArrivalTime());
    }
    deliveryProps.setImmediate(message_0_8.isImmediate());
    deliveryProps.setDiscardUnroutable(!message_0_8.isMandatory());
    deliveryProps.setPriority(MessageDeliveryPriority.get(properties.getPriority()));
    deliveryProps.setRoutingKey(message_0_8.getInitialRoutingAddress());
    deliveryProps.setTimestamp(properties.getTimestamp());
    if (properties.getDeliveryMode() == BasicContentHeaderProperties.PERSISTENT) {
        deliveryProps.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
    } else {
        deliveryProps.setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
    }
    messageProps.setContentEncoding(properties.getEncodingAsString());
    messageProps.setContentLength(size);
    if (properties.getAppId() != null) {
        messageProps.setAppId(properties.getAppId().getBytes());
    }
    messageProps.setContentType(properties.getContentTypeAsString());
    if (properties.getCorrelationId() != null) {
        messageProps.setCorrelationId(properties.getCorrelationId().getBytes());
    }
    if (properties.getReplyTo() != null && properties.getReplyTo().length() != 0) {
        String origReplyToString = properties.getReplyTo().toString();
        ReplyTo replyTo = new ReplyTo();
        // if the string looks like a binding URL, then attempt to parse it...
        try {
            AMQBindingURL burl = new AMQBindingURL(origReplyToString);
            String routingKey = burl.getRoutingKey();
            if (routingKey != null) {
                replyTo.setRoutingKey(routingKey);
            }
            String exchangeName = burl.getExchangeName();
            if (exchangeName != null && !"".equals(exchangeName)) {
                replyTo.setExchange(exchangeName);
            }
        } catch (URISyntaxException e) {
            replyTo.setRoutingKey(origReplyToString);
        }
        messageProps.setReplyTo(replyTo);
    }
    if (properties.getMessageId() != null) {
        UUID uuid;
        String messageIdAsString = properties.getMessageIdAsString();
        if (messageIdAsString.startsWith("ID:")) {
            messageIdAsString = messageIdAsString.substring(3);
        }
        try {
            uuid = UUID.fromString(messageIdAsString);
        } catch (IllegalArgumentException e) {
            uuid = UUID.nameUUIDFromBytes(messageIdAsString.getBytes(UTF_8));
        }
        messageProps.setMessageId(uuid);
    }
    if (properties.getUserId() != null) {
        messageProps.setUserId(properties.getUserId().getBytes());
    }
    FieldTable fieldTable = properties.getHeaders();
    Map<String, Object> appHeaders = FieldTable.convertToMap(fieldTable);
    if (properties.getType() != null) {
        appHeaders.put("x-jms-type", properties.getTypeAsString());
    }
    messageProps.setApplicationHeaders(appHeaders);
    Header header = new Header(deliveryProps, messageProps, null);
    return new MessageMetaData_0_10(header, size, message_0_8.getArrivalTime());
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AMQBindingURL(org.apache.qpid.server.url.AMQBindingURL) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) URISyntaxException(java.net.URISyntaxException) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) UUID(java.util.UUID) MessageMetaData_0_10(org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)

Example 9 with ReplyTo

use of org.apache.qpid.server.protocol.v0_10.transport.ReplyTo in project qpid-broker-j by apache.

the class PropertyConverter_0_10_to_0_8Test method testReplyToConversionWhenRoutingKeySpecified.

public void testReplyToConversionWhenRoutingKeySpecified() {
    final String routingKey = "test_routing_key";
    final MessageProperties messageProperties = new MessageProperties();
    messageProperties.setReplyTo(new ReplyTo(null, routingKey));
    MessageTransferMessage message = createTestMessage(messageProperties);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties properties = convertedMessage.getContentHeaderBody().getProperties();
    String expectedReplyTo = String.format("direct:////?routingkey='%s'", routingKey);
    assertEquals("Unexpected reply-to", expectedReplyTo, properties.getReplyTo().toString());
}
Also used : ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 10 with ReplyTo

use of org.apache.qpid.server.protocol.v0_10.transport.ReplyTo in project qpid-broker-j by apache.

the class PropertyConverter_0_10_to_0_8Test method testReplyToConversionWhenExchangeAndRoutingKeyAreNull.

public void testReplyToConversionWhenExchangeAndRoutingKeyAreNull() {
    final MessageProperties messageProperties = new MessageProperties();
    messageProperties.setReplyTo(new ReplyTo(null, null));
    MessageTransferMessage message = createTestMessage(messageProperties);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties properties = convertedMessage.getContentHeaderBody().getProperties();
    assertNull("Unexpected reply-to", properties.getReplyTo());
}
Also used : ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Aggregations

MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)31 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)31 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)21 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)15 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)14 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)12 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)12 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)11 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)10 Matchers.anyString (org.mockito.Matchers.anyString)10 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)9 Exchange (org.apache.qpid.server.model.Exchange)8 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)7 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)5 Queue (org.apache.qpid.server.model.Queue)4 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)4 MessageDestination (org.apache.qpid.server.message.MessageDestination)3 HashMap (java.util.HashMap)2 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)2 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)2