AMQCLI-4 Using new common XML util class in Artemis
https://issues.apache.org/jira/browse/AMQCLI-4
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.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 @@
*/
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 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 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")
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 @@
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 @@
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 @@
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 @@
}
private QueuesType convertQueue(final Message message) throws JMSException {
-
return QueuesType.builder()
.withQueue(QueueType.builder()
.withName(message.getDestination().getPhysicalName()).build())
@@ -84,10 +74,7 @@
}
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 @@
.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();
+ .withPriority(message.getPriority())
+ .withType(XmlDataExporterUtil.getMessagePrettyType(message.getType())).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;
- }
-
- 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);
- }
-
}
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.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.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 @@
configuration.addAddressConfiguration(new CoreAddressConfiguration()
.setName("test.queue")
- .addRoutingType(RoutingType. ANYCAST)
+ .addRoutingType(RoutingType.ANYCAST)
.addQueueConfiguration(new CoreQueueConfiguration()
.setAddress("test.queue")
.setName("test.queue")