use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 in project qpid-broker-j by apache.
the class PropertyConverter_v1_0_to_InternalTest method createTestMessage.
private Message_1_0 createTestMessage(final Header header, final DeliveryAnnotations deliveryAnnotations, final MessageAnnotations messageAnnotations, final Properties properties, final ApplicationProperties applicationProperties, final long arrivalTime, final byte[] content) {
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations.createEncodingRetainingSection(), messageAnnotations.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties.createEncodingRetainingSection(), new Footer(Collections.emptyMap()).createEncodingRetainingSection(), arrivalTime, content == null ? 0 : content.length);
when(storedMessage.getMetaData()).thenReturn(metaData);
if (content != null) {
Binary binary = new Binary(content);
DataSection dataSection = new Data(binary).createEncodingRetainingSection();
QpidByteBuffer qbb = dataSection.getEncodedForm();
int length = qbb.remaining();
when(storedMessage.getContentSize()).thenReturn(length);
when(storedMessage.getContent(0, length)).thenReturn(qbb);
} else {
when(storedMessage.getContentSize()).thenReturn(0);
when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
}
return new Message_1_0(storedMessage);
}
use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_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);
}
use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_10Test method createTestMessage.
private Message_1_0 createTestMessage(final Header header, final DeliveryAnnotations deliveryAnnotations, final MessageAnnotations messageAnnotations, final Properties properties, final ApplicationProperties applicationProperties, final long arrivalTime, final EncodingRetainingSection section) {
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations.createEncodingRetainingSection(), messageAnnotations.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties.createEncodingRetainingSection(), new Footer(Collections.emptyMap()).createEncodingRetainingSection(), arrivalTime, 0);
when(storedMessage.getMetaData()).thenReturn(metaData);
if (section != null) {
// TODO this seems to leak QBBs
final QpidByteBuffer combined = section.getEncodedForm();
when(storedMessage.getContentSize()).thenReturn((int) section.getEncodedSize());
final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
when(storedMessage.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(invocation -> combined.view(offsetCaptor.getValue(), sizeCaptor.getValue()));
} else {
when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
}
return new Message_1_0(storedMessage);
}
use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method createTestMessage.
private Message_1_0 createTestMessage(final Header header, final DeliveryAnnotations deliveryAnnotations, final MessageAnnotations messageAnnotations, final Properties properties, final ApplicationProperties applicationProperties, final long arrivalTime, final EncodingRetainingSection section) {
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations.createEncodingRetainingSection(), messageAnnotations.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties.createEncodingRetainingSection(), new Footer(Collections.emptyMap()).createEncodingRetainingSection(), arrivalTime, 0);
when(storedMessage.getMetaData()).thenReturn(metaData);
if (section != null) {
// TODO this seems to leak QBBs
final QpidByteBuffer combined = section.getEncodedForm();
when(storedMessage.getContentSize()).thenReturn((int) section.getEncodedSize());
final ArgumentCaptor<Integer> offsetCaptor = ArgumentCaptor.forClass(Integer.class);
final ArgumentCaptor<Integer> sizeCaptor = ArgumentCaptor.forClass(Integer.class);
when(storedMessage.getContent(offsetCaptor.capture(), sizeCaptor.capture())).then(invocation -> combined.view(offsetCaptor.getValue(), sizeCaptor.getValue()));
} else {
when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
}
return new Message_1_0(storedMessage);
}
use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_10Test method createTestMessage.
private Message_1_0 createTestMessage(final Header header, final DeliveryAnnotations deliveryAnnotations, final MessageAnnotations messageAnnotations, final Properties properties, final ApplicationProperties applicationProperties, final long arrivalTime, final byte[] content) {
final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations.createEncodingRetainingSection(), messageAnnotations.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties.createEncodingRetainingSection(), new Footer(Collections.emptyMap()).createEncodingRetainingSection(), arrivalTime, content == null ? 0 : content.length);
when(storedMessage.getMetaData()).thenReturn(metaData);
if (content != null) {
Binary binary = new Binary(content);
DataSection dataSection = new Data(binary).createEncodingRetainingSection();
QpidByteBuffer qbb = dataSection.getEncodedForm();
int length = qbb.remaining();
when(storedMessage.getContentSize()).thenReturn(length);
when(storedMessage.getContent(0, length)).thenReturn(qbb);
} else {
when(storedMessage.getContentSize()).thenReturn(0);
when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
}
return new Message_1_0(storedMessage);
}
Aggregations