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_8 method convertMetaData.
private MessageMetaData convertMetaData(final Message_1_0 serverMsg, final String bodyMimeType, final int size, final NamedAddressSpace addressSpace) {
final MessageMetaData_1_0.MessageHeader_1_0 header = serverMsg.getMessageHeader();
final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
props.setAppId(serverMsg.getMessageHeader().getAppId());
props.setContentType(bodyMimeType);
props.setEncoding(convertToShortStringForProperty("content-encoding", serverMsg.getMessageHeader().getEncoding()));
props.setCorrelationId(getCorrelationIdAsShortString(serverMsg));
props.setDeliveryMode(serverMsg.isPersistent() ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT);
final Date absoluteExpiryTime = getAbsoluteExpiryTime(serverMsg);
if (absoluteExpiryTime != null) {
props.setExpiration(absoluteExpiryTime.getTime());
} else {
Long ttl = getTtl(serverMsg);
if (ttl != null) {
props.setExpiration(ttl + serverMsg.getArrivalTime());
}
}
props.setMessageId(getMessageIdAsShortString(serverMsg));
props.setPriority(serverMsg.getMessageHeader().getPriority());
props.setReplyTo(getReplyTo(serverMsg, addressSpace));
Date timestamp = getCreationTime(serverMsg);
if (timestamp != null) {
props.setTimestamp(timestamp.getTime());
} else {
props.setTimestamp(serverMsg.getArrivalTime());
}
props.setUserId(getUserIdAsShortString(serverMsg));
Map<String, Object> headerProps = new LinkedHashMap<>();
if (header.getSubject() != null) {
headerProps.put("qpid.subject", header.getSubject());
props.setType(convertToShortStringForProperty("subject", header.getSubject()));
}
String groupId = getGroupId(serverMsg);
if (groupId != null) {
headerProps.put("JMSXGroupID", groupId);
}
UnsignedInteger groupSequence = getGroupSequence(serverMsg);
if (groupSequence != null) {
headerProps.put("JMSXGroupSeq", groupSequence.intValue());
}
for (String headerName : serverMsg.getMessageHeader().getHeaderNames()) {
headerProps.put(headerName, convertValue(serverMsg.getMessageHeader().getHeader(headerName)));
}
final FieldTable headers;
try {
headers = FieldTable.convertToFieldTable(headerProps);
} catch (IllegalArgumentException e) {
throw new MessageConversionException("Could not convert message from 1.0 to 0-8 because conversion of 'application-properties' failed.", e);
}
props.setHeaders(headers);
final ContentHeaderBody chb = new ContentHeaderBody(props);
chb.setBodySize(size);
MessagePublishInfo publishInfo = createMessagePublishInfo(header, addressSpace);
return new MessageMetaData(publishInfo, chb, serverMsg.getArrivalTime());
}
use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 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.MessageMetaData_1_0 in project qpid-broker-j by apache.
the class MessageFormat_1_0 method createMessage.
@Override
public Message_1_0 createMessage(final QpidByteBuffer payload, final MessageStore store, final Object connectionReference) {
List<EncodingRetainingSection<?>> dataSections = new ArrayList<>();
List<EncodingRetainingSection<?>> allSections;
try {
allSections = getSectionDecoder().parseAll(payload);
} catch (AmqpErrorException e) {
throw new AmqpErrorRuntimeException(e);
}
MessageMetaData_1_0 mmd = createMessageMetaData(allSections, dataSections);
MessageHandle<MessageMetaData_1_0> handle = store.addMessage(mmd);
for (EncodingRetainingSection<?> dataSection : dataSections) {
try (QpidByteBuffer encodedForm = dataSection.getEncodedForm()) {
handle.addContent(encodedForm);
}
dataSection.dispose();
}
final StoredMessage<MessageMetaData_1_0> storedMessage = handle.allContentAdded();
return new Message_1_0(storedMessage, connectionReference);
}
use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 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.MessageMetaData_1_0 in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_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 StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
when(storedMessage.getContentSize()).thenReturn(0);
when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
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);
return new Message_1_0(storedMessage);
}
Aggregations