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: https://issues.apache.org/jira/browse/AMQCLI-2
Date Tue, 07 Feb 2017 18:51:14 GMT
Repository: activemq-cli-tools
Updated Branches:
  refs/heads/master a5ad7747e -> 796d90177


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

Adding the first version of JAXB classes generated from the Artemis
import schema.  There is also a marshaller class and unit test to
demonstrate streaming to an XML file when marshalling instead of writing
the entire file at once. This will need some work but is a good starting
point.

Also Artemis is currently a SNAPSHOT dependency as we need to work off
the newest code in master.


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/796d9017
Tree: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/tree/796d9017
Diff: http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/diff/796d9017

Branch: refs/heads/master
Commit: 796d90177c31746b7451617949defb362c46404e
Parents: a5ad774
Author: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Authored: Tue Feb 7 13:46:55 2017 -0500
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
Committed: Tue Feb 7 13:46:55 2017 -0500

----------------------------------------------------------------------
 activemq-kahadb-exporter/pom.xml                |  94 ++++++++++++++-
 .../schema/ArtemisJournalMarshaller.java        | 100 ++++++++++++++++
 .../main/resources/artemis-import-export.xjb    |  36 ++++++
 .../schema/ArtemisJournalMarshallerTest.java    | 120 +++++++++++++++++++
 pom.xml                                         |  23 +++-
 5 files changed, 369 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/796d9017/activemq-kahadb-exporter/pom.xml
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/pom.xml b/activemq-kahadb-exporter/pom.xml
index 45e8e81..9335e2e 100644
--- a/activemq-kahadb-exporter/pom.xml
+++ b/activemq-kahadb-exporter/pom.xml
@@ -15,7 +15,8 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <parent>
     <groupId>org.apache.activemq</groupId>
     <artifactId>activemq-cli-tools</artifactId>
@@ -31,7 +32,6 @@
     <dependency>
       <groupId>org.apache.activemq</groupId>
       <artifactId>activemq-kahadb-store</artifactId>
-      <version>${activemq-version}</version>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
@@ -47,7 +47,95 @@
 
   <build>
     <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>unpack-client</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>unpack</goal>
+            </goals>
+            <configuration>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.apache.activemq</groupId>
+                  <artifactId>artemis-cli</artifactId>
+                  <version>${artemis-version}</version>
+                  <type>jar</type>
+                  <overWrite>true</overWrite>
+                  <outputDirectory>${project.build.directory}/artemis-cli</outputDirectory>
+                </artifactItem>
+              </artifactItems>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-resources-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>copy-resources</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>copy-resources</goal>
+            </goals>
+            <configuration>
+              <outputDirectory>${project.build.directory}/artemis-cli/schema</outputDirectory>
+              <resources>
+                <resource>
+                  <directory>${project.basedir}/src/main/resources</directory>
+                  <includes>
+                    <include>artemis-import-export.xjb</include>
+                  </includes>
+                  <filtering>false</filtering>
+                </resource>
+              </resources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>jaxb2-maven-plugin</artifactId>
+        <version>${jaxb2-maven-plugin-version}</version>
+        <executions>
+          <execution>
+            <id>xjc</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>xjc</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <xjbSources>
+            <xjbSource>${project.build.directory}/artemis-cli/schema/artemis-import-export.xjb</xjbSource>
+          </xjbSources>
+          <sources>
+            <source>${project.build.directory}/artemis-cli/schema/artemis-import-export.xsd</source>
+          </sources>
+          <packageName>org.apache.activemq.cli.schema</packageName>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>add-source</goal>
+            </goals>
+            <configuration>
+              <sources>
+                <source>${project.build.directory}/generated-sources/jaxb</source>
+              </sources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
-
 </project>

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/796d9017/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
new file mode 100644
index 0000000..82e167b
--- /dev/null
+++ b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/artemis/schema/ArtemisJournalMarshaller.java
@@ -0,0 +1,100 @@
+/**
+ * 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.cli.artemis.schema;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.activemq.cli.schema.ActivemqJournalType;
+import org.apache.activemq.cli.schema.AddressBindingType;
+import org.apache.activemq.cli.schema.MessageType;
+import org.apache.activemq.cli.schema.ObjectFactory;
+import org.apache.activemq.cli.schema.QueueBindingType;
+
+/**
+ * Marshaller class to stream to a file
+ */
+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;
+    private final XMLStreamWriter xmlWriter;
+    //Used for journal start
+    final JAXBElement<ActivemqJournalType> journalElement =
+            factory.createActivemqJournal(new ActivemqJournalType());
+
+    public ArtemisJournalMarshaller(final XMLStreamWriter xmlWriter) throws JAXBException
{
+        this.context = JAXBContext.newInstance(ObjectFactory.class);
+        this.marshaller = context.createMarshaller();
+        this.marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
+        this.xmlWriter = xmlWriter;
+    }
+
+    public void appendJournalOpen() throws XMLStreamException {
+        xmlWriter.writeStartDocument();
+        xmlWriter.writeStartElement(journalElement.getName().toString());
+    }
+
+    public void appendJournalClose(boolean closeWriter) throws XMLStreamException {
+        xmlWriter.writeEndDocument();
+        if (closeWriter) {
+            xmlWriter.flush();
+            xmlWriter.close();
+        }
+    }
+
+    public void appendMessagesElement() throws XMLStreamException {
+        xmlWriter.writeStartElement(MESSAGES_ELEMENT);
+    }
+
+    public void appendBindingsElement() throws XMLStreamException {
+        xmlWriter.writeStartElement(BINDINGS_ELEMENT);
+    }
+
+    public void appendEndElement() throws XMLStreamException {
+        xmlWriter.writeEndElement();
+    }
+
+    public void appendMessage(final MessageType message) throws JAXBException {
+        marshaller.marshal(wrap(MESSAGE_ELEMENT, message), xmlWriter);
+    }
+
+    public void appendBinding(final AddressBindingType addressBinding) throws JAXBException
{
+        marshaller.marshal(wrap(ADDRESS_BINDING_ELEMENT, addressBinding), xmlWriter);
+    }
+
+    public void appendBinding(final QueueBindingType queueBinding) throws JAXBException {
+        marshaller.marshal(wrap(QUEUE_BINDING_ELEMENT, queueBinding), xmlWriter);
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> JAXBElement<T> wrap(String name, T object) {
+        return new JAXBElement<T>(QName.valueOf(name), (Class<T>) object.getClass(),
object);
+    }
+}

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/796d9017/activemq-kahadb-exporter/src/main/resources/artemis-import-export.xjb
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/main/resources/artemis-import-export.xjb b/activemq-kahadb-exporter/src/main/resources/artemis-import-export.xjb
new file mode 100644
index 0000000..079eeb9
--- /dev/null
+++ b/activemq-kahadb-exporter/src/main/resources/artemis-import-export.xjb
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
+  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  extensionBindingPrefixes="xjc annox"
+  xmlns:annox="http://annox.dev.java.net" version="2.1">
+  <bindings schemaLocation="artemis-import-export.xsd" version="1.0">
+
+    <!-- Customize the package name -->
+    <schemaBindings>
+      <package name="org.apache.activemq.schema" />
+    </schemaBindings>
+
+    <!-- There is already a value field so map the value attribute to a new name -->
+    <bindings node="//xs:complexType[@name='propertyType']">
+      <bindings node=".//xs:attribute[@name='value']">
+        <property name="valueAttribute" />
+      </bindings>
+    </bindings>
+  </bindings>
+</bindings>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/796d9017/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/artemis/schema/ArtemisJournalMarshallerTest.java
----------------------------------------------------------------------
diff --git a/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/artemis/schema/ArtemisJournalMarshallerTest.java
b/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/artemis/schema/ArtemisJournalMarshallerTest.java
new file mode 100644
index 0000000..e96422f
--- /dev/null
+++ b/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/artemis/schema/ArtemisJournalMarshallerTest.java
@@ -0,0 +1,120 @@
+/**
+ * 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.cli.artemis.schema;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.activemq.cli.artemis.schema.ArtemisJournalMarshaller;
+import org.apache.activemq.cli.schema.ActivemqJournalType;
+import org.apache.activemq.cli.schema.AddressBindingType;
+import org.apache.activemq.cli.schema.MessageType;
+import org.apache.activemq.cli.schema.MessagesType;
+import org.apache.activemq.cli.schema.ObjectFactory;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class ArtemisJournalMarshallerTest {
+
+    @Rule
+    public TemporaryFolder tempFolder = new TemporaryFolder();
+
+    /**
+     * Test default marshaling of entire document at once
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testFullMarshal() throws Exception {
+
+        ObjectFactory factory = new ObjectFactory();
+
+        ActivemqJournalType journal = new ActivemqJournalType();
+        MessagesType messages = factory.createMessagesType();
+        for (int i = 0; i < 3; i++) {
+            MessageType message = factory.createMessageType();
+            message.setId((long) i);
+            messages.getMessage().add(message);
+        }
+        journal.setMessages(messages);
+
+        JAXBContext context = JAXBContext.newInstance(ActivemqJournalType.class);
+        Marshaller m = context.createMarshaller();
+        m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
+
+        File file = tempFolder.newFile();
+        JAXBElement<ActivemqJournalType> element = factory.createActivemqJournal(journal);
+        m.marshal(element, file);
+        validate(file);
+    }
+
+    /**
+     * Test stream marshal by appending one message at a time
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testStreamMarshal() throws Exception {
+        File file = tempFolder.newFile();
+
+        try(FileOutputStream fos = new FileOutputStream(file)) {
+            XMLStreamWriter xmlWriter = XMLOutputFactory.newFactory().createXMLStreamWriter(fos);
+            ArtemisJournalMarshaller xmlMarshaller = new ArtemisJournalMarshaller(xmlWriter);
+
+            xmlMarshaller.appendJournalOpen();
+            xmlMarshaller.appendBindingsElement();
+            xmlMarshaller.appendBinding(new AddressBindingType());
+            xmlMarshaller.appendEndElement();
+            xmlMarshaller.appendMessagesElement();
+
+            //Marshal messages one at a time
+            for (int i = 0; i < 3; i++) {
+                MessageType message = new MessageType();
+                message.setId((long) i);
+                message.setTimestamp(System.currentTimeMillis());
+                xmlMarshaller.appendMessage(message);
+            }
+
+            xmlMarshaller.appendEndElement();
+            xmlMarshaller.appendJournalClose(true);
+        }
+
+        //This can be read as a stream as well but for the purpose of this test
+        //just read the whole thing in at once
+        validate(file);
+    }
+
+    @SuppressWarnings("unchecked")
+    private void validate(File file) throws JAXBException {
+        JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
+        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
+        JAXBElement<ActivemqJournalType> read = (JAXBElement<ActivemqJournalType>)
jaxbUnmarshaller.unmarshal(file);
+        assertEquals(3, read.getValue().getMessages().getMessage().size());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-cli-tools/blob/796d9017/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5c56c3c..8be5dd3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,8 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
   <parent>
     <groupId>org.apache</groupId>
@@ -37,10 +38,15 @@
     <maven.compiler.target>1.8</maven.compiler.target>
 
     <activemq-version>5.14.3</activemq-version>
+    <artemis-version>2.0.0-SNAPSHOT</artemis-version>
 
     <!-- Test dependency versions -->
     <junit-version>4.12</junit-version>
     <mockito-version>1.10.19</mockito-version>
+    
+    <!-- Maven Plugins -->
+    <jaxb2-maven-plugin-version>2.2</jaxb2-maven-plugin-version>
+    <build-helper-plugin-version>3.0.0</build-helper-plugin-version>
   </properties>
 
   <url>http://activemq.apache.org</url>
@@ -61,6 +67,21 @@
 
   <dependencyManagement>
     <dependencies>
+
+      <!-- ActiveMQ -->
+      <dependency>
+        <groupId>org.apache.activemq</groupId>
+        <artifactId>activemq-kahadb-store</artifactId>
+        <version>${activemq-version}</version>
+      </dependency>
+
+      <!-- Artemis -->
+      <dependency>
+        <groupId>org.apache.activemq</groupId>
+        <artifactId>artemis-cli</artifactId>
+        <version>${artemis-version}</version>
+      </dependency>
+
       <!-- Test dependencies -->
       <dependency>
         <groupId>junit</groupId>


Mime
View raw message