Search in sources :

Example 1 with AmqpSequence

use of org.apache.qpid.proton.amqp.messaging.AmqpSequence in project activemq-artemis by apache.

the class JMSMappingOutboundTransformerTest method testConvertStreamMessageToAmqpMessageWithAmqpSequencey.

@Test
public void testConvertStreamMessageToAmqpMessageWithAmqpSequencey() throws Exception {
    ServerJMSStreamMessage outbound = createStreamMessage();
    outbound.encode();
    Message amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage()).getProtonMessage();
    assertNotNull(amqp.getBody());
    assertTrue(amqp.getBody() instanceof AmqpSequence);
    assertTrue(((AmqpSequence) amqp.getBody()).getValue() instanceof List);
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) List(java.util.List) AmqpSequence(org.apache.qpid.proton.amqp.messaging.AmqpSequence) Test(org.junit.Test)

Example 2 with AmqpSequence

use of org.apache.qpid.proton.amqp.messaging.AmqpSequence in project activemq-artemis by apache.

the class TestConversions method testSimpleConversionStream.

@Test
public void testSimpleConversionStream() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    List<Object> objects = new LinkedList<>();
    objects.add(new Integer(10));
    objects.add("10");
    message.setBody(new AmqpSequence(objects));
    AMQPMessage encodedMessage = new AMQPMessage(message);
    ICoreMessage serverMessage = encodedMessage.toCore();
    ServerJMSStreamMessage streamMessage = (ServerJMSStreamMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
    verifyProperties(streamMessage);
    streamMessage.reset();
    assertEquals(10, streamMessage.readInt());
    assertEquals("10", streamMessage.readString());
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AmqpSequence(org.apache.qpid.proton.amqp.messaging.AmqpSequence) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 3 with AmqpSequence

use of org.apache.qpid.proton.amqp.messaging.AmqpSequence in project activemq-artemis by apache.

the class JMSMappingOutboundTransformerTest method testConvertCompressedStreamMessageToAmqpMessageWithAmqpValueBody.

@Test
public void testConvertCompressedStreamMessageToAmqpMessageWithAmqpValueBody() throws Exception {
    ServerJMSStreamMessage outbound = createStreamMessage(true);
    outbound.writeBoolean(false);
    outbound.writeString("test");
    outbound.encode();
    Message amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage()).getProtonMessage();
    assertNotNull(amqp.getBody());
    assertTrue(amqp.getBody() instanceof AmqpSequence);
    AmqpSequence list = (AmqpSequence) amqp.getBody();
    @SuppressWarnings("unchecked") List<Object> amqpList = list.getValue();
    assertEquals(2, amqpList.size());
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) AmqpSequence(org.apache.qpid.proton.amqp.messaging.AmqpSequence) Test(org.junit.Test)

Example 4 with AmqpSequence

use of org.apache.qpid.proton.amqp.messaging.AmqpSequence in project activemq-artemis by apache.

the class JMSMappingOutboundTransformerTest method testConvertCompressedStreamMessageToAmqpMessageWithAmqpSequencey.

@Test
public void testConvertCompressedStreamMessageToAmqpMessageWithAmqpSequencey() throws Exception {
    ServerJMSStreamMessage outbound = createStreamMessage(true);
    outbound.writeBoolean(false);
    outbound.writeString("test");
    outbound.encode();
    Message amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage()).getProtonMessage();
    assertNotNull(amqp.getBody());
    assertTrue(amqp.getBody() instanceof AmqpSequence);
    assertTrue(((AmqpSequence) amqp.getBody()).getValue() instanceof List);
    @SuppressWarnings("unchecked") List<Object> amqpList = ((AmqpSequence) amqp.getBody()).getValue();
    assertEquals(2, amqpList.size());
}
Also used : CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) List(java.util.List) AmqpSequence(org.apache.qpid.proton.amqp.messaging.AmqpSequence) Test(org.junit.Test)

Example 5 with AmqpSequence

use of org.apache.qpid.proton.amqp.messaging.AmqpSequence in project activemq-artemis by apache.

the class CoreAmqpConverter method convertBody.

private static Section convertBody(ServerJMSMessage message, Map<Symbol, Object> maMap, Properties properties) throws JMSException {
    Section body = null;
    if (message instanceof ServerJMSBytesMessage) {
        Binary payload = getBinaryFromMessageBody((ServerJMSBytesMessage) message);
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_BYTES_MESSAGE);
        if (payload == null) {
            payload = EMPTY_BINARY;
        } else {
            body = new AmqpValue(payload);
        }
    } else if (message instanceof ServerJMSTextMessage) {
        body = new AmqpValue(((TextMessage) message).getText());
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_TEXT_MESSAGE);
    } else if (message instanceof ServerJMSMapMessage) {
        body = new AmqpValue(getMapFromMessageBody((ServerJMSMapMessage) message));
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_MAP_MESSAGE);
    } else if (message instanceof ServerJMSStreamMessage) {
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_STREAM_MESSAGE);
        ArrayList<Object> list = new ArrayList<>();
        final ServerJMSStreamMessage m = (ServerJMSStreamMessage) message;
        try {
            while (true) {
                list.add(m.readObject());
            }
        } catch (MessageEOFException e) {
        }
        body = new AmqpSequence(list);
    } else if (message instanceof ServerJMSObjectMessage) {
        properties.setContentType(AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE);
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_OBJECT_MESSAGE);
        Binary payload = getBinaryFromMessageBody((ServerJMSObjectMessage) message);
        if (payload == null) {
            payload = EMPTY_BINARY;
        }
        body = new Data(payload);
        // we are sending it.
        if (!message.propertyExists(JMS_AMQP_CONTENT_TYPE)) {
            message.setStringProperty(JMS_AMQP_CONTENT_TYPE, SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString());
        }
    } else if (message instanceof ServerJMSMessage) {
        maMap.put(AMQPMessageSupport.JMS_MSG_TYPE, AMQPMessageSupport.JMS_MESSAGE);
        // If this is not an AMQP message that was converted then the original encoding
        // will be unknown so we check for special cases of messages with special data
        // encoded into the server message body.
        ICoreMessage internalMessage = message.getInnerMessage();
        int readerIndex = internalMessage.getBodyBuffer().readerIndex();
        try {
            Object s = internalMessage.getBodyBuffer().readNullableSimpleString();
            if (s != null) {
                body = new AmqpValue(s.toString());
            }
        } catch (Throwable ignored) {
            logger.debug("Exception ignored during conversion", ignored.getMessage(), ignored);
            body = new AmqpValue("Conversion to AMQP error!");
        } finally {
            internalMessage.getBodyBuffer().readerIndex(readerIndex);
        }
    }
    return body;
}
Also used : MessageEOFException(javax.jms.MessageEOFException) ArrayList(java.util.ArrayList) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) Data(org.apache.qpid.proton.amqp.messaging.Data) Section(org.apache.qpid.proton.amqp.messaging.Section) AmqpSequence(org.apache.qpid.proton.amqp.messaging.AmqpSequence) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) Binary(org.apache.qpid.proton.amqp.Binary) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)

Aggregations

AmqpSequence (org.apache.qpid.proton.amqp.messaging.AmqpSequence)8 ServerJMSStreamMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage)7 ServerJMSMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)6 ServerJMSBytesMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage)5 ServerJMSMapMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage)5 ServerJMSObjectMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage)5 ServerJMSTextMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage)5 Test (org.junit.Test)5 Message (org.apache.qpid.proton.message.Message)4 List (java.util.List)3 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)3 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)3 Binary (org.apache.qpid.proton.amqp.Binary)3 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)3 Data (org.apache.qpid.proton.amqp.messaging.Data)3 Section (org.apache.qpid.proton.amqp.messaging.Section)3 ArrayList (java.util.ArrayList)2 AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBuffer (java.nio.ByteBuffer)1