use of org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_10Test method testGroupIdDoesNotReplaceApplicationPropertiesJMSXGroupID.
public void testGroupIdDoesNotReplaceApplicationPropertiesJMSXGroupID() {
String testGroupId = "group1";
Properties properties = new Properties();
properties.setGroupId(testGroupId);
final String JMSXGroupID = "group2";
Map<String, Object> applicationPropertiesMap = Collections.singletonMap("JMSXGroupID", JMSXGroupID);
ApplicationProperties applicationProperties = new ApplicationProperties(applicationPropertiesMap);
Message_1_0 message = createTestMessage(new Header(), new DeliveryAnnotations(Collections.emptyMap()), new MessageAnnotations(Collections.emptyMap()), properties, applicationProperties, 0, null);
final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
final MessageProperties messageProperties = convertedMessage.getStoredMessage().getMetaData().getMessageProperties();
final Map<String, Object> applicationHeaders = messageProperties.getApplicationHeaders();
assertEquals("Unexpected group-id", JMSXGroupID, applicationHeaders.get("JMSXGroupID"));
}
use of org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_10Test method testSubjectDoesNoReplaceApplicationPropertyQpidSubject.
public void testSubjectDoesNoReplaceApplicationPropertyQpidSubject() {
final String subject = "testSubject";
Properties properties = new Properties();
properties.setSubject(subject);
final String qpidSubject = "testSubject2";
Map<String, Object> applicationPropertiesMap = Collections.singletonMap("qpid.subject", qpidSubject);
ApplicationProperties applicationProperties = new ApplicationProperties(applicationPropertiesMap);
Message_1_0 message = createTestMessage(new Header(), new DeliveryAnnotations(Collections.emptyMap()), new MessageAnnotations(Collections.emptyMap()), properties, applicationProperties, 0, null);
final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
final MessageProperties messageProperties = convertedMessage.getStoredMessage().getMetaData().getMessageProperties();
final Map<String, Object> headers = messageProperties.getApplicationHeaders();
assertEquals("Unexpected qpid.subject is missing from headers", qpidSubject, headers.get("qpid.subject"));
assertEquals("Unexpected type", subject, headers.get("x-jms-type"));
final DeliveryProperties deliveryProperties = convertedMessage.getStoredMessage().getMetaData().getDeliveryProperties();
assertEquals("Unexpected routing-key", subject, deliveryProperties.getRoutingKey());
}
use of org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_10Test method testCreationTimeConversion.
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());
}
use of org.apache.qpid.amqp_1_0.type.messaging.MessageAnnotations in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_10Test method testContentToContentLengthConversion.
public void testContentToContentLengthConversion() {
final byte[] content = new byte[] { 0x31, 0x00, 0x10 };
Message_1_0 message = createTestMessage(new Header(), new DeliveryAnnotations(Collections.emptyMap()), new MessageAnnotations(Collections.emptyMap()), new Properties(), new ApplicationProperties(Collections.emptyMap()), 0, content);
final MessageTransferMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
final MessageProperties messageProperties = convertedMessage.getStoredMessage().getMetaData().getMessageProperties();
assertEquals("Unexpected content length", content.length, messageProperties.getContentLength());
}
use of org.apache.qpid.amqp_1_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());
}
Aggregations