[jboss-cvs] JBoss Messaging SVN: r6451 - in trunk: examples/jms and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 16 09:43:33 EDT 2009


Author: gaohoward
Date: 2009-04-16 09:43:33 -0400 (Thu, 16 Apr 2009)
New Revision: 6451

Added:
   trunk/examples/jms/security/
   trunk/examples/jms/security/build.xml
   trunk/examples/jms/security/readme.html
   trunk/examples/jms/security/server0/
   trunk/examples/jms/security/server0/client-jndi.properties
   trunk/examples/jms/security/server0/jbm-configuration.xml
   trunk/examples/jms/security/server0/jbm-jms.xml
   trunk/examples/jms/security/server0/jbm-queues.xml
   trunk/examples/jms/security/server0/jbm-security.xml
   trunk/examples/jms/security/server0/jbm-standalone-beans.xml
   trunk/examples/jms/security/src/
   trunk/examples/jms/security/src/org/
   trunk/examples/jms/security/src/org/jboss/
   trunk/examples/jms/security/src/org/jboss/jms/
   trunk/examples/jms/security/src/org/jboss/jms/example/
   trunk/examples/jms/security/src/org/jboss/jms/example/SecurityExample.java
Modified:
   trunk/.classpath
Log:
added security example


Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2009-04-16 13:39:48 UTC (rev 6450)
+++ trunk/.classpath	2009-04-16 13:43:33 UTC (rev 6451)
@@ -1,6 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry excluding="**/.svn/**/*" kind="src" path="src/main"/>
+	<classpathentry kind="src" path="examples/jms/security/src"/>
+	<classpathentry kind="src" path="examples/jms/divert/src"/>
+	<classpathentry kind="src" path="examples/jms/message-group/src"/>
+	<classpathentry kind="src" path="examples/jms/ssl-enabled/src"/>
 	<classpathentry kind="src" path="build/src"/>
 	<classpathentry kind="src" path="tests/jms-tests/config"/>
 	<classpathentry kind="src" path="tests/config"/>

Added: trunk/examples/jms/security/build.xml
===================================================================
--- trunk/examples/jms/security/build.xml	                        (rev 0)
+++ trunk/examples/jms/security/build.xml	2009-04-16 13:43:33 UTC (rev 6451)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+      <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+      ]>
+
+<!-- =========================================================================================== -->
+<!--                                                                                             -->
+<!-- JBoss, Home of Professional Open Source                                                     -->
+<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated                        -->
+<!-- by the @authors tag. See the copyright.txt in the distribution for a                        -->
+<!-- full listing of individual contributors.                                                    -->
+<!--                                                                                             -->
+<!-- This is free software; you can redistribute it and/or modify it                             -->
+<!-- under the terms of the GNU Lesser General Public License as                                 -->
+<!-- published by the Free Software Foundation; either version 2.1 of                            -->
+<!-- the License, or (at your option) any later version.                                         -->
+<!--                                                                                             -->
+<!-- This software is distributed in the hope that it will be useful,                            -->
+<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of                              -->
+<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU                            -->
+<!-- Lesser General Public License for more details.                                             -->
+<!--                                                                                             -->
+<!-- You should have received a copy of the GNU Lesser General Public                            -->
+<!-- License along with this software; if not, write to the Free                                 -->
+<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA                          -->
+<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org.                                    -->
+<!--                                                                                             -->
+<!-- =========================================================================================== -->
+
+
+<project default="run" name="JBoss Messaging JMS Security Example">
+
+   <import file="../common/build.xml"/>
+
+   <target name="run">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.SecurityExample"/>
+      </antcall>
+   </target>
+
+   <target name="runRemote">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.SecurityExample"/>
+         <param name="jbm.example.runServer" value="false"/>
+      </antcall>
+   </target>
+
+</project>

Added: trunk/examples/jms/security/readme.html
===================================================================
--- trunk/examples/jms/security/readme.html	                        (rev 0)
+++ trunk/examples/jms/security/readme.html	2009-04-16 13:43:33 UTC (rev 6451)
@@ -0,0 +1,209 @@
+<html>
+  <head>
+    <title>JBoss Messaging JMS Security Example</title>
+    <link rel="stylesheet" type="text/css" href="../common/common.css">
+  </head>
+  <body>
+     <h1>JMS Security Example</h1>
+     <br>
+     <p>This example shows you how configure security with JBoss Messaging.</p>
+     
+     <p>With security properly configured, JBoss Messaging can restrict client access to its resouces, including 
+     connection creation, message sending/receiving, etc. This is done by configuring users and roles as well as permissions in 
+     the configuration files. </p>
+     <p>In this example, two users jbm-sender and jbm-consumer are configured. User jbm-sender belongs to user role and sender role. User
+     jbm-consumer belongs to user role and consumer role. They are configured in server0/jbm-security.xml, as below: </p>
+     
+     <pre>
+     <code>
+        &lt;user name=&quot;jbm-sender&quot; password=&quot;jbossmessaging1&quot;&gt;
+        &lt;role name=&quot;user&quot;/&gt;
+        &lt;role name=&quot;sender&quot;/&gt;
+        &lt;/user&gt;
+   
+        &lt;user name=&quot;jbm-consumer&quot; password=&quot;jbossmessaging2&quot;&gt;
+        &lt;role name=&quot;user&quot;/&gt;
+        &lt;role name=&quot;consumer&quot;/&gt;
+        &lt;/user&gt;
+     </code>
+     </pre>
+     <p>
+     The above configuration makes sure that only 'jbm-sender' and 'jbm-consumer' with correct passwords can create connections to JBoss 
+     Messaging server. In another file server0/jbm-queues.xml, permissions are configured in order to give proper rights to the users to 
+     do the job: 
+     </p>
+     
+     <pre>
+     <code>
+      &lt;security match=&quot;jms.topic.exampleTopic&quot;&gt;
+         &lt;permission type=&quot;createDurableQueue&quot; roles=&quot;user&quot;/&gt;
+         &lt;permission type=&quot;deleteDurableQueue&quot; roles=&quot;user&quot;/&gt;
+         &lt;permission type=&quot;createTempQueue&quot; roles=&quot;user&quot;/&gt;
+         &lt;permission type=&quot;deleteTempQueue&quot; roles=&quot;user&quot;/&gt;
+         &lt;permission type=&quot;send&quot; roles=&quot;sender&quot;/&gt;
+         &lt;permission type=&quot;consume&quot; roles=&quot;consumer&quot;/&gt;
+      &lt;/security&gt;
+     </code>
+     </pre>
+     
+     <p>As you can see, both users can access queue resources (role user). However, user jbm-sender (of role sender) can only send messages 
+     and user jbm-consumer (of role consumer) can only consume messages. In this example the jbm-consumer tries to send message but failed 
+     as it doesn't has the right to do so.</p>
+
+     <br>
+     <h2>Example step-by-step</h2>
+     <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
+     <br>
+     <ol>
+        <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
+        <pre>
+           <code>InitialContext initialContext = getContext(0);</code>
+        </pre>
+
+        <li>We look-up the JMS topic object from JNDI</li>
+        <pre>
+           <code>Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");</code>
+        </pre>
+
+        <li>We look-up the JMS connection factory object from JNDI</li>
+        <pre>
+           <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
+        </pre>
+
+        <li>We try to create a JMS Connection without user/password. It will fail.</li>
+        <pre>
+           <code>
+         try
+         {
+            connection1 = cf.createConnection();
+            result = false;
+         }
+         catch (JMSSecurityException e)
+         {
+            System.out.println("Error creating connection, detail: " + e.getMessage());
+         }
+           </code>
+        </pre>
+
+        <li>We create a Connection using wrong password, it will fail again.</li>
+        <pre>
+           <code>
+         try
+         {
+            connection1 = cf.createConnection("jbm-sender", "wrong-password");
+            result = false;
+         }
+         catch (JMSSecurityException e)
+         {
+            System.out.println("Error creating connection, detail: " + e.getMessage());
+         }
+           </code>
+        </pre>
+
+        <li>We now create two connections with correct credentials. connection1 is used for sending, and connection2 receiving.</li>
+        <pre>
+          <code>
+         connection1 = cf.createConnection("jbm-sender", "jbossmessaging1");
+         connection2 = cf.createConnection("jbm-consumer", "jbossmessaging2");
+          </code>
+       </pre>
+
+        <li>We create 2 JMS Sessions.</li>
+         <pre>
+           <code>
+         Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+           </code>
+         </pre>
+
+        <li>We create 2 Message Producers, where producer2 has no right to send.</li>
+        <pre>
+          <code>
+         MessageProducer producer1 = session1.createProducer(topic);
+         MessageProducer producer2 = session2.createProducer(topic);
+          </code>
+        </pre>
+
+        <li>We create 2 JMS Message Consumers.</li>
+        <pre>
+           <code>
+         MessageConsumer messageConsumer1 = session2.createConsumer(topic);
+         MessageConsumer messageConsumer2 = session2.createConsumer(topic);
+           </code>
+        </pre>
+
+        <li>We start the connections</li>
+        <pre>
+           <code>
+         connection1.start();
+         connection2.start();
+           </code>
+        </pre>
+
+        <li>We create a Text Message</li>
+        <pre>
+           <code>TextMessage message = session1.createTextMessage("This is a text message");</code>
+        </pre>
+
+        <li>We send the message by producer2</li>
+        <pre>
+           <code>
+         producer2.send(message);
+         System.out.println("Producer2 sent message: " + message.getText());
+           </code>
+        </pre>
+
+        <li>We check no messages are received by either consumer.</li>
+        <pre>
+           <code>
+         TextMessage messageReceived1 = (TextMessage) messageConsumer1.receive(2000);
+         TextMessage messageReceived2 = (TextMessage) messageConsumer2.receive(2000);
+         if (messageReceived1 != null) 
+         {
+            System.out.println("Message received! " + messageReceived1.getText());
+            result = false;
+         }
+         if (messageReceived2 != null) 
+         {
+            System.out.println("Message received! " + messageReceived2.getText());
+            result = false;
+         }
+           </code>
+        </pre>
+
+        <li>We send the message by producer1.</li>
+        <pre>
+           <code>producer1.send(message);</code>
+        </pre>
+
+        <li>We receive the message.</li>
+        <pre>
+           <code>
+         messageReceived1 = (TextMessage) messageConsumer1.receive(1000);
+         messageReceived2 = (TextMessage) messageConsumer2.receive(1000);
+         System.out.println("Consumer 1 Received message: " + messageReceived1.getText());
+         System.out.println("Consumer 2 Received message: " + messageReceived2.getText());
+           </code>
+        </pre>
+        
+        <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
+
+        <pre>
+           <code>finally
+           {
+              if (initialContext != null)
+              {
+                initialContext.close();
+              }
+              if (connection != null)
+              {
+                 connection.close();
+              }
+           }</code>
+        </pre>
+
+
+
+     </ol>
+  </body>
+</html>
\ No newline at end of file

Added: trunk/examples/jms/security/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/security/server0/client-jndi.properties	                        (rev 0)
+++ trunk/examples/jms/security/server0/client-jndi.properties	2009-04-16 13:43:33 UTC (rev 6451)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/security/server0/jbm-configuration.xml
===================================================================
--- trunk/examples/jms/security/server0/jbm-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/security/server0/jbm-configuration.xml	2009-04-16 13:43:33 UTC (rev 6451)
@@ -0,0 +1,28 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-configuration.xsd">
+   <configuration>
+
+      <!-- Connectors -->
+      <connectors>
+         <connector name="netty-connector">
+            <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+            <param key="jbm.remoting.netty.port" value="5445" type="Integer"/>
+         </connector>
+      </connectors>
+      
+      <!-- Acceptors -->
+      <acceptors>
+         <acceptor name="netty-acceptor">
+            <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+            <param key="jbm.remoting.netty.port" value="5445" type="Integer"/>
+         </acceptor>
+      </acceptors>
+
+      <!-- Other config -->
+
+      <journal-min-files>2</journal-min-files>
+
+   </configuration>
+
+</deployment>

Added: trunk/examples/jms/security/server0/jbm-jms.xml
===================================================================
--- trunk/examples/jms/security/server0/jbm-jms.xml	                        (rev 0)
+++ trunk/examples/jms/security/server0/jbm-jms.xml	2009-04-16 13:43:33 UTC (rev 6451)
@@ -0,0 +1,20 @@
+<deployment xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-jms.xsd ">
+   <!--the connection factory used by the example-->
+   <connection-factory name="ConnectionFactory">
+      <connector-ref connector-name="netty-connector"/>
+      <entries>
+         <entry name="ConnectionFactory"/>
+         <entry name="XAConnectionFactory"/>
+         <entry name="java:/ConnectionFactory"/>
+         <entry name="java:/XAConnectionFactory"/>
+      </entries>
+   </connection-factory>
+
+   <!--the topic used by the example-->
+   <topic name="exampleTopic">
+      <entry name="/topic/exampleTopic"/>
+   </topic>
+
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/security/server0/jbm-queues.xml
===================================================================
--- trunk/examples/jms/security/server0/jbm-queues.xml	                        (rev 0)
+++ trunk/examples/jms/security/server0/jbm-queues.xml	2009-04-16 13:43:33 UTC (rev 6451)
@@ -0,0 +1,15 @@
+<settings xmlns="urn:jboss:messaging"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-queues.xsd ">
+
+   <!--security for example topic-->
+   <security match="jms.topic.exampleTopic">
+      <permission type="createDurableQueue" roles="user"/>
+      <permission type="deleteDurableQueue" roles="user"/>
+      <permission type="createTempQueue" roles="user"/>
+      <permission type="deleteTempQueue" roles="user"/>
+      <permission type="send" roles="sender"/>
+      <permission type="consume" roles="consumer"/>
+   </security>
+
+</settings>

Added: trunk/examples/jms/security/server0/jbm-security.xml
===================================================================
--- trunk/examples/jms/security/server0/jbm-security.xml	                        (rev 0)
+++ trunk/examples/jms/security/server0/jbm-security.xml	2009-04-16 13:43:33 UTC (rev 6451)
@@ -0,0 +1,13 @@
+<deployment xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:jboss:messaging ../schemas/jbm-security.xsd ">
+   
+   <user name="jbm-sender" password="jbossmessaging1">
+      <role name="user"/>
+      <role name="sender"/>
+   </user>
+   
+   <user name="jbm-consumer" password="jbossmessaging2">
+      <role name="user"/>
+      <role name="consumer"/>
+   </user>
+</deployment>
\ No newline at end of file

Added: trunk/examples/jms/security/server0/jbm-standalone-beans.xml
===================================================================
--- trunk/examples/jms/security/server0/jbm-standalone-beans.xml	                        (rev 0)
+++ trunk/examples/jms/security/server0/jbm-standalone-beans.xml	2009-04-16 13:43:33 UTC (rev 6451)
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+   <!-- JNDI server. Disable this if you don't want JNDI -->
+   <bean name="JNDIServer" class="org.jnp.server.Main">
+      <property name="namingInfo">
+         <inject bean="Naming"/>
+      </property>
+      <property name="port">1099</property>
+      <property name="bindAddress">localhost</property>
+      <property name="rmiPort">1098</property>
+      <property name="rmiBindAddress">localhost</property>
+   </bean>
+   
+   <!-- MBean server -->
+   <bean name="MBeanServer" class="javax.management.MBeanServer">
+      <constructor factoryClass="java.lang.management.ManagementFactory"
+                   factoryMethod="getPlatformMBeanServer"/>
+   </bean> 
+
+   <!-- The core configuration -->
+   <bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
+
+   <!-- The security manager -->
+   <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+
+   <!-- The core server -->
+   <bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl"> 
+      <constructor>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+         <parameter>
+            <inject bean="MBeanServer"/>
+         </parameter>
+         <parameter>
+            <inject bean="JBMSecurityManager"/>
+         </parameter>        
+      </constructor>         
+   </bean>
+   
+   <!-- The JMS server -->
+   <bean name="JMSServerManager" class="org.jboss.messaging.jms.server.impl.JMSServerManagerImpl">
+      <constructor>         
+         <parameter>
+            <inject bean="MessagingServer"/>
+         </parameter>
+      </constructor>
+   </bean>
+
+</deployment>

Added: trunk/examples/jms/security/src/org/jboss/jms/example/SecurityExample.java
===================================================================
--- trunk/examples/jms/security/src/org/jboss/jms/example/SecurityExample.java	                        (rev 0)
+++ trunk/examples/jms/security/src/org/jboss/jms/example/SecurityExample.java	2009-04-16 13:43:33 UTC (rev 6451)
@@ -0,0 +1,159 @@
+/*
+   * JBoss, Home of Professional Open Source
+   * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+   * by the @authors tag. See the copyright.txt in the distribution for a
+   * full listing of individual contributors.
+   *
+   * This is free software; you can redistribute it and/or modify it
+   * under the terms of the GNU Lesser General Public License as
+   * published by the Free Software Foundation; either version 2.1 of
+   * the License, or (at your option) any later version.
+   *
+   * This software is distributed in the hope that it will be useful,
+   * but WITHOUT ANY WARRANTY; without even the implied warranty of
+   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   * Lesser General Public License for more details.
+   *
+   * You should have received a copy of the GNU Lesser General Public
+   * License along with this software; if not, write to the Free
+   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+   */
+package org.jboss.jms.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSSecurityException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+
+/**
+ * A simple JMS example that shows how to access messaging with security configured.
+ *
+ * @author <a href="hgao at redhat.com">Howard Gao</a>
+ */
+public class SecurityExample extends JMSExample
+{
+   private boolean result = true;
+   
+   public static void main(String[] args)
+   {
+      new SecurityExample().run(args);
+   }
+
+   public boolean runExample() throws Exception
+   {
+      Connection connection1 = null;
+      Connection connection2 = null;
+      InitialContext initialContext = null;
+      try
+      {
+         ///Step 1. Create an initial context to perform the JNDI lookup.
+         initialContext = getContext(0);
+
+         //Step 2. perform a lookup on the topic
+         Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");
+
+         //Step 3. perform a lookup on the Connection Factory
+         ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+
+         //Step 4. Try to create a JMS Connection without user/password. It will fail.
+         try
+         {
+            connection1 = cf.createConnection();
+            result = false;
+         }
+         catch (JMSSecurityException e)
+         {
+            System.out.println("Error creating connection, detail: " + e.getMessage());
+         }
+
+         //Step 5. Create a Connection using wrong password, it will fail.
+         try
+         {
+            connection1 = cf.createConnection("jbm-sender", "wrong-password");
+            result = false;
+         }
+         catch (JMSSecurityException e)
+         {
+            System.out.println("Error creating connection, detail: " + e.getMessage());
+         }
+         
+         //Step 6. Now create two connections with correct credentials. connection1 is used for sending, connection2 receiving
+         connection1 = cf.createConnection("jbm-sender", "jbossmessaging1");
+         connection2 = cf.createConnection("jbm-consumer", "jbossmessaging2");
+
+         //Step 7. Create 2 JMS Sessions
+         Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         //Step 8. Create 2 Message Producers, where producer2 has no right to send
+         MessageProducer producer1 = session1.createProducer(topic);
+         MessageProducer producer2 = session2.createProducer(topic);
+
+         //Step 9. Create 2 JMS Message Consumers
+         MessageConsumer messageConsumer1 = session2.createConsumer(topic);
+         MessageConsumer messageConsumer2 = session2.createConsumer(topic);
+                  
+         //Step 10. Start the Connections
+         connection1.start();
+         connection2.start();
+         
+         //Step 11. Create a Text Message
+         TextMessage message = session1.createTextMessage("This is a text message");
+
+         //Step 12. Send the Message by producer2
+         producer2.send(message);
+         System.out.println("Producer2 sent message: " + message.getText());
+         
+         //Step 13. Check no messages are received by either consumer.
+         TextMessage messageReceived1 = (TextMessage) messageConsumer1.receive(2000);
+         TextMessage messageReceived2 = (TextMessage) messageConsumer2.receive(2000);
+         if (messageReceived1 != null) 
+         {
+            System.out.println("Message received! " + messageReceived1.getText());
+            result = false;
+         }
+         if (messageReceived2 != null) 
+         {
+            System.out.println("Message received! " + messageReceived2.getText());
+            result = false;
+         }
+         
+         //Step 14. Send the message by producer1
+         producer1.send(message);
+
+         System.out.println("Producer1 sent message: " + message.getText());
+
+         //Step 15. Receive the message
+         messageReceived1 = (TextMessage) messageConsumer1.receive(1000);
+         messageReceived2 = (TextMessage) messageConsumer2.receive(1000);
+         System.out.println("Consumer 1 Received message: " + messageReceived1.getText());
+         System.out.println("Consumer 2 Received message: " + messageReceived2.getText());
+         
+         return result;
+      }
+      finally
+      {
+         //Step 16. Be sure to close our JMS resources!
+         if (connection1 != null)
+         {
+            connection1.close();
+         }
+         if (connection2 != null)
+         {
+            connection2.close();
+         }
+         
+         // Also the initialContext
+         if (initialContext != null)
+         {
+            initialContext.close();
+         }
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list