From 9d070812dd60def480ede04679385a666474a8f3 Mon Sep 17 00:00:00 2001 From: Domenico Francesco Bruscino Date: Fri, 22 Jan 2021 09:56:14 +0100 Subject: [PATCH] ARTEMIS-3079 Fix AMQP binary properties serialization to JSON --- .../protocol/amqp/broker/AMQPMessage.java | 14 ++++++++ .../integration/amqp/JMXManagementTest.java | 33 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java index 2c4f8d8e66..bb127e8b99 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/broker/AMQPMessage.java @@ -812,6 +812,20 @@ public abstract class AMQPMessage extends RefCountMessage implements org.apache. @Override public abstract int getMemoryEstimate(); + @Override + public Map toPropertyMap() { + Map map = new HashMap<>(); + for (SimpleString name : getPropertyNames()) { + Object value = getObjectProperty(name.toString()); + //some property is Binary, which is not available for management console + if (value instanceof Binary) { + value = ((Binary)value).getArray(); + } + map.put(name.toString(), value); + } + return map; + } + @Override public ICoreMessage toCore(CoreMessageObjectPools coreMessageObjectPools) { try { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMXManagementTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMXManagementTest.java index 3be3e88c32..0a63bde27a 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMXManagementTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/JMXManagementTest.java @@ -20,6 +20,13 @@ import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.management.QueueControl; import org.apache.activemq.artemis.tests.integration.management.ManagementControlHelper; +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.AmqpSender; +import org.apache.activemq.transport.amqp.client.AmqpSession; +import org.apache.qpid.proton.amqp.Binary; +import org.junit.Assert; import org.junit.Test; import javax.jms.Connection; @@ -83,6 +90,32 @@ public class JMXManagementTest extends JMSClientTestSupport { connection2.close(); } + @Test + public void testGetFirstMessage() throws Exception { + AmqpClient client = createAmqpClient(); + AmqpConnection connection = addConnection(client.connect()); + + try { + AmqpSession session = connection.createSession(); + AmqpSender sender = session.createSender(getQueueName()); + + session.begin(); + AmqpMessage message = new AmqpMessage(); + message.setApplicationProperty("TEST_BINARY", new Binary("TEST".getBytes())); + message.setApplicationProperty("TEST_STRING", "TEST"); + message.setText("TEST"); + sender.send(message); + session.commit(); + + SimpleString queue = new SimpleString(getQueueName()); + QueueControl queueControl = createManagementControl(queue, queue); + String firstMessageAsJSON = queueControl.getFirstMessageAsJSON(); + Assert.assertNotNull(firstMessageAsJSON); + } finally { + connection.close(); + } + } + protected QueueControl createManagementControl(final SimpleString address, final SimpleString queue) throws Exception { QueueControl queueControl = ManagementControlHelper.createQueueControl(address, queue, RoutingType.ANYCAST, this.mBeanServer);