use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.
the class MessageConverter_v1_0_to_InternalTest method doTestDataWithAnnotation.
private void doTestDataWithAnnotation(final byte[] data, final MessageAnnotations messageAnnotations, final String mimeType, final String expectedMimeType) {
final Data value = new Data(new Binary(data));
Message_1_0 sourceMessage;
if (mimeType != null) {
Properties properties = new Properties();
properties.setContentType(Symbol.valueOf(mimeType));
sourceMessage = createTestMessage(properties, messageAnnotations, value.createEncodingRetainingSection());
} else {
sourceMessage = createTestMessage(messageAnnotations, value.createEncodingRetainingSection());
}
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", expectedMimeType, convertedMessage.getMessageHeader().getMimeType());
assertArrayEquals("Unexpected content", data, ((byte[]) convertedMessage.getMessageBody()));
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project storm by apache.
the class EventHubReceiverMock method receive.
@Override
public EventData receive(long timeoutInMilliseconds) {
if (isPaused) {
return null;
}
currentOffset++;
List<Section> body = new ArrayList<Section>();
//the body of the message is "message" + currentOffset, e.g. "message123"
body.add(new Data(new Binary(("message" + currentOffset).getBytes())));
Message m = new Message(body);
MessageId mid = new MessageId(partitionId, "" + currentOffset, currentOffset);
EventData ed = new EventData(m, mid);
return ed;
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testDataWithContentTypeAmqpList.
public void testDataWithContentTypeAmqpList() throws Exception {
List<Object> originalMap = Collections.singletonList("testValue");
byte[] bytes = new ListToAmqpListConverter().toMimeContent(originalMap);
final Data value = new Data(new Binary(bytes));
Properties properties = new Properties();
properties.setContentType(Symbol.valueOf("amqp/list"));
Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "amqp/list", convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertArrayEquals("Unexpected content", bytes, getBytes(content));
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.
the class MessageConverter_from_1_0 method convertBodyToObject.
static Object convertBodyToObject(final Message_1_0 serverMessage) {
SectionDecoderImpl sectionDecoder = new SectionDecoderImpl(MessageConverter_v1_0_to_Internal.TYPE_REGISTRY.getSectionDecoderRegistry());
Object bodyObject = null;
List<EncodingRetainingSection<?>> sections = null;
try {
try (QpidByteBuffer allData = serverMessage.getContent()) {
sections = sectionDecoder.parseAll(allData);
}
List<EncodingRetainingSection<?>> bodySections = new ArrayList<>(sections.size());
ListIterator<EncodingRetainingSection<?>> iterator = sections.listIterator();
EncodingRetainingSection<?> previousSection = null;
while (iterator.hasNext()) {
EncodingRetainingSection<?> section = iterator.next();
if (section instanceof AmqpValueSection || section instanceof DataSection || section instanceof AmqpSequenceSection) {
if (previousSection != null && (previousSection.getClass() != section.getClass() || section instanceof AmqpValueSection)) {
throw new MessageConversionException("Message is badly formed and has multiple body section which are not all Data or not all AmqpSequence");
} else {
previousSection = section;
}
bodySections.add(section);
}
}
// In 1.0 of the spec, it is illegal to have message with no body but AMQP-127 asks to have that restriction lifted
if (!bodySections.isEmpty()) {
EncodingRetainingSection<?> firstBodySection = bodySections.get(0);
if (firstBodySection instanceof AmqpValueSection) {
bodyObject = convertValue(firstBodySection.getValue());
} else if (firstBodySection instanceof DataSection) {
int totalSize = 0;
for (EncodingRetainingSection<?> section : bodySections) {
totalSize += ((DataSection) section).getValue().getArray().length;
}
byte[] bodyData = new byte[totalSize];
ByteBuffer buf = ByteBuffer.wrap(bodyData);
for (EncodingRetainingSection<?> section : bodySections) {
buf.put(((DataSection) section).getValue().asByteBuffer());
}
bodyObject = bodyData;
} else {
ArrayList<Object> totalSequence = new ArrayList<>();
for (EncodingRetainingSection<?> section : bodySections) {
totalSequence.addAll(((AmqpSequenceSection) section).getValue());
}
bodyObject = convertValue(totalSequence);
}
}
} catch (AmqpErrorException e) {
throw new ConnectionScopedRuntimeException(e);
} finally {
if (sections != null) {
sections.forEach(EncodingRetaining::dispose);
}
}
return bodyObject;
}
use of org.apache.qpid.server.protocol.v1_0.type.messaging.Data in project qpid-broker-j by apache.
the class MessageConverter_v1_0_to_InternalTest method testData.
public void testData() throws Exception {
final byte[] expected = getObjectBytes("helloworld".getBytes(UTF_8));
final Data value = new Data(new Binary(expected));
final Message_1_0 sourceMessage = createTestMessage(value.createEncodingRetainingSection());
final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "application/octet-stream", convertedMessage.getMessageHeader().getMimeType());
assertArrayEquals("Unexpected content", expected, ((byte[]) convertedMessage.getMessageBody()));
}
Aggregations