[jboss-cvs] JBoss Messaging SVN: r4102 - trunk/docs/examples/messaging/src/org/jboss/messaging/example.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 23 04:25:48 EDT 2008


Author: ataylor
Date: 2008-04-23 04:25:48 -0400 (Wed, 23 Apr 2008)
New Revision: 4102

Modified:
   trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java
   trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java
Log:
refactored examples

Modified: trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java
===================================================================
--- trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java	2008-04-22 23:28:59 UTC (rev 4101)
+++ trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java	2008-04-23 08:25:48 UTC (rev 4102)
@@ -28,6 +28,7 @@
 import org.jboss.messaging.core.remoting.TransportType;
 import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.jms.client.JBossTextMessage;
 
 /**
@@ -38,33 +39,55 @@
  */
 public class SSLClient
 {
-   public static void main(String[] args) throws Exception
+   public static void main(String[] args)
    {
-      Location location = new LocationImpl(TransportType.TCP, "localhost", 5400);
-      ConnectionParams connectionParams = new ConnectionParamsImpl();
-      connectionParams.setSSLEnabled(true);
-      connectionParams.setKeyStorePath("messaging.keystore");
-      connectionParams.setTrustStorePath("messaging.truststore");
-      connectionParams.setKeyStorePassword("secureexample");
-      connectionParams.setTrustStorePassword("secureexample");
-      //it is also possible to set up ssl by using system properties.
-      /*System.setProperty(ConnectionParams.REMOTING_ENABLE_SSL, "true");
-      System.setProperty(ConnectionParams.REMOTING_SSL_KEYSTORE_PATH,"messaging.keystore");
-      System.setProperty(ConnectionParams.REMOTING_SSL_KEYSTORE_PASSWORD,"secureexample");
-      System.setProperty(ConnectionParams.REMOTING_SSL_TRUSTSTORE_PATH,"messaging.truststore");
-      System.setProperty(ConnectionParams.REMOTING_SSL_TRUSTSTORE_PASSWORD,"secureexample");*/
-      ClientConnectionFactory connectionFactory = new ClientConnectionFactoryImpl(0, location, connectionParams);
-      ClientConnection clientConnection = connectionFactory.createConnection(null, null);
-      ClientSession clientSession = clientConnection.createClientSession(false, true, true, 100, true, false);
-      ClientProducer clientProducer = clientSession.createProducer("queuejms.testQueue");
-      Message message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
-            System.currentTimeMillis(), (byte) 1);
-      message.setPayload("Hello!".getBytes());
-      clientProducer.send(message);
-      ClientConsumer clientConsumer = clientSession.createConsumer("queuejms.testQueue", null, false, false, false);
-      clientConnection.start();
-      Message msg = clientConsumer.receive(5000);
-      System.out.println("msg.getPayload() = " + new String(msg.getPayload()));
-      clientConnection.close();
+      ClientConnection clientConnection = null;
+      try
+      {
+         Location location = new LocationImpl(TransportType.TCP, "localhost", 5400);
+         ConnectionParams connectionParams = new ConnectionParamsImpl();
+         connectionParams.setSSLEnabled(true);
+         connectionParams.setKeyStorePath("messaging.keystore");
+         connectionParams.setTrustStorePath("messaging.truststore");
+         connectionParams.setKeyStorePassword("secureexample");
+         connectionParams.setTrustStorePassword("secureexample");
+         //it is also possible to set up ssl by using system properties.
+         /*System.setProperty(ConnectionParams.REMOTING_ENABLE_SSL, "true");
+            System.setProperty(ConnectionParams.REMOTING_SSL_KEYSTORE_PATH,"messaging.keystore");
+            System.setProperty(ConnectionParams.REMOTING_SSL_KEYSTORE_PASSWORD,"secureexample");
+            System.setProperty(ConnectionParams.REMOTING_SSL_TRUSTSTORE_PATH,"messaging.truststore");
+            System.setProperty(ConnectionParams.REMOTING_SSL_TRUSTSTORE_PASSWORD,"secureexample");*/
+         ClientConnectionFactory connectionFactory = new ClientConnectionFactoryImpl(0, location, connectionParams);
+         clientConnection = connectionFactory.createConnection(null, null);
+         ClientSession clientSession = clientConnection.createClientSession(false, true, true, 100, true, false);
+         ClientProducer clientProducer = clientSession.createProducer("queuejms.testQueue");
+         Message message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
+               System.currentTimeMillis(), (byte) 1);
+         message.setPayload("Hello!".getBytes());
+         clientProducer.send(message);
+         ClientConsumer clientConsumer = clientSession.createConsumer("queuejms.testQueue", null, false, false, false);
+         clientConnection.start();
+         Message msg = clientConsumer.receive(5000);
+         System.out.println("msg.getPayload() = " + new String(msg.getPayload()));
+      }
+      catch(Exception e)
+      {
+         e.printStackTrace();
+      }
+      finally
+      {
+         if(clientConnection != null)
+         {
+            try
+            {
+               clientConnection.close();
+            }
+            catch (MessagingException e1)
+            {
+               //
+            }
+         }
+      }
+
    }
 }

Modified: trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java
===================================================================
--- trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java	2008-04-22 23:28:59 UTC (rev 4101)
+++ trunk/docs/examples/messaging/src/org/jboss/messaging/example/SimpleClient.java	2008-04-23 08:25:48 UTC (rev 4102)
@@ -26,30 +26,54 @@
 import org.jboss.messaging.core.remoting.TransportType;
 import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.jms.client.JBossTextMessage;
 
 /**
  * Uses the core messaging API to send and receive a message to a queue.
+ *
  * @author <a href="ataylor at redhat.com">Andy Taylor</a>
  */
 public class SimpleClient
 {
-   public static void main(String[] args) throws Exception
+   public static void main(String[] args)
    {
-      Location location = new LocationImpl(TransportType.TCP, "localhost", 5400);
-      ConnectionParams connectionParams = new ConnectionParamsImpl();
-      ClientConnectionFactory connectionFactory = new ClientConnectionFactoryImpl(0, location, connectionParams);
-      ClientConnection clientConnection = connectionFactory.createConnection();
-      ClientSession clientSession = clientConnection.createClientSession(false, true, true, 100, true, false);
-      ClientProducer clientProducer = clientSession.createProducer("queuejms.testQueue");
-      Message message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
-            System.currentTimeMillis(), (byte) 1);
-      message.setPayload("Hello!".getBytes());
-      clientProducer.send(message);
-      ClientConsumer clientConsumer = clientSession.createConsumer("queuejms.testQueue", null, false, false, false);
-      clientConnection.start();
-      Message msg = clientConsumer.receive(5000);
-      System.out.println("msg.getPayload() = " + new String(msg.getPayload()));
-      clientConnection.close();
+      ClientConnection clientConnection = null;
+      try
+      {
+         Location location = new LocationImpl(TransportType.TCP, "localhost", 5400);
+         ConnectionParams connectionParams = new ConnectionParamsImpl();
+         ClientConnectionFactory connectionFactory = new ClientConnectionFactoryImpl(0, location, connectionParams);
+         clientConnection = connectionFactory.createConnection();
+         ClientSession clientSession = clientConnection.createClientSession(false, true, true, 100, true, false);
+         ClientProducer clientProducer = clientSession.createProducer("queuejms.testQueue");
+         Message message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
+                 System.currentTimeMillis(), (byte) 1);
+         message.setPayload("Hello!".getBytes());
+         clientProducer.send(message);
+         ClientConsumer clientConsumer = clientSession.createConsumer("queuejms.testQueue", null, false, false, false);
+         clientConnection.start();
+         Message msg = clientConsumer.receive(5000);
+         System.out.println("msg.getPayload() = " + new String(msg.getPayload()));
+      }
+      catch(Exception e)
+      {
+         e.printStackTrace();
+      }
+      finally
+      {
+         if (clientConnection != null)
+         {
+            try
+            {
+               clientConnection.close();
+            }
+            catch (MessagingException e1)
+            {
+               //
+            }
+         }
+      }
+
    }
 }




More information about the jboss-cvs-commits mailing list