Search in sources :

Example 56 with AMQMessageHeader

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

the class PropertyConverter_Internal_to_v0_10Test method testMessageIdUUIDConversion.

public void testMessageIdUUIDConversion() throws IOException {
    UUID messageId = UUID.randomUUID();
    final String messageIdAsString = messageId.toString();
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getMessageId()).thenReturn("ID:" + messageIdAsString);
    InternalMessage originalMessage = createTestMessage(header);
    MessageTransferMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected messageId", messageId, convertedMessage.getHeader().getMessageProperties().getMessageId());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) Matchers.anyString(org.mockito.Matchers.anyString) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader) UUID(java.util.UUID)

Example 57 with AMQMessageHeader

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

the class PropertyConverter_Internal_to_v0_10Test method testTimestampConversion.

public void testTimestampConversion() throws IOException {
    final long timestamp = System.currentTimeMillis();
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getTimestamp()).thenReturn(timestamp);
    InternalMessage originalMessage = createTestMessage(header);
    MessageTransferMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected timestamp", timestamp, convertedMessage.getHeader().getDeliveryProperties().getTimestamp());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 58 with AMQMessageHeader

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

the class PropertyConverter_Internal_to_v0_10Test method testExpirationConversion.

public void testExpirationConversion() throws InterruptedException, IOException {
    long ttl = 10000;
    long arrivalTime = System.currentTimeMillis();
    long expiryTime = arrivalTime + ttl;
    final AMQMessageHeader header = mock(AMQMessageHeader.class);
    when(header.getExpiration()).thenReturn(expiryTime);
    InternalMessage originalMessage = createTestMessage(header, arrivalTime);
    MessageTransferMessage convertedMessage = _messageConverter.convert(originalMessage, _addressSpace);
    assertEquals("Unexpected expiration time", expiryTime, convertedMessage.getHeader().getDeliveryProperties().getExpiration());
    assertEquals("Unexpected TTL", ttl, convertedMessage.getHeader().getDeliveryProperties().getTtl());
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 59 with AMQMessageHeader

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

the class MessageConverter_v0_8_to_Internal method convert.

@Override
public InternalMessage convert(AMQMessage serverMessage, NamedAddressSpace addressSpace) {
    final String mimeType = serverMessage.getMessageHeader().getMimeType();
    byte[] data = new byte[(int) serverMessage.getSize()];
    try (QpidByteBuffer content = serverMessage.getContent()) {
        content.get(data);
    }
    String encoding = serverMessage.getMessageHeader().getEncoding();
    byte[] uncompressed;
    if (GZIPUtils.GZIP_CONTENT_ENCODING.equals(encoding) && (uncompressed = GZIPUtils.uncompressBufferToArray(ByteBuffer.wrap(data))) != null) {
        data = uncompressed;
        encoding = null;
    }
    Object body = convertMessageBody(mimeType, data);
    final AMQMessageHeader convertedHeader = convertHeader(serverMessage, addressSpace, body, encoding);
    return InternalMessage.convert(serverMessage, convertedHeader, body);
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 60 with AMQMessageHeader

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

the class MessageConverter_v0_10_to_Internal method convert.

@Override
public InternalMessage convert(MessageTransferMessage serverMessage, NamedAddressSpace addressSpace) {
    final String mimeType = serverMessage.getMessageHeader().getMimeType();
    byte[] data = new byte[(int) serverMessage.getSize()];
    try (QpidByteBuffer content = serverMessage.getContent()) {
        content.get(data);
    }
    String encoding = serverMessage.getMessageHeader().getEncoding();
    byte[] uncompressed;
    if (GZIPUtils.GZIP_CONTENT_ENCODING.equals(encoding) && (uncompressed = GZIPUtils.uncompressBufferToArray(ByteBuffer.wrap(data))) != null) {
        data = uncompressed;
        encoding = null;
    }
    Object body = convertMessageBody(mimeType, data);
    final AMQMessageHeader convertedHeader = convertHeader(serverMessage, addressSpace, body, encoding);
    return InternalMessage.convert(serverMessage, convertedHeader, body);
}
Also used : QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Aggregations

AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)81 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)55 Matchers.anyString (org.mockito.Matchers.anyString)28 ServerMessage (org.apache.qpid.server.message.ServerMessage)16 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)15 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)11 HashMap (java.util.HashMap)10 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)8 MessageReference (org.apache.qpid.server.message.MessageReference)5 Queue (org.apache.qpid.server.model.Queue)5 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)5 Exchange (org.apache.qpid.server.model.Exchange)4 UUID (java.util.UUID)3 UnsignedLong (org.apache.qpid.server.protocol.v1_0.type.UnsignedLong)3 Date (java.util.Date)2 Set (java.util.Set)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)2 StoredMessage (org.apache.qpid.server.store.StoredMessage)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2