Search in sources :

Example 1 with Header

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

the class PropertyConverter_1_0_to_0_10Test method testCreationTimeConversion.

@Test
public void testCreationTimeConversion() {
    final long timestamp = System.currentTimeMillis() - 10000;
    final long arrivalTime = timestamp + 1;
    Properties properties = new Properties();
    properties.setCreationTime(new Date(timestamp));
    Message_1_0 message = createTestMessage(new Header(), new DeliveryAnnotations(Collections.emptyMap()), new MessageAnnotations(Collections.emptyMap()), properties, new ApplicationProperties(Collections.emptyMap()), arrivalTime, null);
    final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    final DeliveryProperties deliveryProperties = convertedMessage.getStoredMessage().getMetaData().getDeliveryProperties();
    assertEquals("Unexpected timestamp", timestamp, deliveryProperties.getTimestamp());
}
Also used : Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) DeliveryAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) Date(java.util.Date) Test(org.junit.Test)

Example 2 with Header

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

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

the class PropertyConverter_0_10_to_1_0Test method testExpirationConversion.

@Test
public void testExpirationConversion() {
    long timestamp = System.currentTimeMillis();
    int ttl = 100000;
    final long expiration = timestamp + ttl;
    final DeliveryProperties deliveryProperties = new DeliveryProperties();
    deliveryProperties.setExpiration(expiration);
    MessageTransferMessage message = createTestMessage(deliveryProperties, new MessageProperties(), null, timestamp);
    final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    Properties properties = convertedMessage.getPropertiesSection().getValue();
    assertNull("Unexpected expiration", properties.getAbsoluteExpiryTime());
    Header header = convertedMessage.getHeaderSection().getValue();
    assertEquals("Unexpected TTL", (long) ttl, (long) header.getTtl().intValue());
}
Also used : Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) 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) Test(org.junit.Test)

Example 4 with Header

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

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

the class PropertyConverter_0_10_to_1_0Test method testPersistentDeliveryModeConversion.

@Test
public void testPersistentDeliveryModeConversion() {
    final DeliveryProperties deliveryProperties = new DeliveryProperties();
    deliveryProperties.setDeliveryMode(MessageDeliveryMode.PERSISTENT);
    MessageTransferMessage message = createTestMessage(deliveryProperties);
    final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
    Header header = convertedMessage.getHeaderSection().getValue();
    assertTrue("Unexpected durable header", header.getDurable());
}
Also used : Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) Test(org.junit.Test)

Aggregations

DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)30 Test (org.junit.Test)26 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)25 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)19 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)19 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)17 Header (org.apache.qpid.server.protocol.v0_10.transport.Header)16 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)10 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)8 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)8 Struct (org.apache.qpid.server.protocol.v0_10.transport.Struct)8 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)8 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 DeliveryAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations)7 ProtocolHeader (org.apache.qpid.server.protocol.v0_10.transport.ProtocolHeader)6 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)5 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)5 Date (java.util.Date)4 MessageMetaData_0_10 (org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)4