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());
}
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;
}
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);
}
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()));
}
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);
}
Aggregations