Search in sources :

Example 1 with MessageMetaData_0_10

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

the class MessageConverter_1_0_to_v0_10 method convertMetaData.

private MessageMetaData_0_10 convertMetaData(Message_1_0 serverMsg, final NamedAddressSpace addressSpace, final String bodyMimeType, final int size) {
    DeliveryProperties deliveryProps = new DeliveryProperties();
    MessageProperties messageProps = new MessageProperties();
    final MessageMetaData_1_0.MessageHeader_1_0 origHeader = serverMsg.getMessageHeader();
    setExchangeAndRoutingKeyOnDeliveryProperties(deliveryProps, origHeader, addressSpace);
    deliveryProps.setDeliveryMode(serverMsg.isPersistent() ? MessageDeliveryMode.PERSISTENT : MessageDeliveryMode.NON_PERSISTENT);
    deliveryProps.setExpiration(serverMsg.getExpiration());
    deliveryProps.setPriority(MessageDeliveryPriority.get(origHeader.getPriority()));
    Date creationTime = getCreationTime(serverMsg);
    final long arrivalTime = serverMsg.getArrivalTime();
    if (creationTime != null) {
        deliveryProps.setTimestamp(creationTime.getTime());
    } else {
        deliveryProps.setTimestamp(arrivalTime);
    }
    Long ttl = getTtl(serverMsg);
    Date absoluteExpiryTime = getAbsoluteExpiryTime(serverMsg);
    if (ttl != null) {
        deliveryProps.setTtl(ttl);
        deliveryProps.setExpiration(arrivalTime + ttl);
    } else if (absoluteExpiryTime != null) {
        final long time = absoluteExpiryTime.getTime();
        deliveryProps.setTtl(Math.max(0, time - arrivalTime));
        deliveryProps.setExpiration(time);
    }
    UUID messageId = getMessageIdAsUUID(serverMsg);
    if (messageId != null) {
        messageProps.setMessageId(messageId);
    }
    byte[] correlationId = getCorrelationIdAsBytes(serverMsg);
    if (correlationId != null) {
        messageProps.setCorrelationId(correlationId);
    }
    final String encoding = origHeader.getEncoding();
    if (encoding != null) {
        messageProps.setContentEncoding(ensureStr8("content-encoding", encoding));
    }
    messageProps.setContentLength(size);
    messageProps.setContentType(bodyMimeType);
    byte[] userId = getUserIdAsBytes(serverMsg);
    if (userId != null && userId.length <= MAX_VBIN16_LENGTH) {
        messageProps.setUserId(ensureVBin16("user-id", userId));
    }
    final String origReplyTo = origHeader.getReplyTo();
    if (origReplyTo != null && !origReplyTo.equals("")) {
        messageProps.setReplyTo(getReplyTo(addressSpace, origReplyTo));
    }
    Map<String, Object> appHeaders = getApplicationHeaders(serverMsg);
    messageProps.setApplicationHeaders(appHeaders);
    Header header = new Header(deliveryProps, messageProps, null);
    return new MessageMetaData_0_10(header, size, arrivalTime);
}
Also used : MessageMetaData_1_0(org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) Date(java.util.Date) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) UnsignedLong(org.apache.qpid.server.protocol.v1_0.type.UnsignedLong) UUID(java.util.UUID) MessageMetaData_0_10(org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)

Example 2 with MessageMetaData_0_10

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

the class MessageConverter_1_0_to_v0_10 method convertToStoredMessage.

private StoredMessage<MessageMetaData_0_10> convertToStoredMessage(final Message_1_0 serverMsg, final NamedAddressSpace addressSpace) {
    final ConvertedContentAndMimeType convertedContentAndMimeType = getAmqp0xConvertedContentAndMimeType(serverMsg);
    final byte[] convertedContent = convertedContentAndMimeType.getContent();
    final MessageMetaData_0_10 messageMetaData_0_10 = convertMetaData(serverMsg, addressSpace, convertedContentAndMimeType.getMimeType(), convertedContent.length);
    final int metadataSize = messageMetaData_0_10.getStorableSize();
    return new StoredMessage<MessageMetaData_0_10>() {

        @Override
        public MessageMetaData_0_10 getMetaData() {
            return messageMetaData_0_10;
        }

        @Override
        public long getMessageNumber() {
            return serverMsg.getMessageNumber();
        }

        @Override
        public QpidByteBuffer getContent(final int offset, final int length) {
            return QpidByteBuffer.wrap(convertedContent, offset, length);
        }

        @Override
        public int getContentSize() {
            return convertedContent.length;
        }

        @Override
        public int getMetadataSize() {
            return metadataSize;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isInContentInMemory() {
            return true;
        }

        @Override
        public long getInMemorySize() {
            return getContentSize() + getMetadataSize();
        }

        @Override
        public boolean flowToDisk() {
            return false;
        }

        @Override
        public void reallocate() {
        }
    };
}
Also used : StoredMessage(org.apache.qpid.server.store.StoredMessage) ConvertedContentAndMimeType(org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.ConvertedContentAndMimeType) MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType(org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType) MessageMetaData_0_10(org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)

Example 3 with MessageMetaData_0_10

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

the class PropertyConverter_0_10_to_1_0Test 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 : Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) MessageMetaData_0_10(org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)

Example 4 with MessageMetaData_0_10

use of org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10 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)

Example 5 with MessageMetaData_0_10

use of org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10 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());
    }
    final Map<String, Object> appHeaders = new LinkedHashMap<>(properties.getHeadersAsMap());
    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) 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) LinkedHashMap(java.util.LinkedHashMap) 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)

Aggregations

Header (org.apache.qpid.server.protocol.v0_10.transport.Header)7 MessageMetaData_0_10 (org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)6 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)6 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)6 UUID (java.util.UUID)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)2 StoredMessage (org.apache.qpid.server.store.StoredMessage)2 URISyntaxException (java.net.URISyntaxException)1 BufferUnderflowException (java.nio.BufferUnderflowException)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)1 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)1 Struct (org.apache.qpid.server.protocol.v0_10.transport.Struct)1 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)1 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)1 ConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.ConvertedContentAndMimeType)1 MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType)1 MessageMetaData_1_0 (org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0)1