Search in sources :

Example 1 with ServerJMSMapMessage

use of org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage in project activemq-artemis by apache.

the class JMSMappingOutboundTransformerTest method testConvertMapMessageToAmqpMessageWithByteArrayValueInBody.

@Test
public void testConvertMapMessageToAmqpMessageWithByteArrayValueInBody() throws Exception {
    final byte[] byteArray = new byte[] { 1, 2, 3, 4, 5 };
    ServerJMSMapMessage outbound = createMapMessage();
    outbound.setBytes("bytes", byteArray);
    outbound.encode();
    Message amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage()).getProtonMessage();
    assertNotNull(amqp.getBody());
    assertTrue(amqp.getBody() instanceof AmqpValue);
    assertTrue(((AmqpValue) amqp.getBody()).getValue() instanceof Map);
    @SuppressWarnings("unchecked") Map<Object, Object> amqpMap = (Map<Object, Object>) ((AmqpValue) amqp.getBody()).getValue();
    assertEquals(1, amqpMap.size());
    Binary readByteArray = (Binary) amqpMap.get("bytes");
    assertNotNull(readByteArray);
}
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) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) Binary(org.apache.qpid.proton.amqp.Binary) Map(java.util.Map) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 2 with ServerJMSMapMessage

use of org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage in project activemq-artemis by apache.

the class JMSMappingOutboundTransformerTest method testConvertMapMessageToAmqpMessageWithNoBody.

// ----- MapMessage type tests --------------------------------------------//
@Test
public void testConvertMapMessageToAmqpMessageWithNoBody() throws Exception {
    ServerJMSMapMessage outbound = createMapMessage();
    outbound.encode();
    Message amqp = AMQPConverter.getInstance().fromCore(outbound.getInnerMessage()).getProtonMessage();
    assertNotNull(amqp.getBody());
    assertTrue(amqp.getBody() instanceof AmqpValue);
    assertTrue(((AmqpValue) amqp.getBody()).getValue() instanceof Map);
}
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) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) Map(java.util.Map) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) Test(org.junit.Test)

Example 3 with ServerJMSMapMessage

use of org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage 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 4 with ServerJMSMapMessage

use of org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage in project activemq-artemis by apache.

the class AMQPMessageSupport method createMapMessage.

public static ServerJMSMapMessage createMapMessage(long id, Map<String, Object> content, CoreMessageObjectPools coreMessageObjectPools) throws JMSException {
    ServerJMSMapMessage message = createMapMessage(id, coreMessageObjectPools);
    final Set<Map.Entry<String, Object>> set = content.entrySet();
    for (Map.Entry<String, Object> entry : set) {
        Object value = entry.getValue();
        if (value instanceof Binary) {
            Binary binary = (Binary) value;
            value = Arrays.copyOfRange(binary.getArray(), binary.getArrayOffset(), binary.getLength());
        }
        message.setObject(entry.getKey(), value);
    }
    return message;
}
Also used : ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) Binary(org.apache.qpid.proton.amqp.Binary) Map(java.util.Map)

Example 5 with ServerJMSMapMessage

use of org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage in project activemq-artemis by apache.

the class AmqpManagementTest method testUnsignedValues.

/**
 * Some clients use Unsigned types from org.apache.qpid.proton.amqp
 * @throws Exception
 */
@Test(timeout = 60000)
public void testUnsignedValues() throws Exception {
    int sequence = 42;
    LinkedHashMap<String, Object> map = new LinkedHashMap<>();
    map.put("sequence", new UnsignedInteger(sequence));
    ServerJMSMapMessage msg = createMapMessage(1, map, null);
    assertEquals(msg.getInt("sequence"), sequence);
    map.clear();
    map.put("sequence", new UnsignedLong(sequence));
    msg = createMapMessage(1, map, null);
    assertEquals(msg.getLong("sequence"), sequence);
    map.clear();
    map.put("sequence", new UnsignedShort((short) sequence));
    msg = createMapMessage(1, map, null);
    assertEquals(msg.getShort("sequence"), sequence);
    map.clear();
    map.put("sequence", new UnsignedByte((byte) sequence));
    msg = createMapMessage(1, map, null);
    assertEquals(msg.getByte("sequence"), sequence);
}
Also used : UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) UnsignedByte(org.apache.qpid.proton.amqp.UnsignedByte) LinkedHashMap(java.util.LinkedHashMap) UnsignedShort(org.apache.qpid.proton.amqp.UnsignedShort) Test(org.junit.Test)

Aggregations

ServerJMSMapMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage)8 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)6 Test (org.junit.Test)6 Map (java.util.Map)5 ServerJMSBytesMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage)5 ServerJMSMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMessage)5 ServerJMSObjectMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSObjectMessage)5 ServerJMSStreamMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage)5 ServerJMSTextMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage)5 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)4 Message (org.apache.qpid.proton.message.Message)4 Binary (org.apache.qpid.proton.amqp.Binary)3 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 MessageEOFException (javax.jms.MessageEOFException)1 AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)1 UnsignedByte (org.apache.qpid.proton.amqp.UnsignedByte)1 UnsignedInteger (org.apache.qpid.proton.amqp.UnsignedInteger)1