use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody in project qpid-broker-j by apache.
the class LargeMessageTest method multiBodyMessage.
@Test
public void multiBodyMessage() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
String consumerTag = "A";
String queueName = "testQueue";
ConnectionTuneBody connTune = interaction.authenticateConnection().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.ConnectionTuneBody in project qpid-broker-j by apache.
the class ConnectionTest method connectionSecureWithChallengeResponse.
@Test
@SpecificationTest(section = "1.4.2.3", description = "security challenge data")
public void connectionSecureWithChallengeResponse() throws Exception {
assumeThat(getBrokerAdmin().isSASLMechanismSupported(CRAM_MD5), is(true));
try (FrameTransport transport = new FrameTransport(getBrokerAdmin(), BrokerAdmin.PortType.AMQP).connect()) {
final Interaction interaction = transport.newInteraction();
final ConnectionStartBody start = interaction.negotiateProtocol().consumeResponse().getLatestResponse(ConnectionStartBody.class);
assertThat(Arrays.asList(new String(start.getMechanisms()).split(" ")), hasItem(CRAM_MD5));
final ConnectionSecureBody secure = interaction.connection().startOkMechanism(CRAM_MD5).startOk().consumeResponse().getLatestResponse(ConnectionSecureBody.class);
byte[] response = generateCramMD5ClientResponse(getBrokerAdmin().getValidUsername(), getBrokerAdmin().getValidPassword(), secure.getChallenge());
final ConnectionTuneBody tune = interaction.connection().secureOk(response).consumeResponse().getLatestResponse(ConnectionTuneBody.class);
interaction.connection().tuneOkChannelMax(tune.getChannelMax()).tuneOkFrameMax(tune.getFrameMax()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class);
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody 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(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
String consumerTag = "A";
ConnectionTuneBody connTune = interaction.authenticateConnection().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<>(properties.getHeadersAsMap());
assertThat(receivedHeaders, is(equalTo(new HashMap<>(messageHeaders))));
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody in project qpid-broker-j by apache.
the class ConnectionTest method overlySizedContentBodyFrame.
@Test
@SpecificationTest(section = "4.2.3", description = "A peer MUST NOT send frames larger than the agreed-upon size. A peer that receives an " + "oversized frame MUST signal a connection exception with reply code 501 (frame error).")
public void overlySizedContentBodyFrame() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
final long frameMax = response.getFrameMax();
// Older Qpid JMS Client 0-x had a defect that meant they could send content body frames that were too
// large. Rather then limiting the user content of each frame to frameSize - 8, it sent frameSize bytes
// of user content meaning the resultant frame was too big. The server accommodates this behaviour
// by reducing the frame-size advertised to the client.
// Should be frameMax - 8 + 1.
final int overlyLargeFrameBodySize = (int) (frameMax + 1);
final byte[] bodyBytes = new byte[overlyLargeFrameBodySize];
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(frameMax).tuneOkHeartbeat(response.getHeartbeat()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).basic().publish().basic().contentHeader(bodyBytes.length).basic().contentBody(bodyBytes);
// Server actually abruptly closes the connection. We might see a graceful TCP/IP close or a broken pipe.
try {
interaction.consumeResponse().getLatestResponse(ChannelClosedResponse.class);
} catch (ExecutionException e) {
Throwable original = e.getCause();
if (original instanceof IOException) {
// PASS
} else {
throw new RuntimeException(original);
}
}
}
}
use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody in project qpid-broker-j by apache.
the class ConnectionTest method connectionTuneOkAndOpen.
@Test
@SpecificationTest(section = "1.4.2.6", description = "negotiate connection tuning parameters")
public void connectionTuneOkAndOpen() throws Exception {
try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
final Interaction interaction = transport.newInteraction();
ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(response.getFrameMax()).tuneOkHeartbeat(response.getHeartbeat()).tuneOk().connection().open().consumeResponse().getLatestResponse(ConnectionOpenOkBody.class);
}
}
Aggregations