use of org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl in project qpid-broker-j by apache.
the class MessageConverter_0_10_to_1_0Test method getEncodingRetainingSections.
private List<EncodingRetainingSection<?>> getEncodingRetainingSections(final QpidByteBuffer content, final int expectedNumberOfSections) throws Exception {
SectionDecoder sectionDecoder = new SectionDecoderImpl(_typeRegistry.getSectionDecoderRegistry());
final List<EncodingRetainingSection<?>> sections = sectionDecoder.parseAll(content);
assertEquals("Unexpected number of sections", expectedNumberOfSections, sections.size());
return sections;
}
use of org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl in project qpid-broker-j by apache.
the class MessageConverter_0_8_to_1_0Test method getEncodingRetainingSections.
private List<EncodingRetainingSection<?>> getEncodingRetainingSections(final QpidByteBuffer content, final int expectedNumberOfSections) throws Exception {
SectionDecoder sectionDecoder = new SectionDecoderImpl(_typeRegistry.getSectionDecoderRegistry());
final List<EncodingRetainingSection<?>> sections = sectionDecoder.parseAll(content);
assertEquals("Unexpected number of sections", expectedNumberOfSections, sections.size());
return sections;
}
use of org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl in project qpid-broker-j by apache.
the class ConsumerTarget_1_0Test method testTTLAdjustedOnSend.
public void testTTLAdjustedOnSend() throws Exception {
final MessageInstanceConsumer comsumer = mock(MessageInstanceConsumer.class);
long ttl = 2000L;
long arrivalTime = System.currentTimeMillis() - 1000L;
final Header header = new Header();
header.setTtl(UnsignedInteger.valueOf(ttl));
final Message_1_0 message = createTestMessage(header, arrivalTime);
final MessageInstance messageInstance = mock(MessageInstance.class);
when(messageInstance.getMessage()).thenReturn(message);
AtomicReference<QpidByteBuffer> payloadRef = new AtomicReference<>();
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
Transfer transfer = (Transfer) args[0];
QpidByteBuffer transferPayload = transfer.getPayload();
QpidByteBuffer payloadCopy = transferPayload.duplicate();
payloadRef.set(payloadCopy);
return null;
}).when(_sendingLinkEndpoint).transfer(any(Transfer.class), anyBoolean());
_consumerTarget.doSend(comsumer, messageInstance, false);
verify(_sendingLinkEndpoint, times(1)).transfer(any(Transfer.class), anyBoolean());
final List<EncodingRetainingSection<?>> sections;
try (QpidByteBuffer payload = payloadRef.get()) {
sections = new SectionDecoderImpl(_describedTypeRegistry.getSectionDecoderRegistry()).parseAll(payload);
}
Header sentHeader = null;
for (EncodingRetainingSection<?> section : sections) {
if (section instanceof HeaderSection) {
sentHeader = ((HeaderSection) section).getValue();
}
}
assertNotNull("Header is not found", sentHeader);
assertNotNull("Ttl is not set", sentHeader.getTtl());
assertTrue("Unexpected ttl", sentHeader.getTtl().longValue() <= 1000);
}
use of org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl in project qpid-broker-j by apache.
the class MessageConverter_Internal_to_1_0Test method getEncodingRetainingSections.
private List<EncodingRetainingSection<?>> getEncodingRetainingSections(final QpidByteBuffer content, final int expectedNumberOfSections) throws Exception {
SectionDecoder sectionDecoder = new SectionDecoderImpl(_typeRegistry.getSectionDecoderRegistry());
final List<EncodingRetainingSection<?>> sections = sectionDecoder.parseAll(content);
assertEquals("Unexpected number of sections", expectedNumberOfSections, sections.size());
return sections;
}
use of org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl 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;
}
Aggregations