Search in sources :

Example 16 with DeliveryProperties

use of org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties 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 17 with DeliveryProperties

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

the class PropertyConverter_0_10_to_0_8Test method testPriorityConversion.

public void testPriorityConversion() {
    final byte priority = 5;
    final DeliveryProperties deliveryProperties = new DeliveryProperties();
    deliveryProperties.setPriority(MessageDeliveryPriority.get(priority));
    MessageTransferMessage message = createTestMessage(deliveryProperties);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties properties = convertedMessage.getContentHeaderBody().getProperties();
    assertEquals("Unexpected priority", priority, properties.getPriority());
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 18 with DeliveryProperties

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

the class PropertyConverter_0_10_to_0_8Test method testTTLConversion.

public void testTTLConversion() {
    long timestamp = System.currentTimeMillis();
    int ttl = 100000;
    final DeliveryProperties deliveryProperties = new DeliveryProperties();
    deliveryProperties.setTtl(ttl);
    MessageTransferMessage message = createTestMessage(deliveryProperties, new MessageProperties(), null, timestamp);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties properties = convertedMessage.getContentHeaderBody().getProperties();
    assertEquals("Unexpected expiration", timestamp + ttl, properties.getExpiration());
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 19 with DeliveryProperties

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

the class PropertyConverter_0_10_to_0_8Test method testTimestampConversion.

public void testTimestampConversion() {
    final DeliveryProperties deliveryProperties = new DeliveryProperties();
    final long timestamp = System.currentTimeMillis() - 1000;
    deliveryProperties.setTimestamp(timestamp);
    MessageTransferMessage message = createTestMessage(deliveryProperties);
    final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    BasicContentHeaderProperties properties = convertedMessage.getContentHeaderBody().getProperties();
    assertEquals("Unexpected creation timestamp", timestamp, properties.getTimestamp());
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQMessage(org.apache.qpid.server.protocol.v0_8.AMQMessage)

Example 20 with DeliveryProperties

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

the class PropertyConverter_0_10_to_0_8Test method createTestMessage.

private MessageTransferMessage createTestMessage(final DeliveryProperties deliveryProperties, final MessageProperties messageProperties, final byte[] content, final long arrivalTime) {
    int bodySize = content == null ? 0 : content.length;
    final org.apache.qpid.server.protocol.v0_10.transport.Header header = new org.apache.qpid.server.protocol.v0_10.transport.Header(deliveryProperties, messageProperties);
    final MessageMetaData_0_10 metaData = new MessageMetaData_0_10(header, bodySize, arrivalTime);
    final StoredMessage<MessageMetaData_0_10> storedMessage = mock(StoredMessage.class);
    when(storedMessage.getMetaData()).thenReturn(metaData);
    if (content != null) {
        when(storedMessage.getContentSize()).thenReturn(content.length);
        when(storedMessage.getContent(0, content.length)).thenReturn(QpidByteBuffer.wrap(content));
    } else {
        when(storedMessage.getContentSize()).thenReturn(0);
        when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
    }
    return new MessageTransferMessage(storedMessage, null);
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) MessageMetaData_0_10(org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)

Aggregations

DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)81 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)54 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)39 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)27 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)25 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)21 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)20 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)17 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)16 Matchers.anyString (org.mockito.Matchers.anyString)16 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)14 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)14 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)10 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)7 Date (java.util.Date)5 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)5 MessageMetaData_0_10 (org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)4 MessageDeliveryMode (org.apache.qpid.server.protocol.v0_10.transport.MessageDeliveryMode)4 DeliveryAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations)4 Method (org.apache.qpid.server.protocol.v0_10.transport.Method)3