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
This commit is contained in:
Gary Tully 2011-02-14 11:11:01 +00:00
parent bf4dd7330d
commit 9edeb21bec
3 changed files with 100 additions and 1 deletions

View File

@ -283,6 +283,7 @@ public final class OpenTypeSupport {
@Override
public Map<String, Object> getFields(Object o) throws OpenDataException {
ActiveMQBytesMessage m = (ActiveMQBytesMessage)o;
m.setReadOnlyBody(true);
Map<String, Object> rc = super.getFields(o);
long length = 0;
try {

View File

@ -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<MESSAGE_COUNT; i++) {
Message message = consumer.receive(5000);
assertNotNull(message);
assertTrue(message instanceof BytesMessage);
}
consumer.close();
session.close();
}
}

View File

@ -0,0 +1,34 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.jmx;
import org.apache.activemq.broker.jmx.OpenTypeSupport;
import org.apache.activemq.command.ActiveMQBytesMessage;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class OpenTypeSupportTest {
private static final Logger LOG = LoggerFactory.getLogger(OpenTypeSupportTest.class);
@Test
public void testBrowseByteMessageFails() throws Exception {
ActiveMQBytesMessage bm = new ActiveMQBytesMessage();
bm.writeBytes("123456".getBytes());
Object result = OpenTypeSupport.convert(bm);
LOG.info("result : " + result);
}
}