use of org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties 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.ApplicationProperties in project qpid-broker-j by apache.
the class MessageEncoder method getPayload.
public QpidByteBuffer getPayload() {
List<QpidByteBuffer> payload = new ArrayList<>();
if (_header != null) {
payload.add(_header.createEncodingRetainingSection().getEncodedForm());
}
if (_properties != null) {
payload.add(_properties.createEncodingRetainingSection().getEncodedForm());
}
if (_applicationProperties != null) {
payload.add(new ApplicationProperties(_applicationProperties).createEncodingRetainingSection().getEncodedForm());
}
if (_data.isEmpty()) {
throw new IllegalStateException("Message should have at least one data section");
}
List<EncodingRetainingSection<?>> dataSections = new ArrayList<>();
if (_data.size() == 1) {
AmqpValue amqpValue = new AmqpValue(_data.get(0));
dataSections.add(amqpValue.createEncodingRetainingSection());
} else {
throw new UnsupportedOperationException("Unsupported yet");
}
for (EncodingRetainingSection<?> section : dataSections) {
payload.add(section.getEncodedForm());
section.dispose();
}
QpidByteBuffer combined = QpidByteBuffer.concatenate(payload);
payload.forEach(QpidByteBuffer::dispose);
return combined;
}
use of org.apache.qpid.amqp_1_0.type.messaging.ApplicationProperties 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.amqp_1_0.type.messaging.ApplicationProperties 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.amqp_1_0.type.messaging.ApplicationProperties in project qpid-broker-j by apache.
the class PropertyConverter_1_0_to_0_8Test method testApplicationPropertiesConversionWithUuid.
public void testApplicationPropertiesConversionWithUuid() {
Map<String, Object> properties = new HashMap<>();
final String key = "uuidProperty";
properties.put(key, UUID.randomUUID());
ApplicationProperties applicationProperties = new ApplicationProperties(properties);
Message_1_0 message = createTestMessage(applicationProperties);
final AMQMessage convertedMessage = _messageConverter.convert(message, _namedAddressSpace);
BasicContentHeaderProperties convertedProperties = convertedMessage.getContentHeaderBody().getProperties();
final Map<String, Object> headers = FieldTable.convertToMap(convertedProperties.getHeaders());
assertEquals("Unexpected headers size", properties.size(), headers.size());
assertEquals("Unexpected headers", properties.get(key), UUID.fromString((String) headers.get(key)));
}
Aggregations