diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/CompositeDataHelper.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/CompositeDataHelper.java index 33821b2c83..ec27ae2f3f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/CompositeDataHelper.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/CompositeDataHelper.java @@ -34,6 +34,11 @@ public class CompositeDataHelper { */ public static Map getTabularMap(CompositeData cdata, String fieldName) { Map map = new HashMap(); + appendTabularMap(map, cdata, fieldName); + return map; + } + + public static void appendTabularMap(Map map, CompositeData cdata, String fieldName) { Object tabularObject = cdata.get(fieldName); if (tabularObject instanceof TabularData) { TabularData tabularData = (TabularData) tabularObject; @@ -44,6 +49,25 @@ public class CompositeDataHelper { map.put(key, value); } } + } + + /** + * Returns a map of all the user properties in the given message {@link javax.management.openmbean.CompositeData} + * object + * + * @param cdata + * @return + */ + public static Map getMessageUserProperties(CompositeData cdata) { + Map map = new HashMap(); + appendTabularMap(map, cdata, CompositeDataConstants.STRING_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.BOOLEAN_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.BYTE_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.SHORT_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.INT_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.LONG_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.FLOAT_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.DOUBLE_PROPERTIES); return map; } } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java index c5198953ca..fcad449b48 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java @@ -188,6 +188,11 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { assertEquals("stringProperties size()", 1, stringProperties.size()); assertEquals("stringProperties.MyHeader", "StringHeader" + i, stringProperties.get("MyStringHeader")); + Map properties = CompositeDataHelper.getMessageUserProperties(cdata); + assertEquals("properties size()", 2, properties.size()); + assertEquals("properties.MyHeader", i, properties.get("MyHeader")); + assertEquals("properties.MyHeader", "StringHeader" + i, properties.get("MyStringHeader")); + assertComplexData(cdata, "JMSXGroupSeq", 1234); assertComplexData(cdata, "JMSXGroupID", "MyGroupID"); assertComplexData(cdata, "Text", "message:" + i);