Search in sources :

Example 1 with DeliveryAnnotationsSection

use of org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection in project qpid-broker-j by apache.

the class ConsumerTarget_1_0Test method createTestMessage.

private Message_1_0 createTestMessage(final Header header, long arrivalTime) {
    DeliveryAnnotationsSection deliveryAnnotations = new DeliveryAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
    MessageAnnotationsSection messageAnnotations = new MessageAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
    ApplicationPropertiesSection applicationProperties = new ApplicationProperties(Collections.emptyMap()).createEncodingRetainingSection();
    FooterSection footer = new Footer(Collections.emptyMap()).createEncodingRetainingSection();
    MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations, messageAnnotations, new Properties().createEncodingRetainingSection(), applicationProperties, footer, arrivalTime, 0);
    final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
    when(storedMessage.getContent(eq(0), anyInt())).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
    when(storedMessage.getMetaData()).thenReturn(metaData);
    return new Message_1_0(storedMessage);
}
Also used : DeliveryAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection) FooterSection(org.apache.qpid.server.protocol.v1_0.type.messaging.FooterSection) MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) DeliveryAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations) Footer(org.apache.qpid.server.protocol.v1_0.type.messaging.Footer) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) MessageAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection) ApplicationPropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationPropertiesSection) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 2 with DeliveryAnnotationsSection

use of org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection in project qpid-broker-j by apache.

the class DecodeErrorTest method buildInvalidMessage.

private QpidByteBuffer buildInvalidMessage() {
    final List<QpidByteBuffer> payloads = new ArrayList<>();
    try {
        final Header header = new Header();
        header.setTtl(UnsignedInteger.valueOf(10000L));
        final HeaderSection headerSection = header.createEncodingRetainingSection();
        try {
            payloads.add(headerSection.getEncodedForm());
        } finally {
            headerSection.dispose();
        }
        final StringWriter stringWriter = new StringWriter("string in between message sections");
        final QpidByteBuffer encodedString = QpidByteBuffer.allocate(stringWriter.getEncodedSize());
        stringWriter.writeToBuffer(encodedString);
        encodedString.flip();
        payloads.add(encodedString);
        final Map<Symbol, Object> annotationMap = Collections.singletonMap(Symbol.valueOf("foo"), "bar");
        final DeliveryAnnotations annotations = new DeliveryAnnotations(annotationMap);
        final DeliveryAnnotationsSection deliveryAnnotationsSection = annotations.createEncodingRetainingSection();
        try {
            payloads.add(deliveryAnnotationsSection.getEncodedForm());
        } finally {
            deliveryAnnotationsSection.dispose();
        }
        final AmqpValueSection payload = new AmqpValue(getTestName()).createEncodingRetainingSection();
        try {
            payloads.add(payload.getEncodedForm());
        } finally {
            payload.dispose();
        }
        return QpidByteBuffer.concatenate(payloads);
    } finally {
        payloads.forEach(QpidByteBuffer::dispose);
    }
}
Also used : DeliveryAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) 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) AmqpValue(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) StringWriter(org.apache.qpid.server.protocol.v1_0.codec.StringWriter) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpValueSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)

Example 3 with DeliveryAnnotationsSection

use of org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection 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)

Example 4 with DeliveryAnnotationsSection

use of org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection in project qpid-broker-j by apache.

the class MessageDecoder method parse.

public void parse() throws AmqpErrorException {
    if (!_parsed) {
        List<EncodingRetainingSection<?>> sections;
        try (QpidByteBuffer combined = QpidByteBuffer.concatenate(_fragments)) {
            sections = _sectionDecoder.parseAll(combined);
        }
        _fragments.forEach(QpidByteBuffer::dispose);
        Iterator<EncodingRetainingSection<?>> iter = sections.iterator();
        EncodingRetainingSection<?> s = iter.hasNext() ? iter.next() : null;
        if (s instanceof HeaderSection) {
            _headerSection = (HeaderSection) s;
            s = iter.hasNext() ? iter.next() : null;
        }
        if (s instanceof DeliveryAnnotationsSection) {
            _deliveryAnnotationsSection = (DeliveryAnnotationsSection) s;
            s = iter.hasNext() ? iter.next() : null;
        }
        if (s instanceof MessageAnnotationsSection) {
            _messageAnnotationsSection = (MessageAnnotationsSection) s;
            s = iter.hasNext() ? iter.next() : null;
        }
        if (s instanceof PropertiesSection) {
            _propertiesSection = (PropertiesSection) s;
            s = iter.hasNext() ? iter.next() : null;
        }
        if (s instanceof ApplicationPropertiesSection) {
            _applicationPropertiesSection = (ApplicationPropertiesSection) s;
            s = iter.hasNext() ? iter.next() : null;
        }
        if (s instanceof AmqpValueSection) {
            _contentSize = s.getEncodedSize();
            _dataSections.add(s);
            s = iter.hasNext() ? iter.next() : null;
        } else if (s instanceof DataSection) {
            do {
                _contentSize += s.getEncodedSize();
                _dataSections.add(s);
                s = iter.hasNext() ? iter.next() : null;
            } while (s instanceof DataSection);
        } else if (s instanceof AmqpSequenceSection) {
            do {
                _contentSize += s.getEncodedSize();
                _dataSections.add(s);
                s = iter.hasNext() ? iter.next() : null;
            } while (s instanceof AmqpSequenceSection);
        }
        if (s instanceof FooterSection) {
            _footerSection = (FooterSection) s;
            s = iter.hasNext() ? iter.next() : null;
        }
        if (s != null) {
            throw new IllegalStateException(String.format("Encountered unexpected section '%s'", s.getClass().getSimpleName()));
        }
        _parsed = true;
    }
}
Also used : PropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.PropertiesSection) ApplicationPropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationPropertiesSection) DeliveryAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection) EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) MessageAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection) ApplicationPropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationPropertiesSection) AmqpSequenceSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection) HeaderSection(org.apache.qpid.server.protocol.v1_0.type.messaging.HeaderSection) FooterSection(org.apache.qpid.server.protocol.v1_0.type.messaging.FooterSection) DataSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpValueSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)

Example 5 with DeliveryAnnotationsSection

use of org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection in project qpid-broker-j by apache.

the class MessageFormat_1_0 method createMessageMetaData.

private MessageMetaData_1_0 createMessageMetaData(final List<EncodingRetainingSection<?>> allSections, final List<EncodingRetainingSection<?>> dataSections) {
    long contentSize = 0L;
    HeaderSection headerSection = null;
    PropertiesSection propertiesSection = null;
    DeliveryAnnotationsSection deliveryAnnotationsSection = null;
    MessageAnnotationsSection messageAnnotationsSection = null;
    ApplicationPropertiesSection applicationPropertiesSection = null;
    FooterSection footerSection = null;
    Iterator<EncodingRetainingSection<?>> iter = allSections.iterator();
    EncodingRetainingSection<?> s = iter.hasNext() ? iter.next() : null;
    if (s instanceof HeaderSection) {
        headerSection = (HeaderSection) s;
        s = iter.hasNext() ? iter.next() : null;
    }
    if (s instanceof DeliveryAnnotationsSection) {
        deliveryAnnotationsSection = (DeliveryAnnotationsSection) s;
        s = iter.hasNext() ? iter.next() : null;
    }
    if (s instanceof MessageAnnotationsSection) {
        messageAnnotationsSection = (MessageAnnotationsSection) s;
        s = iter.hasNext() ? iter.next() : null;
    }
    if (s instanceof PropertiesSection) {
        propertiesSection = (PropertiesSection) s;
        s = iter.hasNext() ? iter.next() : null;
    }
    if (s instanceof ApplicationPropertiesSection) {
        applicationPropertiesSection = (ApplicationPropertiesSection) s;
        s = iter.hasNext() ? iter.next() : null;
    }
    if (s instanceof AmqpValueSection) {
        contentSize = s.getEncodedSize();
        dataSections.add(s);
        s = iter.hasNext() ? iter.next() : null;
    } else if (s instanceof DataSection) {
        do {
            contentSize += s.getEncodedSize();
            dataSections.add(s);
            s = iter.hasNext() ? iter.next() : null;
        } while (s instanceof DataSection);
    } else if (s instanceof AmqpSequenceSection) {
        do {
            contentSize += s.getEncodedSize();
            dataSections.add(s);
            s = iter.hasNext() ? iter.next() : null;
        } while (s instanceof AmqpSequenceSection);
    }
    if (s instanceof FooterSection) {
        footerSection = (FooterSection) s;
        s = iter.hasNext() ? iter.next() : null;
    }
    if (s != null) {
        throw new ConnectionScopedRuntimeException(String.format("Encountered unexpected section '%s'", s.getClass().getSimpleName()));
    }
    return new MessageMetaData_1_0(headerSection, deliveryAnnotationsSection, messageAnnotationsSection, propertiesSection, applicationPropertiesSection, footerSection, System.currentTimeMillis(), contentSize);
}
Also used : PropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.PropertiesSection) ApplicationPropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationPropertiesSection) DeliveryAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection) EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) MessageAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection) ApplicationPropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationPropertiesSection) AmqpSequenceSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection) HeaderSection(org.apache.qpid.server.protocol.v1_0.type.messaging.HeaderSection) FooterSection(org.apache.qpid.server.protocol.v1_0.type.messaging.FooterSection) DataSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) AmqpValueSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)

Aggregations

DeliveryAnnotationsSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection)6 HeaderSection (org.apache.qpid.server.protocol.v1_0.type.messaging.HeaderSection)5 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)4 ApplicationPropertiesSection (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationPropertiesSection)4 DeliveryAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations)4 FooterSection (org.apache.qpid.server.protocol.v1_0.type.messaging.FooterSection)4 MessageAnnotationsSection (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection)4 AmqpValueSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)3 PropertiesSection (org.apache.qpid.server.protocol.v1_0.type.messaging.PropertiesSection)3 ArrayList (java.util.ArrayList)2 StringWriter (org.apache.qpid.server.protocol.v1_0.codec.StringWriter)2 AmqpSequenceSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection)2 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)2 DataSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection)2 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)2 Footer (org.apache.qpid.server.protocol.v1_0.type.messaging.Footer)2 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)2 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)2 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)1 AmqpValue (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValue)1