Search in sources :

Example 6 with AMQBody

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");
    }
}
Also used : AMQDataBlock(org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock) Random(java.util.Random) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) AMQBody(org.apache.qpid.server.protocol.v0_8.transport.AMQBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 7 with AMQBody

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;
}
Also used : BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)

Example 8 with AMQBody

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);
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)

Example 9 with AMQBody

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;
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)

Example 10 with AMQBody

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");
    }
}
Also used : AMQDataBlock(org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) AMQBody(org.apache.qpid.server.protocol.v0_8.transport.AMQBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Aggregations

AMQBody (org.apache.qpid.server.protocol.v0_8.transport.AMQBody)5 AMQFrame (org.apache.qpid.server.protocol.v0_8.transport.AMQFrame)4 ByteBuffer (java.nio.ByteBuffer)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 AMQDataBlock (org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock)2 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)2 Random (java.util.Random)1 ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)1