Search in sources :

Example 11 with AMQPMessage

use of org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage in project activemq-artemis by apache.

the class TestConversions method testSimpleConversionText.

@Test
public void testSimpleConversionText() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    String text = "someText";
    message.setBody(new AmqpValue(text));
    AMQPMessage encodedMessage = new AMQPMessage(message);
    ICoreMessage serverMessage = encodedMessage.toCore();
    ServerJMSTextMessage textMessage = (ServerJMSTextMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
    textMessage.decode();
    verifyProperties(textMessage);
    Assert.assertEquals(text, textMessage.getText());
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 12 with AMQPMessage

use of org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage in project activemq-artemis by apache.

the class TestConversions method testSimpleConversionMap.

@Test
public void testSimpleConversionMap() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    Map<String, Object> mapValues = new HashMap<>();
    mapValues.put("somestr", "value");
    mapValues.put("someint", Integer.valueOf(1));
    message.setBody(new AmqpValue(mapValues));
    AMQPMessage encodedMessage = new AMQPMessage(message);
    ICoreMessage serverMessage = encodedMessage.toCore();
    serverMessage.getReadOnlyBodyBuffer();
    ServerJMSMapMessage mapMessage = (ServerJMSMapMessage) ServerJMSMessage.wrapCoreMessage(serverMessage);
    mapMessage.decode();
    verifyProperties(mapMessage);
    Assert.assertEquals(1, mapMessage.getInt("someint"));
    Assert.assertEquals("value", mapMessage.getString("somestr"));
    AMQPMessage newAMQP = CoreAmqpConverter.fromCore(mapMessage.getInnerMessage());
    System.out.println(newAMQP.getProtonMessage().getBody());
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) HashMap(java.util.HashMap) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 13 with AMQPMessage

use of org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage in project activemq-artemis by apache.

the class TestConversions method testAmqpValueOfBooleanIsPassedThrough.

@Test
public void testAmqpValueOfBooleanIsPassedThrough() throws Exception {
    Map<String, Object> mapprop = createPropertiesMap();
    ApplicationProperties properties = new ApplicationProperties(mapprop);
    MessageImpl message = (MessageImpl) Message.Factory.create();
    message.setApplicationProperties(properties);
    byte[] bodyBytes = new byte[4];
    for (int i = 0; i < bodyBytes.length; i++) {
        bodyBytes[i] = (byte) 0xff;
    }
    message.setBody(new AmqpValue(new Boolean(true)));
    AMQPMessage encodedMessage = new AMQPMessage(message);
    ICoreMessage serverMessage = encodedMessage.toCore();
    verifyProperties(ServerJMSMessage.wrapCoreMessage(serverMessage));
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ApplicationProperties(org.apache.qpid.proton.amqp.messaging.ApplicationProperties) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 14 with AMQPMessage

use of org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage 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 15 with AMQPMessage

use of org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage in project activemq-artemis by apache.

the class JMSMappingInboundTransformerTest method testCreateObjectMessageFromAmqpValueWithBinaryAndContentType.

/**
 * Test that a message with an AmqpValue section containing a Binary, but with the content
 * type set to {@value AMQPMessageSupport#SERIALIZED_JAVA_OBJECT_CONTENT_TYPE} results in an
 * ObjectMessage when not otherwise annotated to indicate the type of JMS message it is.
 *
 * @throws Exception
 *         if an error occurs during the test.
 */
@Test
public void testCreateObjectMessageFromAmqpValueWithBinaryAndContentType() throws Exception {
    Message message = Message.Factory.create();
    message.setBody(new AmqpValue(new Binary(new byte[0])));
    message.setContentType(AMQPMessageSupport.SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString());
    javax.jms.Message jmsMessage = ServerJMSMessage.wrapCoreMessage(new AMQPMessage(message).toCore());
    assertNotNull("Message should not be null", jmsMessage);
    assertEquals("Unexpected message class type", ServerJMSObjectMessage.class, jmsMessage.getClass());
}
Also used : ServerJMSTextMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) ServerJMSObjectMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage) Message(org.apache.qpid.proton.message.Message) TextMessage(javax.jms.TextMessage) ServerJMSMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage) ServerJMSStreamMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) ServerJMSBytesMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) Binary(org.apache.qpid.proton.amqp.Binary) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Aggregations

AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)57 Test (org.junit.Test)49 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)35 Message (org.apache.qpid.proton.message.Message)26 MessageImpl (org.apache.qpid.proton.message.impl.MessageImpl)21 ServerJMSBytesMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage)20 ServerJMSMapMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage)20 ServerJMSMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)20 ServerJMSStreamMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage)20 ServerJMSTextMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage)20 TextMessage (javax.jms.TextMessage)19 ServerJMSObjectMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage)19 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)19 Header (org.apache.qpid.proton.amqp.messaging.Header)11 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)10 HashMap (java.util.HashMap)9 Binary (org.apache.qpid.proton.amqp.Binary)9 Data (org.apache.qpid.proton.amqp.messaging.Data)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 ByteBuf (io.netty.buffer.ByteBuf)4