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))));
}
}
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)));
}
}
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());
}
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);
}
}
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);
}
}
Aggregations