use of org.apache.qpid.server.protocol.v0_8.transport.AMQBody in project qpid-broker-j by apache.
the class AMQDecoderTest method testDecodeWithManyBuffers.
public void testDecodeWithManyBuffers() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
Random random = new Random();
final byte[] payload = new byte[2048];
random.nextBytes(payload);
final AMQBody body = new ContentBody(ByteBuffer.wrap(payload));
AMQFrame frame = new AMQFrame(1, body);
TestSender sender = new TestSender();
frame.writePayload(sender);
ByteBuffer allData = combine(sender.getSentBuffers());
for (int i = 0; i < allData.remaining(); i++) {
byte[] minibuf = new byte[1];
minibuf[0] = allData.get(i);
_decoder.decodeBuffer(ByteBuffer.wrap(minibuf));
}
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
if (frames.get(0) instanceof AMQFrame) {
assertEquals(ContentBody.TYPE, ((AMQFrame) frames.get(0)).getBodyFrame().getFrameType());
ContentBody decodedBody = (ContentBody) ((AMQFrame) frames.get(0)).getBodyFrame();
byte[] bodyBytes;
try (QpidByteBuffer payloadBuffer = decodedBody.getPayload()) {
bodyBytes = new byte[payloadBuffer.remaining()];
payloadBuffer.get(bodyBytes);
}
assertTrue("Body was corrupted", Arrays.equals(payload, bodyBytes));
} else {
fail("decode was not a frame");
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQBody in project qpid-broker-j by apache.
the class ProtocolOutputConverterImpl method writeMessageDelivery.
private long writeMessageDelivery(MessageContentSource message, ContentHeaderBody contentHeaderBody, int channelId, AMQBody deliverBody) {
int bodySize = (int) message.getSize();
boolean msgCompressed = isCompressed(contentHeaderBody);
DisposableMessageContentSource modifiedContent = null;
boolean compressionSupported = _connection.isCompressionSupported();
long length;
if (msgCompressed && !compressionSupported && (modifiedContent = inflateIfPossible(message)) != null) {
BasicContentHeaderProperties modifiedProps = new BasicContentHeaderProperties(contentHeaderBody.getProperties());
modifiedProps.setEncoding((String) null);
length = writeMessageDeliveryModified(modifiedContent, channelId, deliverBody, modifiedProps);
} else if (!msgCompressed && compressionSupported && contentHeaderBody.getProperties().getEncoding() == null && bodySize > _connection.getMessageCompressionThreshold() && (modifiedContent = deflateIfPossible(message)) != null) {
BasicContentHeaderProperties modifiedProps = new BasicContentHeaderProperties(contentHeaderBody.getProperties());
modifiedProps.setEncoding(GZIP_ENCODING);
length = writeMessageDeliveryModified(modifiedContent, channelId, deliverBody, modifiedProps);
} else {
writeMessageDeliveryUnchanged(message, channelId, deliverBody, contentHeaderBody, bodySize);
length = bodySize;
}
if (modifiedContent != null) {
modifiedContent.dispose();
}
return length;
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQBody in project qpid-broker-j by apache.
the class ProtocolOutputConverterImpl method createEncodedDeliverBody.
private AMQBody createEncodedDeliverBody(AMQMessage message, boolean isRedelivered, final long deliveryTag, final AMQShortString consumerTag) {
final AMQShortString exchangeName;
final AMQShortString routingKey;
final MessagePublishInfo pb = message.getMessagePublishInfo();
exchangeName = pb.getExchange();
routingKey = pb.getRoutingKey();
return new EncodedDeliveryBody(deliveryTag, routingKey, exchangeName, consumerTag, isRedelivered);
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQBody in project qpid-broker-j by apache.
the class ProtocolOutputConverterImpl method writeMessageDeliveryModified.
private int writeMessageDeliveryModified(final MessageContentSource content, final int channelId, final AMQBody deliverBody, final BasicContentHeaderProperties modifiedProps) {
final int bodySize = (int) content.getSize();
ContentHeaderBody modifiedHeaderBody = new ContentHeaderBody(modifiedProps, bodySize);
writeMessageDeliveryUnchanged(content, channelId, deliverBody, modifiedHeaderBody, bodySize);
return bodySize;
}
use of org.apache.qpid.server.protocol.v0_8.transport.AMQBody in project qpid-broker-j by apache.
the class AMQDecoderTest method testContentHeaderPropertiesFrame.
public void testContentHeaderPropertiesFrame() throws AMQProtocolVersionException, AMQFrameDecodingException, IOException {
final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
final FieldTable table = new FieldTable();
table.setString("hello", "world");
table.setInteger("1+1=", 2);
props.setHeaders(table);
final AMQBody body = new ContentHeaderBody(props);
AMQFrame frame = new AMQFrame(1, body);
TestSender sender = new TestSender();
frame.writePayload(sender);
ByteBuffer msg = combine(sender.getSentBuffers());
_decoder.decodeBuffer(msg);
List<AMQDataBlock> frames = _methodProcessor.getProcessedMethods();
AMQDataBlock firstFrame = frames.get(0);
if (firstFrame instanceof AMQFrame) {
assertEquals(ContentHeaderBody.TYPE, ((AMQFrame) firstFrame).getBodyFrame().getFrameType());
BasicContentHeaderProperties decodedProps = ((ContentHeaderBody) ((AMQFrame) firstFrame).getBodyFrame()).getProperties();
final FieldTable headers = decodedProps.getHeaders();
assertEquals("world", headers.getString("hello"));
} else {
fail("decode was not a frame");
}
}
Aggregations