karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf git commit: [KARAF-3430] Add username and password in the generated ActiveMQ connection factory blueprint XML. Fix ActiveMQ pool import Add itests about jms feature
Date Sun, 04 Jan 2015 06:54:26 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-2.x 09cb9e8f0 -> 21e0eaec0


[KARAF-3430] Add username and password in the generated ActiveMQ connection factory blueprint
XML.
Fix ActiveMQ pool import
Add itests about jms feature


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/21e0eaec
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/21e0eaec
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/21e0eaec

Branch: refs/heads/karaf-2.x
Commit: 21e0eaec0a83c6ec6e6bd5b8659f2427d6e412ee
Parents: 09cb9e8
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Sun Jan 4 07:53:45 2015 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Sun Jan 4 07:53:45 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/karaf/itests/JmsTest.java   | 121 +++++++++++++++++++
 jms/command/pom.xml                             |   1 +
 .../apache/karaf/jms/command/CreateCommand.java |   8 +-
 jms/core/pom.xml                                |   1 +
 .../java/org/apache/karaf/jms/JmsMBean.java     |  10 ++
 .../java/org/apache/karaf/jms/JmsService.java   |  12 ++
 .../apache/karaf/jms/internal/JmsMBeanImpl.java |   8 ++
 .../karaf/jms/internal/JmsServiceImpl.java      |  10 +-
 .../jms/internal/connectionfactory-activemq.xml |   2 +
 9 files changed, 170 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/21e0eaec/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/JmsTest.java b/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
new file mode 100644
index 0000000..66ab608
--- /dev/null
+++ b/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed 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.karaf.itests;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import java.net.URI;
+import java.util.List;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class JmsTest extends KarafTestSupport {
+
+    @Before
+    public void installJmsFeatureAndActiveMQBroker() throws Exception {
+        installAndAssertFeature("jms");
+        featuresService.addRepository(new URI("mvn:org.apache.activemq/activemq-karaf/5.10.0/xml/features"));
+        installAndAssertFeature("activemq-broker-noweb");
+    }
+
+    @Test
+    public void testCommands() throws Exception {
+        // jms:create command
+        System.out.println(executeCommand("jms:create -t ActiveMQ -u karaf -p karaf --url
tcp://localhost:61616 test"));
+        // give time to fileinstall to load the blueprint file
+        Thread.sleep(5000);
+        // jms:connectionfactories command
+        String connectionFactories = executeCommand("jms:connectionfactories");
+        System.out.println(connectionFactories);
+        assertTrue(connectionFactories.contains("jms/test"));
+        // jms:info command
+        String info = executeCommand("jms:info test");
+        System.out.println(info);
+        assertTrue(info.contains("ActiveMQ"));
+        assertTrue(info.contains("5.10.0"));
+        // jms:send command
+        System.out.println(executeCommand("jms:send test queue message"));
+        // jms:count command
+        String count = executeCommand("jms:count test queue");
+        System.out.println(count);
+        assertTrue(count.contains("1"));
+        // jms:consume command
+        String consumed = executeCommand("jms:consume test queue");
+        System.out.println(consumed);
+        assertTrue(consumed.contains("1 message"));
+        // jms:send & jms:move commands
+        System.out.print(executeCommand("jms:send test queue message"));
+        String move = executeCommand("jms:move test queue other");
+        System.out.println(move);
+        assertTrue(move.contains("1 message"));
+        // jms:queues command
+        String queues = executeCommand("jms:queues test");
+        System.out.println(queues);
+        assertTrue(queues.contains("queue"));
+        assertTrue(queues.contains("other"));
+        // jms:browse command
+        String browse = executeCommand("jms:browse test other");
+        System.out.println(browse);
+        assertTrue(browse.contains("message"));
+        assertTrue(browse.contains("queue://other"));
+        // jms:consume command
+        System.out.println(executeCommand("jms:consume test other"));
+        // jms:delete command
+        System.out.println(executeCommand("jms:delete test"));
+        // jms:connectionfactories command
+        connectionFactories = executeCommand("jms:connectionfactories");
+        System.out.println(connectionFactories);
+    }
+
+    @Test
+    public void testMBean() throws Exception {
+        JMXConnector connector = null;
+        try {
+            connector = this.getJMXConnector();
+            MBeanServerConnection connection = connector.getMBeanServerConnection();
+            ObjectName name = new ObjectName("org.apache.karaf:type=jms,name=root");
+            // create operation
+            connection.invoke(name, "create", new String[]{ "testMBean", "activemq", "tcp://localhost:61616",
"karaf", "karaf" }, new String[]{ "java.lang.String", "java.lang.String", "java.lang.String",
"java.lang.String", "java.lang.String" });
+            Thread.sleep(5000);
+            List<String> connectionFactories = (List<String>) connection.getAttribute(name,
"Connectionfactories");
+            assertEquals(true, connectionFactories.size() >= 1);
+            // send operation
+            connection.invoke(name, "send", new String[]{ "testMBean", "queueMBean", "message",
null, "karaf", "karaf" }, new String[]{ "java.lang.String", "java.lang.String", "java.lang.String",
"java.lang.String", "java.lang.String", "java.lang.String"});
+            // count operation
+            Integer count = (Integer) connection.invoke(name, "count", new String[]{ "testMBean",
"queueMBean", "karaf", "karaf" }, new String[]{ "java.lang.String", "java.lang.String", "java.lang.String",
"java.lang.String"});
+            assertEquals(1, count.intValue());
+            // queues operation
+            List<String> queues = (List<String>) connection.invoke(name, "queues",
new String[]{ "testMBean", "karaf", "karaf" }, new String[]{ "java.lang.String", "java.lang.String",
"java.lang.String"});
+            assertTrue(queues.size() >= 1);
+            // delete operation
+            connection.invoke(name, "delete", new String[]{ "testMBean" }, new String[]{
"java.lang.String" });
+        } finally {
+            if (connector != null) {
+                connector.close();
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/21e0eaec/jms/command/pom.xml
----------------------------------------------------------------------
diff --git a/jms/command/pom.xml b/jms/command/pom.xml
index 8f544b7..74998aa 100644
--- a/jms/command/pom.xml
+++ b/jms/command/pom.xml
@@ -83,6 +83,7 @@
                             org.apache.karaf.shell.console,
                             *
                         </Import-Package>
+                        <DynamicImport-Package>*</DynamicImport-Package>
                     </instructions>
                 </configuration>
             </plugin>

http://git-wip-us.apache.org/repos/asf/karaf/blob/21e0eaec/jms/command/src/main/java/org/apache/karaf/jms/command/CreateCommand.java
----------------------------------------------------------------------
diff --git a/jms/command/src/main/java/org/apache/karaf/jms/command/CreateCommand.java b/jms/command/src/main/java/org/apache/karaf/jms/command/CreateCommand.java
index 5c00466..2cfe235 100644
--- a/jms/command/src/main/java/org/apache/karaf/jms/command/CreateCommand.java
+++ b/jms/command/src/main/java/org/apache/karaf/jms/command/CreateCommand.java
@@ -32,8 +32,14 @@ public class CreateCommand extends JmsCommandSupport {
     @Option(name = "-u", aliases = { "--url" }, description = "The JMS URL. NB: for WebsphereMQ
type, the URL is hostname/port/queuemanager/channel", required = true, multiValued = false)
     String url;
 
+    @Option(name = "-u", aliases = { "--username" }, description = "Username to connect to
the JMS broker", required = false, multiValued = false)
+    String username = "karaf";
+
+    @Option(name = "-p", aliases = { "--password" }, description = "Password to connect to
the JMS broker", required = false, multiValued = false)
+    String password = "karaf";
+
     public Object doExecute() throws Exception {
-        getJmsService().create(name, type, url);
+        getJmsService().create(name, type, url, username, password);
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/21e0eaec/jms/core/pom.xml
----------------------------------------------------------------------
diff --git a/jms/core/pom.xml b/jms/core/pom.xml
index 857f097..4d57f4f 100644
--- a/jms/core/pom.xml
+++ b/jms/core/pom.xml
@@ -91,6 +91,7 @@
                         <Private-Package>
                             org.apache.karaf.jms.internal
                         </Private-Package>
+                        <DynamicImport-Package>*</DynamicImport-Package>
                     </instructions>
                 </configuration>
             </plugin>

http://git-wip-us.apache.org/repos/asf/karaf/blob/21e0eaec/jms/core/src/main/java/org/apache/karaf/jms/JmsMBean.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/JmsMBean.java b/jms/core/src/main/java/org/apache/karaf/jms/JmsMBean.java
index 8540b86..8fb69c7 100644
--- a/jms/core/src/main/java/org/apache/karaf/jms/JmsMBean.java
+++ b/jms/core/src/main/java/org/apache/karaf/jms/JmsMBean.java
@@ -45,6 +45,16 @@ public interface JmsMBean {
     void create(String name, String type, String url) throws MBeanException;
 
     /**
+     * Create a JMS connection factory.
+     *
+     * @param name the JMS connection factory name.
+     * @param type the JMS connection factory type (ActiveMQ or WebsphereMQ).
+     * @param url the JMS connection factory URL. NB: when type is WebsphereMQ, the URL has
the format host/port/queuemanager/channel.
+     * @throws MBeanException
+     */
+    void create(String name, String type, String url, String username, String password) throws
MBeanException;
+
+    /**
      * Delete a JMS connection factory.
      *
      * @param name the JMS connection factory name.

http://git-wip-us.apache.org/repos/asf/karaf/blob/21e0eaec/jms/core/src/main/java/org/apache/karaf/jms/JmsService.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/JmsService.java b/jms/core/src/main/java/org/apache/karaf/jms/JmsService.java
index 8aa970f..31cd492 100644
--- a/jms/core/src/main/java/org/apache/karaf/jms/JmsService.java
+++ b/jms/core/src/main/java/org/apache/karaf/jms/JmsService.java
@@ -46,6 +46,18 @@ public interface JmsService {
      * @param name the JMS connection factory name.
      * @param type the JMS connection factory type (ActiveMQ, WebsphereMQ, ...).
      * @param url the JMS URL to use.
+     * @param username the JMS connection factory authentication username.
+     * @param password the JMS connection factory authentication password.
+     * @throws Exception
+     */
+    void create(String name, String type, String url, String username, String password) throws
Exception;
+
+    /**
+     * Create a new JMS connection factory.
+     *
+     * @param name the JMS connection factory name.
+     * @param type the JMS connection factory type (ActiveMQ, WebsphereMQ, ...).
+     * @param url the JMS URL to use.
      * @throws Exception
      */
     void create(String name, String type, String url) throws Exception;

http://git-wip-us.apache.org/repos/asf/karaf/blob/21e0eaec/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java b/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java
index 511b690..85fc385 100644
--- a/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java
+++ b/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsMBeanImpl.java
@@ -54,6 +54,14 @@ public class JmsMBeanImpl extends StandardMBean implements JmsMBean {
         }
     }
 
+    public void create(String name, String type, String url, String username, String password)
throws MBeanException {
+        try {
+            jmsService.create(name, type, url, username, password);
+        } catch (Throwable t) {
+            throw new MBeanException(null, t.getMessage());
+        }
+    }
+
     public void delete(String name) throws MBeanException {
         try {
             jmsService.delete(name);

http://git-wip-us.apache.org/repos/asf/karaf/blob/21e0eaec/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java
----------------------------------------------------------------------
diff --git a/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java b/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java
index bf31704..252a039 100644
--- a/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java
+++ b/jms/core/src/main/java/org/apache/karaf/jms/internal/JmsServiceImpl.java
@@ -39,20 +39,22 @@ public class JmsServiceImpl implements JmsService {
 
     private BundleContext bundleContext;
 
-    public void create(String name, String type, String url) throws Exception {
+    public void create(String name, String type, String url, String username, String password)
throws Exception {
         if (!type.equalsIgnoreCase("activemq") && !type.equalsIgnoreCase("webspheremq"))
{
             throw new IllegalArgumentException("JMS connection factory type not known");
         }
 
         File karafBase = new File(System.getProperty("karaf.base"));
         File deployFolder = new File(karafBase, "deploy");
-        File  outFile = new File(deployFolder, "connectionfactory-" + name + ".xml");
+        File outFile = new File(deployFolder, "connectionfactory-" + name + ".xml");
 
         if (type.equalsIgnoreCase("activemq")) {
             // activemq
             HashMap<String, String> properties = new HashMap<String, String>();
             properties.put("${name}", name);
             properties.put("${url}", url);
+            properties.put("${username}", username);
+            properties.put("${password}", password);
             copyDataSourceFile(outFile, "connectionfactory-activemq.xml", properties);
         } else {
             // webspheremq
@@ -70,6 +72,10 @@ public class JmsServiceImpl implements JmsService {
         }
     }
 
+    public void create(String name, String type, String url) throws Exception {
+        create(name, type, url, null, null);
+    }
+
     public void delete(String name) throws Exception {
         File karafBase = new File(System.getProperty("karaf.base"));
         File deployFolder = new File(karafBase, "deploy");

http://git-wip-us.apache.org/repos/asf/karaf/blob/21e0eaec/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
----------------------------------------------------------------------
diff --git a/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
b/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
index 53d73cc..1750283 100644
--- a/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
+++ b/jms/core/src/main/resources/org/apache/karaf/jms/internal/connectionfactory-activemq.xml
@@ -19,6 +19,8 @@
 
     <bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
         <property name="brokerURL" value="${url}" />
+        <property name="userName" value="${username}" />
+        <property name="password" value="${password}" />
     </bean>
 
     <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">


Mime
View raw message