Search in sources :

Example 6 with ContentHeaderBody

use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody in project qpid-broker-j by apache.

the class LargeHeadersTest method headersFillContentHeaderFrame.

@Test
public /**
 * Tests boundary case where headers exactly fill the content header frame
 */
void headersFillContentHeaderFrame() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        String consumerTag = "A";
        ConnectionTuneBody connTune = interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().startOkMechanism("ANONYMOUS").startOk().consumeResponse(ConnectionTuneBody.class).getLatestResponse(ConnectionTuneBody.class);
        final String headerName = "test";
        final int headerValueSize = (int) (connTune.getFrameMax() - calculateContentHeaderFramingOverhead(headerName));
        final String headerValue = generateLongString(headerValueSize);
        final Map<String, Object> messageHeaders = Collections.singletonMap(headerName, headerValue);
        interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(BrokerAdmin.TEST_QUEUE_NAME).consumeNoAck(true).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().contentHeaderPropertiesHeaders(messageHeaders).publishExchange("").publishRoutingKey(BrokerAdmin.TEST_QUEUE_NAME).publishMessage().consumeResponse(BasicDeliverBody.class);
        BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
        assertThat(delivery.getConsumerTag(), is(equalTo(AMQShortString.valueOf(consumerTag))));
        ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
        assertThat(header.getBodySize(), is(equalTo(0L)));
        BasicContentHeaderProperties properties = header.getProperties();
        Map<String, Object> receivedHeaders = new HashMap<>(FieldTable.convertToMap(properties.getHeaders()));
        assertThat(receivedHeaders, is(equalTo(new HashMap<>(messageHeaders))));
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) HashMap(java.util.HashMap) ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) BasicQosOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) ChannelOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody) Test(org.junit.Test)

Example 7 with ContentHeaderBody

use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody in project qpid-broker-j by apache.

the class LargeMessageTest method multiBodyMessage.

@Test
public void multiBodyMessage() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        final Interaction interaction = transport.newInteraction();
        String consumerTag = "A";
        String queueName = "testQueue";
        ConnectionTuneBody connTune = interaction.negotiateProtocol().consumeResponse(ConnectionStartBody.class).connection().startOkMechanism("ANONYMOUS").startOk().consumeResponse(ConnectionTuneBody.class).getLatestResponse(ConnectionTuneBody.class);
        byte[] messageContent = new byte[(int) connTune.getFrameMax()];
        IntStream.range(0, messageContent.length).forEach(i -> {
            messageContent[i] = (byte) (i & 0xFF);
        });
        interaction.connection().tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().qosPrefetchCount(1).qos().consumeResponse(BasicQosOkBody.class).basic().consumeConsumerTag(consumerTag).consumeQueue(queueName).consumeNoAck(true).consume().consumeResponse(BasicConsumeOkBody.class).channel().flow(true).consumeResponse(ChannelFlowOkBody.class).basic().publishExchange("").publishRoutingKey(queueName).content(messageContent).publishMessage().consumeResponse(BasicDeliverBody.class);
        BasicDeliverBody delivery = interaction.getLatestResponse(BasicDeliverBody.class);
        assertThat(delivery.getConsumerTag(), is(equalTo(AMQShortString.valueOf(consumerTag))));
        ContentHeaderBody header = interaction.consumeResponse(ContentHeaderBody.class).getLatestResponse(ContentHeaderBody.class);
        assertThat(header.getBodySize(), is(equalTo((long) messageContent.length)));
        byte[] receivedContent = new byte[messageContent.length];
        ContentBody content1 = interaction.consumeResponse(ContentBody.class).getLatestResponse(ContentBody.class);
        ContentBody content2 = interaction.consumeResponse(ContentBody.class).getLatestResponse(ContentBody.class);
        try (QpidByteBuffer allContent = QpidByteBuffer.concatenate(content1.getPayload(), content2.getPayload())) {
            allContent.get(receivedContent);
        }
        assertThat(receivedContent, is(equalTo(messageContent)));
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) ConnectionStartBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody) BasicConsumeOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) ContentBody(org.apache.qpid.server.protocol.v0_8.transport.ContentBody) BasicQosOkBody(org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) BasicDeliverBody(org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody) ChannelOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody) Test(org.junit.Test)

Example 8 with ContentHeaderBody

use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_v0_8 method convertMetaData.

private MessageMetaData convertMetaData(final InternalMessage serverMsg, final NamedAddressSpace addressSpace, final String bodyMimeType, final int size) {
    MessagePublishInfo publishInfo = createMessagePublishInfo(serverMsg, addressSpace);
    final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    props.setAppId(serverMsg.getMessageHeader().getAppId());
    props.setContentType(bodyMimeType);
    props.setCorrelationId(convertToShortStringForProperty("correlation-id", serverMsg.getMessageHeader().getCorrelationId()));
    props.setDeliveryMode(serverMsg.isPersistent() ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT);
    props.setExpiration(serverMsg.getExpiration());
    props.setMessageId(convertToOptionalAMQPShortString(serverMsg.getMessageHeader().getMessageId()));
    props.setPriority(serverMsg.getMessageHeader().getPriority());
    props.setReplyTo(convertToShortStringForProperty("reply-to", getReplyTo(serverMsg, addressSpace)));
    props.setTimestamp(serverMsg.getMessageHeader().getTimestamp());
    props.setUserId(convertToOptionalAMQPShortString(serverMsg.getMessageHeader().getUserId()));
    props.setEncoding(convertToShortStringForProperty("encoding", serverMsg.getMessageHeader().getEncoding()));
    Map<String, Object> headerProps = new LinkedHashMap<String, Object>();
    for (String headerName : serverMsg.getMessageHeader().getHeaderNames()) {
        headerProps.put(headerName, serverMsg.getMessageHeader().getHeader(headerName));
    }
    try {
        props.setHeaders(FieldTable.convertToFieldTable(headerProps));
    } catch (IllegalArgumentException | AMQPInvalidClassException e) {
        throw new MessageConversionException("Could not convert message from internal to 0-8 because headers conversion failed.", e);
    }
    final ContentHeaderBody chb = new ContentHeaderBody(props);
    chb.setBodySize(size);
    return new MessageMetaData(publishInfo, chb, serverMsg.getArrivalTime());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with ContentHeaderBody

use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody in project qpid-broker-j by apache.

the class MessageFormat_0_9_1 method createMessage.

@Override
public AMQMessage createMessage(final QpidByteBuffer payload, final MessageStore store, final Object connectionReference) {
    try {
        AMQShortString exchange = readShortString(payload);
        AMQShortString routingKey = readShortString(payload);
        byte flags = payload.get();
        final MessagePublishInfo publishBody = new MessagePublishInfo(exchange, (flags & IMMEDIATE_MASK) != 0, (flags & MANDATORY_MASK) != 0, routingKey);
        final ContentHeaderBody contentHeaderBody = readContentBody(payload);
        MessageMetaData mmd = new MessageMetaData(publishBody, contentHeaderBody);
        final MessageHandle<MessageMetaData> handle = store.addMessage(mmd);
        handle.addContent(payload);
        final StoredMessage<MessageMetaData> storedMessage = handle.allContentAdded();
        return new AMQMessage(storedMessage, connectionReference);
    } catch (AMQFrameDecodingException | BufferUnderflowException e) {
        throw new ConnectionScopedRuntimeException("Error parsing AMQP 0-9-1 message format", e);
    }
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 10 with ContentHeaderBody

use of org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody in project qpid-broker-j by apache.

the class MessageFormat_0_9_1 method readContentBody.

private ContentHeaderBody readContentBody(final QpidByteBuffer buf) throws AMQFrameDecodingException {
    long size = buf.getUnsignedInt();
    try (QpidByteBuffer buffer = readByteBuffer(buf, size)) {
        final long newPosition = buf.position() + size;
        if (newPosition > Integer.MAX_VALUE) {
            throw new IllegalStateException(String.format("trying to advance QBB to %d which is larger than MAX_INT", newPosition));
        }
        buf.position((int) newPosition);
        return new ContentHeaderBody(buffer, size);
    }
}
Also used : ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Aggregations

ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)23 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)13 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)11 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)6 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 ContentBody (org.apache.qpid.server.protocol.v0_8.transport.ContentBody)5 Test (org.junit.Test)5 MessageMetaData (org.apache.qpid.server.protocol.v0_8.MessageMetaData)4 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)4 BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)4 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)4 HashMap (java.util.HashMap)3 AMQBody (org.apache.qpid.server.protocol.v0_8.transport.AMQBody)3 AMQFrame (org.apache.qpid.server.protocol.v0_8.transport.AMQFrame)3 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)3 LinkedHashMap (java.util.LinkedHashMap)2 MessageReference (org.apache.qpid.server.message.MessageReference)2 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)2 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)2 BasicQosOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody)2