Search in sources :

Example 16 with Message_1_0

use of org.apache.qpid.server.protocol.v1_0.Message_1_0 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 17 with Message_1_0

use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10Test method testDataWithStreamMessageAnnotationAndContentTypeJmsStreamMessage.

public void testDataWithStreamMessageAnnotationAndContentTypeJmsStreamMessage() throws Exception {
    List<Object> originalList = Collections.singletonList("testValue");
    byte[] data = new ListToJmsStreamMessage().toMimeContent(originalList);
    String expectedMimeType = "jms/stream-message";
    final Data value = new Data(new Binary(data));
    Properties properties = new Properties();
    properties.setContentType(Symbol.valueOf(expectedMimeType));
    Message_1_0 sourceMessage = createTestMessage(properties, STREAM_MESSAGE_MESSAGE_ANNOTATION, value.createEncodingRetainingSection());
    final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", expectedMimeType, convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    assertArrayEquals("Unexpected content", data, getBytes(content));
}
Also used : ListToJmsStreamMessage(org.apache.qpid.server.typedmessage.mimecontentconverter.ListToJmsStreamMessage) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 18 with Message_1_0

use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10Test method doTestDataWithAnnotation.

private void doTestDataWithAnnotation(final byte[] data, final MessageAnnotations messageAnnotations, final String expectedMimeType) throws Exception {
    final Data value = new Data(new Binary(data));
    Message_1_0 sourceMessage = createTestMessage(messageAnnotations, value.createEncodingRetainingSection());
    final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", expectedMimeType, convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent();
    assertArrayEquals("Unexpected content", data, getBytes(content));
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary)

Example 19 with Message_1_0

use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10Test method testDataWithContentTypeAmqpMap.

public void testDataWithContentTypeAmqpMap() throws Exception {
    Map<String, Object> originalMap = Collections.singletonMap("testKey", "testValue");
    byte[] bytes = new MapToAmqpMapConverter().toMimeContent(originalMap);
    final Data value = new Data(new Binary(bytes));
    Properties properties = new Properties();
    properties.setContentType(Symbol.valueOf("amqp/map"));
    Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
    final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "amqp/map", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    assertArrayEquals("Unexpected content", bytes, getBytes(content));
}
Also used : MapToAmqpMapConverter(org.apache.qpid.server.protocol.v0_10.transport.mimecontentconverter.MapToAmqpMapConverter) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 20 with Message_1_0

use of org.apache.qpid.server.protocol.v1_0.Message_1_0 in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_10Test method testAmqpSequenceWithSimpleTypes.

public void testAmqpSequenceWithSimpleTypes() throws Exception {
    final List<Integer> expected = new ArrayList<>();
    expected.add(37);
    expected.add(42);
    final AmqpSequence amqpSequence = new AmqpSequence(expected);
    Message_1_0 sourceMessage = createTestMessage(amqpSequence.createEncodingRetainingSection());
    final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "jms/stream-message", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    assertEquals("Unexpected content", expected, new JmsStreamMessageToList().toObject(getBytes(content)));
}
Also used : JmsStreamMessageToList(org.apache.qpid.server.typedmessage.mimecontentconverter.JmsStreamMessageToList) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) ArrayList(java.util.ArrayList) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpSequence(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequence)

Aggregations

Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)254 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)199 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)153 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)125 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)116 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)112 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)75 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)73 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)69 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)68 Matchers.anyString (org.mockito.Matchers.anyString)67 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)58 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)55 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)52 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)49 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)35 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)32 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)25 HashMap (java.util.HashMap)21 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)17