Search in sources :

Example 1 with StringWriter

use of org.apache.qpid.server.protocol.v1_0.codec.StringWriter in project qpid-broker-j by apache.

the class DecodeErrorTest method illegalMessageFormatPayload.

@Test
@SpecificationTest(section = "3.2", description = "Altogether a message consists of the following sections: Zero or one header," + " Zero or one delivery-annotations, [...]")
public void illegalMessageFormatPayload() throws Exception {
    try (FrameTransport transport = new FrameTransport(_brokerAddress).connect()) {
        List<QpidByteBuffer> payloads = new ArrayList<>();
        final HeaderSection headerSection = new Header().createEncodingRetainingSection();
        payloads.add(headerSection.getEncodedForm());
        headerSection.dispose();
        final StringWriter stringWriter = new StringWriter("string in between annotation sections");
        QpidByteBuffer encodedString = QpidByteBuffer.allocate(stringWriter.getEncodedSize());
        stringWriter.writeToBuffer(encodedString);
        encodedString.flip();
        payloads.add(encodedString);
        final DeliveryAnnotationsSection deliveryAnnotationsSection = new DeliveryAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
        payloads.add(deliveryAnnotationsSection.getEncodedForm());
        deliveryAnnotationsSection.dispose();
        final Detach detachResponse;
        try (QpidByteBuffer combinedPayload = QpidByteBuffer.concatenate(payloads)) {
            detachResponse = transport.newInteraction().negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.SENDER).attachTargetAddress(BrokerAdmin.TEST_QUEUE_NAME).attach().consumeResponse(Attach.class).consumeResponse(Flow.class).transferMessageFormat(UnsignedInteger.ZERO).transferPayload(combinedPayload).transfer().consumeResponse().getLatestResponse(Detach.class);
        }
        payloads.forEach(QpidByteBuffer::dispose);
        assertThat(detachResponse.getError(), is(notNullValue()));
        assertThat(detachResponse.getError().getCondition(), is(equalTo(DECODE_ERROR)));
    }
}
Also used : DeliveryAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) ArrayList(java.util.ArrayList) DeliveryAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations) HeaderSection(org.apache.qpid.server.protocol.v1_0.type.messaging.HeaderSection) Open(org.apache.qpid.server.protocol.v1_0.type.transport.Open) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) StringWriter(org.apache.qpid.server.protocol.v1_0.codec.StringWriter) Begin(org.apache.qpid.server.protocol.v1_0.type.transport.Begin) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

ArrayList (java.util.ArrayList)1 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 StringWriter (org.apache.qpid.server.protocol.v1_0.codec.StringWriter)1 DeliveryAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations)1 DeliveryAnnotationsSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection)1 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)1 HeaderSection (org.apache.qpid.server.protocol.v1_0.type.messaging.HeaderSection)1 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)1 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)1 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)1 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)1 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)1 Test (org.junit.Test)1