use of org.apache.qpid.server.protocol.v0_10.transport.MessageProperties 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);
}
use of org.apache.qpid.server.protocol.v0_10.transport.MessageProperties in project qpid-broker-j by apache.
the class PropertyConverter_0_10_to_1_0Test method testReplyToConversionWhenExchangeIsEmptyStringAndRoutingKeySpecified.
public void testReplyToConversionWhenExchangeIsEmptyStringAndRoutingKeySpecified() {
final String routingKey = "test_routing_key";
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setReplyTo(new ReplyTo("", routingKey));
MessageTransferMessage message = createTestMessage(messageProperties);
final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
Properties properties = convertedMessage.getPropertiesSection().getValue();
assertEquals("Unexpected reply-to", "test_routing_key", properties.getReplyTo());
}
use of org.apache.qpid.server.protocol.v0_10.transport.MessageProperties in project qpid-broker-j by apache.
the class PropertyConverter_0_10_to_1_0Test method testHeaderConversionWhenQpidSubjectIsPresent.
public void testHeaderConversionWhenQpidSubjectIsPresent() {
String testSubject = "testSubject";
Map<String, Object> headers = new HashMap<>();
headers.put("testProperty1", "testProperty1Value");
headers.put("qpid.subject", testSubject);
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setApplicationHeaders(headers);
MessageTransferMessage message = createTestMessage(messageProperties);
final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
Properties properties = convertedMessage.getPropertiesSection().getValue();
assertEquals("Unexpected subject", testSubject, properties.getSubject());
Map<String, Object> applicationProperties = convertedMessage.getApplicationPropertiesSection().getValue();
assertFalse("Unexpected subject in application properties", applicationProperties.containsKey("qpid.subject"));
}
use of org.apache.qpid.server.protocol.v0_10.transport.MessageProperties in project qpid-broker-j by apache.
the class PropertyConverter_0_10_to_1_0Test method createTestMessage.
private MessageTransferMessage createTestMessage(final DeliveryProperties deliveryProperties, final MessageProperties messageProperties, final byte[] content, final long arrivalTime) {
int bodySize = content == null ? 0 : content.length;
final org.apache.qpid.server.protocol.v0_10.transport.Header header = new org.apache.qpid.server.protocol.v0_10.transport.Header(deliveryProperties, messageProperties);
final MessageMetaData_0_10 metaData = new MessageMetaData_0_10(header, bodySize, arrivalTime);
final StoredMessage<MessageMetaData_0_10> storedMessage = mock(StoredMessage.class);
when(storedMessage.getMetaData()).thenReturn(metaData);
if (content != null) {
when(storedMessage.getContentSize()).thenReturn(content.length);
when(storedMessage.getContent(0, content.length)).thenReturn(QpidByteBuffer.wrap(content));
} else {
when(storedMessage.getContentSize()).thenReturn(0);
when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
}
return new MessageTransferMessage(storedMessage, null);
}
use of org.apache.qpid.server.protocol.v0_10.transport.MessageProperties in project qpid-broker-j by apache.
the class PropertyConverter_0_10_to_1_0Test method testReplyToConversionWhenExchangeAndRoutingKeySpecified.
public void testReplyToConversionWhenExchangeAndRoutingKeySpecified() {
final String exchangeName = "amq.direct";
final String routingKey = "test_routing_key";
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setReplyTo(new ReplyTo(exchangeName, routingKey));
MessageTransferMessage message = createTestMessage(messageProperties);
final Message_1_0 convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
Properties properties = convertedMessage.getPropertiesSection().getValue();
assertEquals("Unexpected reply-to", "amq.direct/test_routing_key", properties.getReplyTo());
}
Aggregations