Search in sources :

Example 1 with AmqpSequence

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

the class MessageConverter_1_0_to_v0_10Test method testAmqpSequenceWithUnsupportedType.

@Test
public void testAmqpSequenceWithUnsupportedType() throws Exception {
    final List<Object> originalList = Collections.singletonList(new Source());
    final AmqpSequence amqpSequence = new AmqpSequence(originalList);
    Message_1_0 sourceMessage = createTestMessage(amqpSequence.createEncodingRetainingSection());
    try {
        _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
        fail("expected exception not thrown.");
    } catch (MessageConversionException e) {
    // pass
    }
}
Also used : MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) AmqpSequence(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequence) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) Test(org.junit.Test)

Example 2 with AmqpSequence

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

the class MessageConverter_1_0_to_v0_10Test method testAmqpSequenceWithMap.

@Test
public void testAmqpSequenceWithMap() throws Exception {
    final List<Object> originalList = Collections.singletonList(Collections.singletonMap("testKey", "testValue"));
    final AmqpSequence amqpSequence = new AmqpSequence(originalList);
    Message_1_0 sourceMessage = createTestMessage(amqpSequence.createEncodingRetainingSection());
    final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "amqp/list", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    List<Object> convertedList = new AmqpListToListConverter().toObject(getBytes(content));
    assertEquals("Unexpected size", (long) originalList.size(), (long) convertedList.size());
    assertEquals("Unexpected map item", new HashMap<String, Object>((Map) originalList.get(0)), new HashMap<String, Object>((Map) convertedList.get(0)));
}
Also used : MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpListToListConverter(org.apache.qpid.server.protocol.v0_10.transport.mimecontentconverter.AmqpListToListConverter) AmqpSequence(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequence) JmsMapMessageToMap(org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with AmqpSequence

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

the class MessageConverter_1_0_to_v0_10Test method testAmqpSequenceWithSimpleTypes.

@Test
public void testAmqpSequenceWithSimpleTypes() throws Exception {
    final List<Integer> expected = new ArrayList<>();
    expected.add(37);
    expected.add(42);
    final AmqpSequence amqpSequence = new AmqpSequence(expected);
    Message_1_0 sourceMessage = createTestMessage(amqpSequence.createEncodingRetainingSection());
    final MessageTransferMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", "jms/stream-message", convertedMessage.getMessageHeader().getMimeType());
    final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
    assertEquals("Unexpected content", expected, new JmsStreamMessageToList().toObject(getBytes(content)));
}
Also used : JmsStreamMessageToList(org.apache.qpid.server.typedmessage.mimecontentconverter.JmsStreamMessageToList) MessageTransferMessage(org.apache.qpid.server.protocol.v0_10.MessageTransferMessage) ArrayList(java.util.ArrayList) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpSequence(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequence) Test(org.junit.Test)

Example 4 with AmqpSequence

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

the class MessageConverter_v1_0_to_InternalTest method testAmqpSequenceWithSimpleTypes.

@Test
public void testAmqpSequenceWithSimpleTypes() throws Exception {
    final List<Object> originalList = new ArrayList<>();
    originalList.add(37);
    originalList.add(42F);
    final AmqpSequence amqpSequence = new AmqpSequence(originalList);
    Message_1_0 sourceMessage = createTestMessage(amqpSequence.createEncodingRetainingSection());
    final InternalMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
    assertEquals("Unexpected mime type", null, convertedMessage.getMessageHeader().getMimeType());
    List<Object> convertedList = ((List<Object>) convertedMessage.getMessageBody());
    assertEquals("Unexpected size", (long) originalList.size(), (long) convertedList.size());
    assertEquals("Unexpected first item", originalList.get(0), convertedList.get(0));
    assertEquals("Unexpected second item", originalList.get(1), convertedList.get(1));
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) ArrayList(java.util.ArrayList) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AmqpSequence(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequence) Test(org.junit.Test)

Example 5 with AmqpSequence

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

the class MessageConverter_from_1_0 method convertBodyToObject.

static Object convertBodyToObject(final Message_1_0 serverMessage) {
    final SectionDecoderImpl sectionDecoder = new SectionDecoderImpl(MessageConverter_v1_0_to_Internal.TYPE_REGISTRY.getSectionDecoderRegistry());
    Object bodyObject = null;
    List<EncodingRetainingSection<?>> sections = null;
    try {
        try (QpidByteBuffer allData = serverMessage.getContent()) {
            sections = sectionDecoder.parseAll(allData);
        }
        final int size = sections == null ? 0 : sections.size();
        final List<EncodingRetainingSection<?>> bodySections = new ArrayList<>(size);
        final ListIterator<EncodingRetainingSection<?>> iterator = sections == null ? Collections.emptyListIterator() : sections.listIterator();
        EncodingRetainingSection<?> previousSection = null;
        while (iterator.hasNext()) {
            final EncodingRetainingSection<?> section = iterator.next();
            if (section instanceof AmqpValueSection || section instanceof DataSection || section instanceof AmqpSequenceSection) {
                if (previousSection != null && (previousSection.getClass() != section.getClass() || section instanceof AmqpValueSection)) {
                    throw new MessageConversionException("Message is badly formed and has multiple body section which are not all Data or not all AmqpSequence");
                } else {
                    previousSection = section;
                }
                bodySections.add(section);
            }
        }
        // In 1.0 of the spec, it is illegal to have message with no body but AMQP-127 asks to have that restriction lifted
        if (!bodySections.isEmpty()) {
            final EncodingRetainingSection<?> firstBodySection = bodySections.get(0);
            if (firstBodySection instanceof AmqpValueSection) {
                bodyObject = convertValue(firstBodySection.getValue());
            } else if (firstBodySection instanceof DataSection) {
                int totalSize = 0;
                for (EncodingRetainingSection<?> section : bodySections) {
                    totalSize += ((DataSection) section).getValue().getArray().length;
                }
                final byte[] bodyData = new byte[totalSize];
                final ByteBuffer buf = ByteBuffer.wrap(bodyData);
                for (EncodingRetainingSection<?> section : bodySections) {
                    buf.put(((DataSection) section).getValue().asByteBuffer());
                }
                bodyObject = bodyData;
            } else {
                final ArrayList<Object> totalSequence = new ArrayList<>();
                for (EncodingRetainingSection<?> section : bodySections) {
                    totalSequence.addAll(((AmqpSequenceSection) section).getValue());
                }
                bodyObject = convertValue(totalSequence);
            }
        }
    } catch (AmqpErrorException e) {
        throw new ConnectionScopedRuntimeException(e);
    } finally {
        if (sections != null) {
            sections.forEach(EncodingRetaining::dispose);
        }
    }
    return bodyObject;
}
Also used : MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) EncodingRetaining(org.apache.qpid.server.protocol.v1_0.type.messaging.codec.EncodingRetaining) ArrayList(java.util.ArrayList) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) AmqpSequenceSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) DataSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) SectionDecoderImpl(org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpValueSection(org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)

Aggregations

NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)7 AmqpSequence (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequence)7 Test (org.junit.Test)7 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)6 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)5 ArrayList (java.util.ArrayList)4 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)2 AmqpListToListConverter (org.apache.qpid.server.protocol.v0_10.transport.mimecontentconverter.AmqpListToListConverter)2 AMQMessage (org.apache.qpid.server.protocol.v0_8.AMQMessage)2 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)2 JmsMapMessageToMap (org.apache.qpid.server.typedmessage.mimecontentconverter.JmsMapMessageToMap)2 JmsStreamMessageToList (org.apache.qpid.server.typedmessage.mimecontentconverter.JmsStreamMessageToList)2 ByteBuffer (java.nio.ByteBuffer)1 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)1 SectionDecoderImpl (org.apache.qpid.server.protocol.v1_0.messaging.SectionDecoderImpl)1 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)1