activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/5] activemq-6 git commit: Fix jms/embedded-simple example
Date Wed, 11 Mar 2015 23:15:57 GMT
Repository: activemq-6
Updated Branches:
  refs/heads/master dba926a1c -> 670f5841b


Fix jms/embedded-simple example


Project: http://git-wip-us.apache.org/repos/asf/activemq-6/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-6/commit/4b7eafdd
Tree: http://git-wip-us.apache.org/repos/asf/activemq-6/tree/4b7eafdd
Diff: http://git-wip-us.apache.org/repos/asf/activemq-6/diff/4b7eafdd

Branch: refs/heads/master
Commit: 4b7eafddc1cbaf87eb7eb06919bd1d928042e339
Parents: dba926a
Author: Howard Gao <hgao@redhat.com>
Authored: Tue Mar 10 21:28:07 2015 +0800
Committer: Howard Gao <hgao@redhat.com>
Committed: Wed Mar 11 16:50:52 2015 +0800

----------------------------------------------------------------------
 examples/jms/embedded-simple/readme.html        | 53 ++++++++++++++------
 .../activemq/jms/example/EmbeddedExample.java   | 11 ++++
 .../main/resources/activemq-configuration.xml   |  9 ++--
 .../main/resources/activemq-roles.properties    | 17 -------
 .../main/resources/activemq-users.properties    | 17 -------
 5 files changed, 54 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b7eafdd/examples/jms/embedded-simple/readme.html
----------------------------------------------------------------------
diff --git a/examples/jms/embedded-simple/readme.html b/examples/jms/embedded-simple/readme.html
index 7a4104c..bf41258 100644
--- a/examples/jms/embedded-simple/readme.html
+++ b/examples/jms/embedded-simple/readme.html
@@ -34,38 +34,63 @@ under the License.
 
       <ol>
          <li>Create ActiveMQ core configuration files and make sure they are within
your classpath.  By default, ActiveMQ
-             expects the classnames to be "activemq-configuration.xml", "activemq-jms.xml",
and "activemq-users.xml".</li>
-         <li>Create and start ActiveMQ JMS server</li>
+             expects the configuration file name to be "activemq-configuration.xml".</li>
+         <li>Create an embedded ActiveMQ JMS server</li>
          <pre class="prettyprint">
-            <code>EmbeddedJMS jmsServer = new EmbeddedJMS();
-            jmsServer.start();</code>
+            <code>EmbeddedJMS jmsServer = new EmbeddedJMS();</code>
          </pre>
-        
+
+         <li>Setup security configurations</li>
+         <pre class="prettyprint">
+            <code>SecurityConfiguration securityConfig = new SecurityConfiguration();
+            securityConfig.addUser("guest", "guest");
+            securityConfig.addRole("guest", "guest");
+            securityConfig.setDefaultUser("guest");
+            jmsServer.setSecurityManager(new ActiveMQSecurityManagerImpl(securityConfig));</code>
+         </pre>
+
+         <li>Start the embedded ActiveMQ JMS server</li>
+         <pre class="prettyprint">
+            <code>jmsServer.start()</code>
+         </pre>
+
+         <li>Create JMS resources (connection factory and queue) for the example</li>
+         <pre class="prettyprint">
+            <code>JMSServerManager jmsServerManager = jmsServer.getJMSServerManager();
+            List<String> connectors = new ArrayList<String>();
+            connectors.add("in-vm");
+            jmsServerManager.createConnectionFactory("ConnectionFactory", false, JMSFactoryType.CF,
connectors, "ConnectionFactory");
+            jmsServerManager.createQueue(false, "exampleQueue", null, false, "queue/exampleQueue");</code>
+         </pre>
+
          <p>At this point the JMS server is started and any JMS clients can look up
JMS resources from the JNDI to send/receive 
             messages from the server. To keep the example simple, we will send and receive
a JMS message from the same JVM 
             used to run the JMS server.</p>
               
          <li>Lookup JMS resources defined in the configuration </li>
          <pre class="prettyprint">
-            <code>ConnectionFactory cf = (ConnectionFactory)context.lookup("/cf");
-            Queue queue = (Queue)context.lookup("/queue/queue1");</code>
+            <code>ConnectionFactory cf = (ConnectionFactory)jmsServer.lookup("ConnectionFactory");
+            Queue queue = (Queue)jmsServer.lookup("queue/exampleQueue");</code>
          </pre>
          
          <li>Send and receive a message using JMS API</li>
-         <p>See the <a href="../../queue/readme.html">Queue Example</a>
for detailed steps to send and receive a JMS message</p>
+         <p>See the <a href="../queue/readme.html">Queue Example</a> for
detailed steps to send and receive a JMS message</p>
            
          <p>Finally, we stop the JMS server and its associated resources.</p>
-        
+
+         <li>Close the connection</li>
+         <pre class="prettyprint">
+            <code>if (connection != null)
+            {
+               connection.close();
+            }</code>
+         </pre>
+
          <li>Stop the JMS server</li>
          <pre class="prettyprint">
             <code>jmsServer.stop();</code>
          </pre>
         
-         <li>Stop the JNDI server</li>
-         <pre class="prettyprint">
-            <code>naming.stop();
-            jndiServer.stop();</code>
-         </pre>
       </ol>
    </body>
 </html>

http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b7eafdd/examples/jms/embedded-simple/src/main/java/org/apache/activemq/jms/example/EmbeddedExample.java
----------------------------------------------------------------------
diff --git a/examples/jms/embedded-simple/src/main/java/org/apache/activemq/jms/example/EmbeddedExample.java
b/examples/jms/embedded-simple/src/main/java/org/apache/activemq/jms/example/EmbeddedExample.java
index 008a604..838c3fd 100644
--- a/examples/jms/embedded-simple/src/main/java/org/apache/activemq/jms/example/EmbeddedExample.java
+++ b/examples/jms/embedded-simple/src/main/java/org/apache/activemq/jms/example/EmbeddedExample.java
@@ -29,8 +29,10 @@ import javax.jms.Session;
 import javax.jms.TextMessage;
 
 import org.apache.activemq.common.example.ActiveMQExample;
+import org.apache.activemq.core.config.impl.SecurityConfiguration;
 import org.apache.activemq.jms.server.embedded.EmbeddedJMS;
 import org.apache.activemq.jms.server.JMSServerManager;
+import org.apache.activemq.spi.core.security.ActiveMQSecurityManagerImpl;
 import org.apache.activemq.api.jms.JMSFactoryType;
 
 /**
@@ -50,6 +52,13 @@ public class EmbeddedExample extends ActiveMQExample
       try
       {
          EmbeddedJMS jmsServer = new EmbeddedJMS();
+
+         SecurityConfiguration securityConfig = new SecurityConfiguration();
+         securityConfig.addUser("guest", "guest");
+         securityConfig.addRole("guest", "guest");
+         securityConfig.setDefaultUser("guest");
+         jmsServer.setSecurityManager(new ActiveMQSecurityManagerImpl(securityConfig));
+
          jmsServer.start();
          System.out.println("Started Embedded JMS Server");
 
@@ -57,6 +66,8 @@ public class EmbeddedExample extends ActiveMQExample
          List<String> connectors = new ArrayList<String>();
          connectors.add("in-vm");
          jmsServerManager.createConnectionFactory("ConnectionFactory", false, JMSFactoryType.CF,
connectors, "ConnectionFactory");
+         jmsServerManager.createQueue(false, "exampleQueue", null, false, "queue/exampleQueue");
+
          ConnectionFactory cf = (ConnectionFactory)jmsServer.lookup("ConnectionFactory");
          Queue queue = (Queue)jmsServer.lookup("queue/exampleQueue");
 

http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b7eafdd/examples/jms/embedded-simple/src/main/resources/activemq-configuration.xml
----------------------------------------------------------------------
diff --git a/examples/jms/embedded-simple/src/main/resources/activemq-configuration.xml b/examples/jms/embedded-simple/src/main/resources/activemq-configuration.xml
index fdc8811..68cca46 100644
--- a/examples/jms/embedded-simple/src/main/resources/activemq-configuration.xml
+++ b/examples/jms/embedded-simple/src/main/resources/activemq-configuration.xml
@@ -22,15 +22,14 @@ under the License.
                xmlns="urn:activemq"
                xsi:schemaLocation="urn:activemq /schema/activemq-server.xsd">
 
-   <jms xmlns="urn:activemq:jms">
-      <!--the queue used by the example-->
-      <queue name="exampleQueue"/>
-   </jms>
-
    <core xmlns="urn:activemq:core">
 
       <persistence-enabled>false</persistence-enabled>
 
+      <connectors>
+         <connector name="in-vm">vm://0</connector>
+      </connectors>
+
       <acceptors>
          <acceptor name="in-vm">vm://0</acceptor>
       </acceptors>

http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b7eafdd/examples/jms/embedded-simple/src/main/resources/activemq-roles.properties
----------------------------------------------------------------------
diff --git a/examples/jms/embedded-simple/src/main/resources/activemq-roles.properties b/examples/jms/embedded-simple/src/main/resources/activemq-roles.properties
deleted file mode 100644
index 4e2d44c..0000000
--- a/examples/jms/embedded-simple/src/main/resources/activemq-roles.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-guest=guest
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b7eafdd/examples/jms/embedded-simple/src/main/resources/activemq-users.properties
----------------------------------------------------------------------
diff --git a/examples/jms/embedded-simple/src/main/resources/activemq-users.properties b/examples/jms/embedded-simple/src/main/resources/activemq-users.properties
deleted file mode 100644
index 4e2d44c..0000000
--- a/examples/jms/embedded-simple/src/main/resources/activemq-users.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-guest=guest
\ No newline at end of file


Mime
View raw message