Search in sources :

Example 16 with MessageAnnotations

use of org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_v1_0 method convertMetaData.

@Override
protected MessageMetaData_1_0 convertMetaData(final InternalMessage serverMessage, final EncodingRetainingSection<?> bodySection, final SectionEncoder sectionEncoder) {
    Header header = new Header();
    header.setDurable(serverMessage.isPersistent());
    header.setPriority(UnsignedByte.valueOf(serverMessage.getMessageHeader().getPriority()));
    if (serverMessage.getExpiration() != 0l && serverMessage.getArrivalTime() != 0l && serverMessage.getExpiration() >= serverMessage.getArrivalTime()) {
        header.setTtl(UnsignedInteger.valueOf(serverMessage.getExpiration() - serverMessage.getArrivalTime()));
    }
    Properties properties = new Properties();
    if (serverMessage.getMessageHeader().getEncoding() != null) {
        properties.setContentEncoding(Symbol.valueOf(serverMessage.getMessageHeader().getEncoding()));
    }
    properties.setCorrelationId(getCorrelationId(serverMessage));
    properties.setCreationTime(new Date(serverMessage.getMessageHeader().getTimestamp()));
    properties.setMessageId(getMessageId(serverMessage));
    Symbol contentType = getContentTypeSymbol(serverMessage.getMessageBody(), serverMessage.getMessageHeader().getMimeType());
    properties.setContentType(contentType);
    final String userId = serverMessage.getMessageHeader().getUserId();
    if (userId != null) {
        properties.setUserId(new Binary(userId.getBytes(StandardCharsets.UTF_8)));
    }
    properties.setReplyTo(serverMessage.getMessageHeader().getReplyTo());
    properties.setTo(serverMessage.getTo());
    ApplicationProperties applicationProperties = null;
    if (!serverMessage.getMessageHeader().getHeaderNames().isEmpty()) {
        try {
            applicationProperties = new ApplicationProperties(serverMessage.getMessageHeader().getHeaderMap());
        } catch (IllegalArgumentException e) {
            throw new MessageConversionException("Could not convert message from internal to 1.0" + " because conversion of 'application headers' failed.", e);
        }
    }
    final MessageAnnotations messageAnnotation = createMessageAnnotation(serverMessage.getMessageBody(), serverMessage.getMessageHeader().getMimeType(), bodySection);
    return new MessageMetaData_1_0(header.createEncodingRetainingSection(), null, messageAnnotation == null ? null : messageAnnotation.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties == null ? null : applicationProperties.createEncodingRetainingSection(), null, serverMessage.getArrivalTime(), bodySection.getEncodedSize());
}
Also used : MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) 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) Date(java.util.Date)

Example 17 with MessageAnnotations

use of org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.

the class MessageConverter_to_1_0 method createMessageAnnotation.

public static MessageAnnotations createMessageAnnotation(final EncodingRetainingSection<?> bodySection, final String contentMimeType) {
    MessageAnnotations messageAnnotations = null;
    final Symbol key = Symbol.valueOf("x-opt-jms-msg-type");
    if (contentMimeType != null) {
        if (TEXT_CONTENT_TYPES.matcher(contentMimeType).matches()) {
            messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, TEXT_MESSAGE.getType()));
        } else if (BYTES_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
            messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, BYTES_MESSAGE.getType()));
        } else if (MAP_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
            if (isSectionValidForJmsMap(bodySection)) {
                messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, MAP_MESSAGE.getType()));
            }
        } else if (LIST_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
            if (isSectionValidForJmsList(bodySection)) {
                messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, STREAM_MESSAGE.getType()));
            }
        } else if (OBJECT_MESSAGE_CONTENT_TYPES.matcher(contentMimeType).matches()) {
            messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, OBJECT_MESSAGE.getType()));
        }
    } else if (bodySection instanceof AmqpValueSection && bodySection.getValue() == null) {
        messageAnnotations = new MessageAnnotations(Collections.singletonMap(key, MESSAGE.getType()));
    }
    return messageAnnotations;
}
Also used : MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) AmqpValueSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)

Example 18 with MessageAnnotations

use of org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.

the class ConsumerTarget_1_0Test method createTestMessage.

private Message_1_0 createTestMessage(final Header header, long arrivalTime) {
    DeliveryAnnotationsSection deliveryAnnotations = new DeliveryAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
    MessageAnnotationsSection messageAnnotations = new MessageAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
    ApplicationPropertiesSection applicationProperties = new ApplicationProperties(Collections.emptyMap()).createEncodingRetainingSection();
    FooterSection footer = new Footer(Collections.emptyMap()).createEncodingRetainingSection();
    MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations, messageAnnotations, new Properties().createEncodingRetainingSection(), applicationProperties, footer, arrivalTime, 0);
    final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
    when(storedMessage.getContent(eq(0), anyInt())).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
    when(storedMessage.getMetaData()).thenReturn(metaData);
    return new Message_1_0(storedMessage);
}
Also used : DeliveryAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection) FooterSection(org.apache.qpid.server.protocol.v1_0.type.messaging.FooterSection) MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) DeliveryAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations) Footer(org.apache.qpid.server.protocol.v1_0.type.messaging.Footer) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) MessageAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection) ApplicationPropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationPropertiesSection) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 19 with MessageAnnotations

use of org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.

the class MessageConverter_v1_0_to_InternalTest method doTestDataWithAnnotation.

private void doTestDataWithAnnotation(final byte[] data, final MessageAnnotations messageAnnotations, final String mimeType, final String expectedMimeType) {
    final Data value = new Data(new Binary(data));
    Message_1_0 sourceMessage;
    if (mimeType != null) {
        Properties properties = new Properties();
        properties.setContentType(Symbol.valueOf(mimeType));
        sourceMessage = createTestMessage(properties, messageAnnotations, value.createEncodingRetainingSection());
    } else {
        sourceMessage = createTestMessage(messageAnnotations, value.createEncodingRetainingSection());
    }
    final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", expectedMimeType, convertedMessage.getMessageHeader().getMimeType());
    assertArrayEquals("Unexpected content", data, ((byte[]) convertedMessage.getMessageBody()));
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Data(org.apache.qpid.server.protocol.v1_0.type.messaging.Data) 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 MessageAnnotations

use of org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations in project storm by apache.

the class EventHubReceiverImpl method createMessageId.

private MessageId createMessageId(Message message) {
    String offset = null;
    long sequenceNumber = 0;
    for (Section section : message.getPayload()) {
        if (section instanceof MessageAnnotations) {
            MessageAnnotations annotations = (MessageAnnotations) section;
            HashMap annonationMap = (HashMap) annotations.getValue();
            if (annonationMap.containsKey(OffsetKey)) {
                offset = (String) annonationMap.get(OffsetKey);
            }
            if (annonationMap.containsKey(SequenceNumberKey)) {
                sequenceNumber = (Long) annonationMap.get(SequenceNumberKey);
            }
        }
    }
    return MessageId.create(partitionId, offset, sequenceNumber);
}
Also used : HashMap(java.util.HashMap) MessageAnnotations(org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations) Section(org.apache.qpid.amqp_1_0.type.Section)

Aggregations

MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)22 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)19 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)15 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)15 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)12 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)10 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)10 DeliveryAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations)10 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)8 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)8 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)8 Date (java.util.Date)7 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)7 Footer (org.apache.qpid.server.protocol.v1_0.type.messaging.Footer)7 MessageMetaData_1_0 (org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0)6 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)5 Data (org.apache.qpid.server.protocol.v1_0.type.messaging.Data)5 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)4 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)4 DataSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection)4