activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject activemq-cli-tools git commit: AMQCLI-4 Using new common XML util class in Artemis
Date Tue, 14 Feb 2017 19:51:23 GMT
Repository: activemq-cli-tools
Updated Branches:
  refs/heads/master 3fee126f1 -> 5b8a4b93c


AMQCLI-4 Using new common XML util class in Artemis

https://issues.apache.org/jira/browse/AMQCLI-4


Project: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/commit/5b8a4b93
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/tree/5b8a4b93
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/diff/5b8a4b93

Branch: refs/heads/master
Commit: 5b8a4b93cb5d5fc37710b6b5ecc55ffac0f14861
Parents: 3fee126
Author: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Authored: Tue Feb 14 14:49:34 2017 -0500
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Committed: Tue Feb 14 14:49:34 2017 -0500

----------------------------------------------------------------------
 .../schema/ArtemisJournalMarshaller.java        | 17 ++----
 .../artemis/OpenWireMessageTypeConverter.java   | 58 ++------------------
 .../cli/kahadb/exporter/ExporterTest.java       |  4 +-
 3 files changed, 14 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/5b8a4b93/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/artemis/schema/ArtemisJournalMarshaller.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/artemis/schema/ArtemisJournalMarshaller.java
b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/artemis/schema/ArtemisJournalMarshaller.java
index f1695e5..2fad01d 100644
--- a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/artemis/schema/ArtemisJournalMarshaller.java
+++ b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/artemis/schema/ArtemisJournalMarshaller.java
@@ -29,6 +29,7 @@ import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.activemq.artemis.cli.commands.tools.XmlDataConstants;
 import org.apache.activemq.cli.schema.ActivemqJournalType;
 import org.apache.activemq.cli.schema.AddressBindingType;
 import org.apache.activemq.cli.schema.MessageType;
@@ -40,12 +41,6 @@ import org.apache.activemq.cli.schema.QueueBindingType;
  */
 public class ArtemisJournalMarshaller {
 
-    public final static String MESSAGE_ELEMENT = "message";
-    public final static String MESSAGES_ELEMENT = "messages";
-    public final static String BINDINGS_ELEMENT = "bindings";
-    public final static String ADDRESS_BINDING_ELEMENT = "address-binding";
-    public final static String QUEUE_BINDING_ELEMENT = "queue-binding";
-
     private final ObjectFactory factory = new ObjectFactory();
     private final JAXBContext context;
     private final Marshaller marshaller;
@@ -77,11 +72,11 @@ public class ArtemisJournalMarshaller {
     }
 
     public void appendMessagesElement() throws XMLStreamException {
-        xmlWriter.writeStartElement(MESSAGES_ELEMENT);
+        xmlWriter.writeStartElement(XmlDataConstants.MESSAGES_PARENT);
     }
 
     public void appendBindingsElement() throws XMLStreamException {
-        xmlWriter.writeStartElement(BINDINGS_ELEMENT);
+        xmlWriter.writeStartElement(XmlDataConstants.BINDINGS_PARENT);
     }
 
     public void appendEndElement() throws XMLStreamException {
@@ -89,15 +84,15 @@ public class ArtemisJournalMarshaller {
     }
 
     public void appendMessage(final MessageType message) throws JAXBException {
-        marshaller.marshal(wrap(MESSAGE_ELEMENT, message), xmlWriter);
+        marshaller.marshal(wrap(XmlDataConstants.MESSAGES_CHILD, message), xmlWriter);
     }
 
     public void appendBinding(final AddressBindingType addressBinding) throws JAXBException
{
-        marshaller.marshal(wrap(ADDRESS_BINDING_ELEMENT, addressBinding), xmlWriter);
+        marshaller.marshal(wrap(XmlDataConstants.ADDRESS_BINDINGS_CHILD, addressBinding),
xmlWriter);
     }
 
     public void appendBinding(final QueueBindingType queueBinding) throws JAXBException {
-        marshaller.marshal(wrap(QUEUE_BINDING_ELEMENT, queueBinding), xmlWriter);
+        marshaller.marshal(wrap(XmlDataConstants.QUEUE_BINDINGS_CHILD, queueBinding), xmlWriter);
     }
 
     @SuppressWarnings("unchecked")

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/5b8a4b93/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/artemis/OpenWireMessageTypeConverter.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/artemis/OpenWireMessageTypeConverter.java
b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/artemis/OpenWireMessageTypeConverter.java
index 8d24e96..259decc 100644
--- a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/artemis/OpenWireMessageTypeConverter.java
+++ b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/artemis/OpenWireMessageTypeConverter.java
@@ -18,10 +18,9 @@ package org.apache.activemq.cli.kahadb.exporter.artemis;
 
 import javax.jms.JMSException;
 
-import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.cli.commands.tools.XmlDataExporterUtil;
 import org.apache.activemq.artemis.core.protocol.openwire.OpenWireMessageConverter;
 import org.apache.activemq.artemis.core.server.ServerMessage;
-import org.apache.activemq.artemis.utils.Base64;
 import org.apache.activemq.cli.kahadb.exporter.OpenWireExportConverter;
 import org.apache.activemq.cli.schema.BodyType;
 import org.apache.activemq.cli.schema.MessageType;
@@ -34,14 +33,6 @@ import org.apache.activemq.openwire.OpenWireFormat;
 
 public class OpenWireMessageTypeConverter implements OpenWireExportConverter<MessageType>
{
 
-    static final String MESSAGE_TIMESTAMP = "timestamp";
-    static final String DEFAULT_TYPE_PRETTY = "default";
-    static final String BYTES_TYPE_PRETTY = "bytes";
-    static final String MAP_TYPE_PRETTY = "map";
-    static final String OBJECT_TYPE_PRETTY = "object";
-    static final String STREAM_TYPE_PRETTY = "stream";
-    static final String TEXT_TYPE_PRETTY = "text";
-
     final OpenWireMessageConverter converter = new OpenWireMessageConverter(new OpenWireFormat());
 
     /* (non-Javadoc)
@@ -59,8 +50,8 @@ public class OpenWireMessageTypeConverter implements OpenWireExportConverter<Mes
                     Object value = serverMessage.getObjectProperty(key);
                     propertiesType.getProperty().add(PropertyType.builder()
                             .withName(key.toString())
-                            .withValueAttribute(convertPropertyValue(value))
-                            .withType(convertPropertyType(value.getClass()))
+                            .withValueAttribute(XmlDataExporterUtil.convertProperty(value))
+                            .withType(XmlDataExporterUtil.getPropertyType(value))
                             .build());
                 });
                 messageType.setProperties(propertiesType);
@@ -76,7 +67,6 @@ public class OpenWireMessageTypeConverter implements OpenWireExportConverter<Mes
     }
 
     private QueuesType convertQueue(final Message message) throws JMSException {
-
         return QueuesType.builder()
                 .withQueue(QueueType.builder()
                         .withName(message.getDestination().getPhysicalName()).build())
@@ -84,10 +74,7 @@ public class OpenWireMessageTypeConverter implements OpenWireExportConverter<Mes
     }
 
     private BodyType convertBody(final ServerMessage serverMessage) throws Exception {
-        int size = serverMessage.getEndOfBodyPosition() - serverMessage.getBodyBuffer().readerIndex();
-        byte[] buffer = new byte[size];
-        serverMessage.getBodyBuffer().readBytes(buffer);
-        String value = encode(buffer);
+        String value = XmlDataExporterUtil.encodeMessageBody(serverMessage);
 
         //requires CDATA
         return BodyType.builder()
@@ -95,46 +82,13 @@ public class OpenWireMessageTypeConverter implements OpenWireExportConverter<Mes
             .build();
     }
 
-    private String convertPropertyValue(Object value) {
-        if (value instanceof byte[]) {
-            return encode((byte[]) value).toString();
-        }
-        return value.toString();
-    }
-
     private MessageType convertAttributes(final ServerMessage message) {
         MessageType messageType = MessageType.builder()
                 .withId(message.getMessageID())
                 .withTimestamp(message.getTimestamp())
-                .withPriority(message.getPriority()).build();
-
-        byte rawType = message.getType();
-        String prettyType = DEFAULT_TYPE_PRETTY;
-        if (rawType == org.apache.activemq.artemis.api.core.Message.BYTES_TYPE) {
-           prettyType = BYTES_TYPE_PRETTY;
-        } else if (rawType == org.apache.activemq.artemis.api.core.Message.MAP_TYPE) {
-           prettyType = MAP_TYPE_PRETTY;
-        } else if (rawType == org.apache.activemq.artemis.api.core.Message.OBJECT_TYPE) {
-           prettyType = OBJECT_TYPE_PRETTY;
-        } else if (rawType == org.apache.activemq.artemis.api.core.Message.STREAM_TYPE) {
-           prettyType = STREAM_TYPE_PRETTY;
-        } else if (rawType == org.apache.activemq.artemis.api.core.Message.TEXT_TYPE) {
-           prettyType = TEXT_TYPE_PRETTY;
-        }
+                .withPriority(message.getPriority())
+                .withType(XmlDataExporterUtil.getMessagePrettyType(message.getType())).build();
 
-        messageType.setType(prettyType);
         return messageType;
     }
-
-    private String convertPropertyType(Class<?> clazz) {
-        if (clazz.equals(SimpleString.class)) {
-            return String.class.getSimpleName().toLowerCase();
-        }
-        return clazz.getSimpleName().toLowerCase();
-    }
-
-    private static String encode(final byte[] data) {
-        return Base64.encodeBytes(data, 0, data.length, Base64.DONT_BREAK_LINES | Base64.URL_SAFE);
-     }
-
 }

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/5b8a4b93/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterTest.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterTest.java
b/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterTest.java
index 84edb33..73bcecd 100644
--- a/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterTest.java
+++ b/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterTest.java
@@ -44,6 +44,7 @@ import javax.xml.bind.Unmarshaller;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.activemq.artemis.api.core.RoutingType;
 import org.apache.activemq.artemis.api.core.TransportConfiguration;
 import org.apache.activemq.artemis.cli.commands.tools.XmlDataImporter;
 import org.apache.activemq.artemis.core.config.Configuration;
@@ -53,7 +54,6 @@ import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
 import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory;
 import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
-import org.apache.activemq.artemis.core.server.RoutingType;
 import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl;
 import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.ConnectionContext;
@@ -272,7 +272,7 @@ public class ExporterTest {
 
         configuration.addAddressConfiguration(new CoreAddressConfiguration()
                 .setName("test.queue")
-                .addRoutingType(RoutingType. ANYCAST)
+                .addRoutingType(RoutingType.ANYCAST)
                 .addQueueConfiguration(new CoreQueueConfiguration()
                         .setAddress("test.queue")
                         .setName("test.queue")


Mime
View raw message