diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java index c904944b6f..588b10e292 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/converter/jms/ServerJMSMapMessage.java @@ -29,6 +29,10 @@ import org.apache.activemq.artemis.api.core.ICoreMessage; import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.utils.collections.TypedProperties; +import org.apache.qpid.proton.amqp.UnsignedByte; +import org.apache.qpid.proton.amqp.UnsignedInteger; +import org.apache.qpid.proton.amqp.UnsignedLong; +import org.apache.qpid.proton.amqp.UnsignedShort; import static org.apache.activemq.artemis.reader.MapMessageUtil.readBodyMap; import static org.apache.activemq.artemis.reader.MapMessageUtil.writeBodyMap; @@ -122,7 +126,18 @@ public final class ServerJMSMapMessage extends ServerJMSMessage implements MapMe @Override public void setObject(final String name, final Object value) throws JMSException { try { - TypedProperties.setObjectProperty(new SimpleString(name), value, map); + // primitives and String + Object val = value; + if (value instanceof UnsignedInteger) { + val = ((UnsignedInteger) value).intValue(); + } else if (value instanceof UnsignedShort) { + val = ((UnsignedShort) value).shortValue(); + } else if (value instanceof UnsignedByte) { + val = ((UnsignedByte) value).byteValue(); + } else if (value instanceof UnsignedLong) { + val = ((UnsignedLong) value).longValue(); + } + TypedProperties.setObjectProperty(new SimpleString(name), val, map); } catch (ActiveMQPropertyConversionException e) { throw new MessageFormatException(e.getMessage()); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpManagementTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpManagementTest.java index 9b8ddfee13..98b18e8d00 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpManagementTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpManagementTest.java @@ -16,19 +16,27 @@ */ package org.apache.activemq.artemis.tests.integration.amqp; +import java.util.LinkedHashMap; import java.util.concurrent.TimeUnit; import org.apache.activemq.artemis.api.core.management.ResourceNames; +import org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage; import org.apache.activemq.transport.amqp.client.AmqpClient; import org.apache.activemq.transport.amqp.client.AmqpConnection; import org.apache.activemq.transport.amqp.client.AmqpMessage; import org.apache.activemq.transport.amqp.client.AmqpReceiver; import org.apache.activemq.transport.amqp.client.AmqpSender; import org.apache.activemq.transport.amqp.client.AmqpSession; +import org.apache.qpid.proton.amqp.UnsignedByte; +import org.apache.qpid.proton.amqp.UnsignedInteger; +import org.apache.qpid.proton.amqp.UnsignedLong; +import org.apache.qpid.proton.amqp.UnsignedShort; import org.apache.qpid.proton.amqp.messaging.AmqpValue; import org.junit.Assert; import org.junit.Test; +import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.createMapMessage; + public class AmqpManagementTest extends AmqpClientTestSupport { @Test(timeout = 60000) @@ -65,4 +73,32 @@ public class AmqpManagementTest extends AmqpClientTestSupport { connection.close(); } } + + /** + * 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 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); + } }