From d4790f00ba6c7a5f4c99145df0c40c72bed1e5a3 Mon Sep 17 00:00:00 2001 From: Andy Taylor Date: Tue, 14 Feb 2017 13:29:27 +0000 Subject: [PATCH] ARTEMIS-962 - improve the OpenMBean support for browsing https://issues.apache.org/jira/browse/ARTEMIS-962 --- .../management/impl/QueueControlImpl.java | 6 +- .../openmbean/CompositeDataConstants.java | 3 +- .../impl/openmbean/OpenTypeSupport.java | 73 +++++++++++++++---- 3 files changed, 66 insertions(+), 16 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java index 1aa6206ede..4b84909941 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java @@ -746,7 +746,11 @@ public class QueueControlImpl extends AbstractControl implements QueueControl { message.setDurable(durable); message.setTimestamp(System.currentTimeMillis()); if (body != null) { - message.getBodyBuffer().writeBytes(Base64.decode(body)); + if (type == Message.TEXT_TYPE) { + message.getBodyBuffer().writeNullableSimpleString(new SimpleString(body)); + } else { + message.getBodyBuffer().writeBytes(Base64.decode(body)); + } } message.setAddress(queue.getAddress()); ByteBuffer buffer = ByteBuffer.allocate(8); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/openmbean/CompositeDataConstants.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/openmbean/CompositeDataConstants.java index 6d85d893ee..d9d70155b1 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/openmbean/CompositeDataConstants.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/openmbean/CompositeDataConstants.java @@ -27,7 +27,8 @@ public interface CompositeDataConstants { String PRIORITY = "priority"; String REDELIVERED = "redelivered"; String TIMESTAMP = "timestamp"; - String BODY = "body"; + String BODY = "BodyPreview"; + String TEXT_BODY = "text"; String PROPERTIES = "PropertiesText"; String ADDRESS_DESCRIPTION = "The Address"; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/openmbean/OpenTypeSupport.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/openmbean/OpenTypeSupport.java index 41e26327b3..ec6848b12f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/openmbean/OpenTypeSupport.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/openmbean/OpenTypeSupport.java @@ -35,17 +35,32 @@ import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.core.server.MessageReference; +import org.apache.activemq.artemis.core.server.ServerMessage; public final class OpenTypeSupport { - private static MessageOpenTypeFactory FACTORY = new MessageOpenTypeFactory(); + private static MessageOpenTypeFactory TEXT_FACTORY = new TextMessageOpenTypeFactory(); + private static MessageOpenTypeFactory BYTES_FACTORY = new BytesMessageOpenTypeFactory(); private OpenTypeSupport() { } public static CompositeData convert(MessageReference ref) throws OpenDataException { - CompositeType ct = FACTORY.getCompositeType(); - Map fields = FACTORY.getFields(ref); + CompositeType ct; + + Map fields; + byte type = ref.getMessage().getType(); + + switch(type) { + case Message.TEXT_TYPE: + ct = TEXT_FACTORY.getCompositeType(); + fields = TEXT_FACTORY.getFields(ref); + break; + default: + ct = BYTES_FACTORY.getCompositeType(); + fields = BYTES_FACTORY.getFields(ref); + break; + } return new CompositeDataSupport(ct, fields); } @@ -65,8 +80,6 @@ public final class OpenTypeSupport { protected TabularType floatPropertyTabularType; protected TabularType doublePropertyTabularType; - protected ArrayType body; - protected String getTypeName() { return Message.class.getName(); } @@ -103,10 +116,6 @@ public final class OpenTypeSupport { floatPropertyTabularType = createTabularType(Float.class, SimpleType.FLOAT); doublePropertyTabularType = createTabularType(Double.class, SimpleType.DOUBLE); - body = new ArrayType(SimpleType.BYTE, true); - - addItem(CompositeDataConstants.BODY, CompositeDataConstants.BODY_DESCRIPTION, body); - addItem(CompositeDataConstants.STRING_PROPERTIES, CompositeDataConstants.STRING_PROPERTIES_DESCRIPTION, stringPropertyTabularType); addItem(CompositeDataConstants.BOOLEAN_PROPERTIES, CompositeDataConstants.BOOLEAN_PROPERTIES_DESCRIPTION, booleanPropertyTabularType); addItem(CompositeDataConstants.BYTE_PROPERTIES, CompositeDataConstants.BYTE_PROPERTIES_DESCRIPTION, bytePropertyTabularType); @@ -134,11 +143,6 @@ public final class OpenTypeSupport { rc.put(CompositeDataConstants.PRIORITY, m.getPriority()); rc.put(CompositeDataConstants.REDELIVERED, ref.getDeliveryCount() > 1); - ActiveMQBuffer bodyCopy = m.getBodyBufferDuplicate(); - byte[] bytes = new byte[bodyCopy.readableBytes()]; - bodyCopy.readBytes(bytes); - rc.put(CompositeDataConstants.BODY, bytes); - Map propertyMap = m.toPropertyMap(); rc.put(CompositeDataConstants.PROPERTIES, "" + propertyMap); @@ -246,4 +250,45 @@ public final class OpenTypeSupport { } } + + static class BytesMessageOpenTypeFactory extends MessageOpenTypeFactory { + protected ArrayType body; + + @Override + protected void init() throws OpenDataException { + super.init(); + body = new ArrayType(SimpleType.BYTE, true); + addItem(CompositeDataConstants.BODY, CompositeDataConstants.BODY_DESCRIPTION, body); + } + + @Override + public Map getFields(MessageReference ref) throws OpenDataException { + Map rc = super.getFields(ref); + ServerMessage m = ref.getMessage(); + ActiveMQBuffer bodyCopy = m.getBodyBufferDuplicate(); + byte[] bytes = new byte[bodyCopy.readableBytes()]; + bodyCopy.readBytes(bytes); + rc.put(CompositeDataConstants.BODY, bytes); + return rc; + } + } + + static class TextMessageOpenTypeFactory extends MessageOpenTypeFactory { + protected SimpleType text; + + @Override + protected void init() throws OpenDataException { + super.init(); + addItem(CompositeDataConstants.TEXT_BODY, CompositeDataConstants.TEXT_BODY, SimpleType.STRING); + } + + @Override + public Map getFields(MessageReference ref) throws OpenDataException { + Map rc = super.getFields(ref); + ServerMessage m = ref.getMessage(); + SimpleString text = m.getBodyBuffer().copy().readNullableSimpleString(); + rc.put(CompositeDataConstants.TEXT_BODY, text != null ? text.toString() : ""); + return rc; + } + } }