ARTEMIS-1646 fix for browsing messages sent via JS client

This commit is contained in:
Stanislav Knot 2018-01-31 09:37:31 +01:00 committed by Michael Pearce
parent 5ed518f412
commit a259b6972c
2 changed files with 52 additions and 1 deletions

View File

@ -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.Message;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.utils.collections.TypedProperties; 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.readBodyMap;
import static org.apache.activemq.artemis.reader.MapMessageUtil.writeBodyMap; import static org.apache.activemq.artemis.reader.MapMessageUtil.writeBodyMap;
@ -122,7 +126,18 @@ public final class ServerJMSMapMessage extends ServerJMSMessage implements MapMe
@Override @Override
public void setObject(final String name, final Object value) throws JMSException { public void setObject(final String name, final Object value) throws JMSException {
try { 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) { } catch (ActiveMQPropertyConversionException e) {
throw new MessageFormatException(e.getMessage()); throw new MessageFormatException(e.getMessage());
} }

View File

@ -16,19 +16,27 @@
*/ */
package org.apache.activemq.artemis.tests.integration.amqp; package org.apache.activemq.artemis.tests.integration.amqp;
import java.util.LinkedHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.activemq.artemis.api.core.management.ResourceNames; 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.AmqpClient;
import org.apache.activemq.transport.amqp.client.AmqpConnection; import org.apache.activemq.transport.amqp.client.AmqpConnection;
import org.apache.activemq.transport.amqp.client.AmqpMessage; import org.apache.activemq.transport.amqp.client.AmqpMessage;
import org.apache.activemq.transport.amqp.client.AmqpReceiver; import org.apache.activemq.transport.amqp.client.AmqpReceiver;
import org.apache.activemq.transport.amqp.client.AmqpSender; import org.apache.activemq.transport.amqp.client.AmqpSender;
import org.apache.activemq.transport.amqp.client.AmqpSession; 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.apache.qpid.proton.amqp.messaging.AmqpValue;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import static org.apache.activemq.artemis.protocol.amqp.converter.AMQPMessageSupport.createMapMessage;
public class AmqpManagementTest extends AmqpClientTestSupport { public class AmqpManagementTest extends AmqpClientTestSupport {
@Test(timeout = 60000) @Test(timeout = 60000)
@ -65,4 +73,32 @@ public class AmqpManagementTest extends AmqpClientTestSupport {
connection.close(); 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<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);
}
} }