use of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue 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.AmqpValue in project qpid-broker-j by apache.
the class MessageConverter_v1_0_to_InternalTest method testAmqpValueWithNullWithObjectMessageAnnotation.
public void testAmqpValueWithNullWithObjectMessageAnnotation() throws Exception {
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
Message_1_0 sourceMessage = createTestMessage(OBJECT_MESSAGE_MESSAGE_ANNOTATION, amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "application/x-java-serialized-object", convertedMessage.getMessageHeader().getMimeType());
assertNull("Unexpected content", convertedMessage.getMessageBody());
}
use of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue in project qpid-broker-j by apache.
the class MessageConverter_v1_0_to_InternalTest method testAmqpValueWithNull.
public void testAmqpValueWithNull() throws Exception {
final Object expected = null;
final AmqpValue amqpValue = new AmqpValue(expected);
Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", null, convertedMessage.getMessageHeader().getMimeType());
assertNull("Unexpected content", convertedMessage.getMessageBody());
}
use of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue in project qpid-broker-j by apache.
the class MessageConverter_v1_0_to_InternalTest method testAmqpValueWithString.
public void testAmqpValueWithString() throws Exception {
final String expected = "testContent";
final AmqpValue amqpValue = new AmqpValue(expected);
Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "text/plain", convertedMessage.getMessageHeader().getMimeType());
assertEquals("Unexpected content", expected, convertedMessage.getMessageBody());
}
use of org.apache.qpid.amqp_1_0.type.messaging.AmqpValue in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testAmqpValueWithMapContainingNonFieldTableCompliantEntries.
public void testAmqpValueWithMapContainingNonFieldTableCompliantEntries() throws Exception {
final AmqpValue amqpValue = new AmqpValue(Collections.<Object, Object>singletonMap(13, 42));
Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
try {
_converter.convert(sourceMessage, mock(NamedAddressSpace.class));
fail("expected exception not thrown.");
} catch (MessageConversionException e) {
// pass
}
}
Aggregations