mirror of https://github.com/apache/activemq.git
apply fix and patch for: https://issues.apache.org/jira/browse/AMQ-4530
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1481930 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
87a29847bb
commit
2bd0e5703e
|
@ -16,13 +16,16 @@
|
|||
*/
|
||||
package org.apache.activemq.broker.jmx;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.apache.activemq.broker.region.policy.SlowConsumerEntry;
|
||||
import org.apache.activemq.broker.scheduler.Job;
|
||||
import org.apache.activemq.command.ActiveMQBlobMessage;
|
||||
import org.apache.activemq.command.ActiveMQBytesMessage;
|
||||
import org.apache.activemq.command.ActiveMQMapMessage;
|
||||
import org.apache.activemq.command.ActiveMQMessage;
|
||||
import org.apache.activemq.command.ActiveMQObjectMessage;
|
||||
import org.apache.activemq.command.ActiveMQStreamMessage;
|
||||
import org.apache.activemq.command.ActiveMQTextMessage;
|
||||
import org.fusesource.hawtbuf.UTF8Buffer;
|
||||
|
||||
import javax.jms.DeliveryMode;
|
||||
import javax.jms.JMSException;
|
||||
|
@ -35,16 +38,13 @@ import javax.management.openmbean.OpenType;
|
|||
import javax.management.openmbean.SimpleType;
|
||||
import javax.management.openmbean.TabularDataSupport;
|
||||
import javax.management.openmbean.TabularType;
|
||||
|
||||
import org.apache.activemq.broker.region.policy.SlowConsumerEntry;
|
||||
import org.apache.activemq.broker.scheduler.Job;
|
||||
import org.apache.activemq.command.ActiveMQBlobMessage;
|
||||
import org.apache.activemq.command.ActiveMQBytesMessage;
|
||||
import org.apache.activemq.command.ActiveMQMapMessage;
|
||||
import org.apache.activemq.command.ActiveMQMessage;
|
||||
import org.apache.activemq.command.ActiveMQObjectMessage;
|
||||
import org.apache.activemq.command.ActiveMQStreamMessage;
|
||||
import org.apache.activemq.command.ActiveMQTextMessage;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class OpenTypeSupport {
|
||||
|
||||
|
@ -239,6 +239,11 @@ public final class OpenTypeSupport {
|
|||
Set<Map.Entry<String,Object>> entries = m.getProperties().entrySet();
|
||||
for (Map.Entry<String, Object> entry : entries) {
|
||||
Object value = entry.getValue();
|
||||
if (value instanceof UTF8Buffer && valueType.equals(String.class)) {
|
||||
String actual = value.toString();
|
||||
CompositeDataSupport compositeData = createTabularRowValue(type, entry.getKey(), actual);
|
||||
answer.put(compositeData);
|
||||
}
|
||||
if (valueType.isInstance(value)) {
|
||||
CompositeDataSupport compositeData = createTabularRowValue(type, entry.getKey(), value);
|
||||
answer.put(compositeData);
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
package org.apache.activemq.bugs;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.jms.Connection;
|
||||
import javax.jms.Destination;
|
||||
import javax.jms.JMSException;
|
||||
import javax.jms.Message;
|
||||
import javax.jms.MessageProducer;
|
||||
import javax.jms.Session;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
import javax.management.openmbean.TabularDataSupport;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.jmx.CompositeDataConstants;
|
||||
import org.apache.activemq.broker.jmx.QueueViewMBean;
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AMQ4530Test {
|
||||
|
||||
private static BrokerService brokerService;
|
||||
private static String TEST_QUEUE = "testQueue";
|
||||
private static ActiveMQQueue queue = new ActiveMQQueue(TEST_QUEUE);
|
||||
private static String BROKER_ADDRESS = "tcp://localhost:0";
|
||||
private static String KEY = "testproperty";
|
||||
private static String VALUE = "propvalue";
|
||||
|
||||
private ActiveMQConnectionFactory connectionFactory;
|
||||
private String connectionUri;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
brokerService = new BrokerService();
|
||||
brokerService.setPersistent(false);
|
||||
brokerService.setUseJmx(true);
|
||||
connectionUri = brokerService.addConnector(BROKER_ADDRESS).getPublishableConnectString();
|
||||
brokerService.start();
|
||||
brokerService.waitUntilStarted();
|
||||
|
||||
connectionFactory = new ActiveMQConnectionFactory(connectionUri);
|
||||
sendMessage();
|
||||
}
|
||||
|
||||
public void sendMessage() throws Exception {
|
||||
final Connection conn = connectionFactory.createConnection();
|
||||
try {
|
||||
conn.start();
|
||||
final Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
final Destination queue = session.createQueue(TEST_QUEUE);
|
||||
final Message toSend = session.createMessage();
|
||||
toSend.setStringProperty(KEY, VALUE);
|
||||
final MessageProducer producer = session.createProducer(queue);
|
||||
producer.send(queue, toSend);
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
brokerService.stop();
|
||||
brokerService.waitUntilStopped();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testStringPropertiesFromCompositeData() throws Exception {
|
||||
final QueueViewMBean queueView = getProxyToQueueViewMBean();
|
||||
final CompositeData message = queueView.browse()[0];
|
||||
assertNotNull(message);
|
||||
TabularDataSupport stringProperties = (TabularDataSupport) message.get(CompositeDataConstants.STRING_PROPERTIES);
|
||||
assertNotNull(stringProperties);
|
||||
assertThat(stringProperties.size(), is(greaterThan(0)));
|
||||
Map.Entry<Object, Object> compositeDataEntry = (Map.Entry<Object, Object>) stringProperties.entrySet().toArray()[0];
|
||||
CompositeData stringEntry = (CompositeData) compositeDataEntry.getValue();
|
||||
assertThat(String.valueOf(stringEntry.get("key")), equalTo(KEY));
|
||||
assertThat(String.valueOf(stringEntry.get("value")), equalTo(VALUE));
|
||||
}
|
||||
|
||||
private QueueViewMBean getProxyToQueueViewMBean() throws MalformedObjectNameException, NullPointerException,
|
||||
JMSException {
|
||||
final ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + queue.getQueueName());
|
||||
final QueueViewMBean proxy = (QueueViewMBean) brokerService.getManagementContext().newProxyInstance(
|
||||
queueViewMBeanName, QueueViewMBean.class, true);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
}
|
|
@ -70,6 +70,7 @@ public class ActiveMQMessageTest extends TestCase {
|
|||
/*
|
||||
* @see TestCase#setUp()
|
||||
*/
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
this.jmsMessageID = "testid";
|
||||
|
@ -92,6 +93,7 @@ public class ActiveMQMessageTest extends TestCase {
|
|||
/*
|
||||
* @see TestCase#tearDown()
|
||||
*/
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
}
|
||||
|
@ -432,18 +434,22 @@ public class ActiveMQMessageTest extends TestCase {
|
|||
|
||||
public void testConvertProperties() throws Exception {
|
||||
org.apache.activemq.command.Message msg = new org.apache.activemq.command.Message() {
|
||||
@Override
|
||||
public org.apache.activemq.command.Message copy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeMarshall(WireFormat wireFormat) throws IOException {
|
||||
super.beforeMarshall(wireFormat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getDataStructureType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response visit(CommandVisitor visitor) throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
@ -455,6 +461,11 @@ public class ActiveMQMessageTest extends TestCase {
|
|||
@Override
|
||||
public void storeContent() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeContentAndClear() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
msg.setProperty("stringProperty", "string");
|
||||
|
@ -630,7 +641,7 @@ public class ActiveMQMessageTest extends TestCase {
|
|||
public void testIntPropertyConversion() throws JMSException {
|
||||
ActiveMQMessage msg = new ActiveMQMessage();
|
||||
String propertyName = "property";
|
||||
msg.setIntProperty(propertyName, (int)1);
|
||||
msg.setIntProperty(propertyName, 1);
|
||||
|
||||
assertEquals(((Integer)msg.getObjectProperty(propertyName)).intValue(), 1);
|
||||
assertEquals(msg.getIntProperty(propertyName), 1);
|
||||
|
|
Loading…
Reference in New Issue