From 9edeb21bec968dcda639222c45a7c1ae72e54d6b Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Mon, 14 Feb 2011 11:11:01 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-3180 - JMX Browse of BytesMessage fails with javax.management.openmbean.OpenDataException: Argument's element itemValues[8]=[B@de15a0 is not a valid value for this item. readonly flag needs to be flipped by browser such that content can be read. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1070442 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/broker/jmx/OpenTypeSupport.java | 1 + .../apache/activemq/broker/jmx/MBeanTest.java | 66 ++++++++++++++++++- .../activemq/jmx/OpenTypeSupportTest.java | 34 ++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 activemq-core/src/test/java/org/apache/activemq/jmx/OpenTypeSupportTest.java diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java index d7034755db..a6df8e947d 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/OpenTypeSupport.java @@ -283,6 +283,7 @@ public final class OpenTypeSupport { @Override public Map getFields(Object o) throws OpenDataException { ActiveMQBytesMessage m = (ActiveMQBytesMessage)o; + m.setReadOnlyBody(true); Map rc = super.getFields(o); long length = 0; try { 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 3c5f02cea1..f735926f75 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 @@ -23,6 +23,7 @@ import java.net.URL; import java.util.HashMap; import java.util.Map; +import javax.jms.BytesMessage; import javax.jms.Connection; import javax.jms.Message; import javax.jms.MessageConsumer; @@ -601,7 +602,26 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { } Thread.sleep(1000); } - + + protected void useConnectionWithByteMessage(Connection connection) throws Exception { + connection.setClientID(clientID); + connection.start(); + ActiveMQSession session = (ActiveMQSession) connection.createSession(transacted, authMode); + destination = createDestination(); + MessageProducer producer = session.createProducer(destination); + for (int i = 0; i < MESSAGE_COUNT; i++) { + BytesMessage message = session.createBytesMessage(); + message.writeBytes(("Message: " + i).getBytes()); + message.setIntProperty("counter", i); + message.setJMSCorrelationID("MyCorrelationID"); + message.setJMSReplyTo(new ActiveMQQueue("MyReplyTo")); + message.setJMSType("MyType"); + message.setJMSPriority(5); + producer.send(message); + } + Thread.sleep(1000); + } + protected void echo(String text) { LOG.info(text); } @@ -667,4 +687,48 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { assertTrue("dest has some memory usage", queue.getMemoryPercentUsage() > 0); } + + public void testBrowseBytesMessages() throws Exception { + connection = connectionFactory.createConnection(); + useConnectionWithByteMessage(connection); + + ObjectName queueViewMBeanName = assertRegisteredObjectName(domain + ":Type=Queue,Destination=" + getDestinationString() + ",BrokerName=localhost"); + + QueueViewMBean queue = (QueueViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer, queueViewMBeanName, QueueViewMBean.class, true); + + CompositeData[] compdatalist = queue.browse(); + int initialQueueSize = compdatalist.length; + if (initialQueueSize == 0) { + fail("There is no message in the queue:"); + } + else { + echo("Current queue size: " + initialQueueSize); + } + int messageCount = initialQueueSize; + String[] messageIDs = new String[messageCount]; + for (int i = 0; i < messageCount; i++) { + CompositeData cdata = compdatalist[i]; + String messageID = (String) cdata.get("JMSMessageID"); + assertNotNull("Should have a message ID for message " + i, messageID); + messageIDs[i] = messageID; + + Byte[] preview = (Byte[]) cdata.get(CompositeDataConstants.BODY_PREVIEW); + assertNotNull("should be a preview", preview); + assertTrue("not empty", preview.length > 0); + } + + assertTrue("dest has some memory usage", queue.getMemoryPercentUsage() > 0); + + // consume all the messages + echo("Attempting to consume all bytes messages from: " + destination); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageConsumer consumer = session.createConsumer(destination); + for (int i=0; i