[jboss-cvs] JBoss Messaging SVN: r4095 - in trunk: docs/examples and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 22 08:37:58 EDT 2008


Author: ataylor
Date: 2008-04-22 08:37:58 -0400 (Tue, 22 Apr 2008)
New Revision: 4095

Added:
   trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java
Modified:
   trunk/build-messaging.xml
   trunk/docs/examples/build.properties
   trunk/docs/examples/jms/build.xml
   trunk/docs/examples/messaging/build.xml
   trunk/src/main/org/jboss/messaging/core/client/ConnectionParams.java
   trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionParamsImpl.java
   trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java
Log:
added ssl configuration via system properties on the client side and added an example

Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml	2008-04-21 23:55:18 UTC (rev 4094)
+++ trunk/build-messaging.xml	2008-04-22 12:37:58 UTC (rev 4095)
@@ -463,6 +463,10 @@
             <include name="*.xml"/>
             <include name="jndi.properties"/>
          </fileset>
+         <fileset dir="${test.dir}/etc">
+            <include name="messaging.keystore"/>
+            <include name="messaging.truststore"/>
+         </fileset>
       </copy>
 
       <copy todir="${build.distro.bin.dir}">
@@ -496,7 +500,7 @@
             <exclude name="build.properties"/>
          </fileset>
       </copy>
-      <echo message="lib.dir=../../../lib${line.separator}client.jar=../../../lib/jboss-messaging-client.jar"
+      <echo message="lib.dir=../../../lib${line.separator}client.jar=../../../lib/jboss-messaging-client.jar${line.separator}config.dir=../../../config"
             file="${build.distro.examples.dir}/build.properties"/>
       <echo message="java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory${line.separator}java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces"
             file="${build.distro.config.dir}/jndi.properties"/>

Modified: trunk/docs/examples/build.properties
===================================================================
--- trunk/docs/examples/build.properties	2008-04-21 23:55:18 UTC (rev 4094)
+++ trunk/docs/examples/build.properties	2008-04-22 12:37:58 UTC (rev 4095)
@@ -1,3 +1,3 @@
-#Tue Apr 15 10:48:39 GMT+00:00 2008
 lib.dir=../../../thirdparty
 client.jar=../../../build/jars/jboss-messaging-client.jar
+config.dir=../../../tests/etc/

Modified: trunk/docs/examples/jms/build.xml
===================================================================
--- trunk/docs/examples/jms/build.xml	2008-04-21 23:55:18 UTC (rev 4094)
+++ trunk/docs/examples/jms/build.xml	2008-04-22 12:37:58 UTC (rev 4095)
@@ -44,13 +44,13 @@
       <fileset dir="${lib.dir}">
          <include name="**/*.jar"/>
       </fileset>
+      <pathelement location="${client.jar}"/>
    </path>
 
    <path id="runtime.classpath">
       <path refid="compile.classpath"/>
       <pathelement location="${build.dir}"/>
       <pathelement location="${etc.dir}"/>
-      <pathelement location="${client.jar}"/>
    </path>
 
    <target name="clean">

Modified: trunk/docs/examples/messaging/build.xml
===================================================================
--- trunk/docs/examples/messaging/build.xml	2008-04-21 23:55:18 UTC (rev 4094)
+++ trunk/docs/examples/messaging/build.xml	2008-04-22 12:37:58 UTC (rev 4095)
@@ -32,7 +32,7 @@
 <!-- =========================================================================================== -->
 
 
-<project default="compile" name="JBoss Messaging JMS Examples">
+<project default="compile" name="JBoss Messaging Examples">
 
    <property file="../build.properties"/>
 
@@ -43,12 +43,13 @@
       <fileset dir="${lib.dir}">
          <include name="**/*.jar"/>
       </fileset>
+      <pathelement location="${client.jar}"/>
    </path>
 
    <path id="runtime.classpath">
       <path refid="compile.classpath"/>
       <pathelement location="${build.dir}"/>
-      <pathelement location="${client.jar}"/>
+      <pathelement location="${config.dir}"/>
    </path>
 
    <target name="clean">
@@ -62,15 +63,21 @@
 
    <target name="compile" depends="init">
       <javac srcdir="${src.dir}" destdir="${build.dir}" debug="on"
-         source="1.5">
+             source="1.5">
          <classpath refid="compile.classpath"/>
       </javac>
    </target>
 
-    <target name="SimpleClient" depends="compile">
+   <target name="SimpleClient" depends="compile">
       <java classname="org.jboss.messaging.example.SimpleClient" fork="true">
          <classpath refid="runtime.classpath"/>
       </java>
    </target>
 
+   <target name="SSLClient" depends="compile">
+      <java classname="org.jboss.messaging.example.SSLClient" fork="true">
+         <classpath refid="runtime.classpath"/>
+      </java>
+   </target>
+
 </project>
\ No newline at end of file

Added: trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java
===================================================================
--- trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java	                        (rev 0)
+++ trunk/docs/examples/messaging/src/org/jboss/messaging/example/SSLClient.java	2008-04-22 12:37:58 UTC (rev 4095)
@@ -0,0 +1,70 @@
+/*
+   * 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.
+   */
+package org.jboss.messaging.example;
+
+import org.jboss.messaging.core.client.*;
+import org.jboss.messaging.core.client.impl.LocationImpl;
+import org.jboss.messaging.core.client.impl.ConnectionParamsImpl;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+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.jms.client.JBossTextMessage;
+
+/**
+ * A simple Client that uses SSL, to run this example enable ssl on the server in the jbm-configuration.xml file.
+ * (<remoting-enable-ssl>true</remoting-enable-ssl>)
+ * 
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class SSLClient
+{
+   public static void main(String[] args) throws Exception
+   {
+      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();
+   }
+}

Modified: trunk/src/main/org/jboss/messaging/core/client/ConnectionParams.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/ConnectionParams.java	2008-04-21 23:55:18 UTC (rev 4094)
+++ trunk/src/main/org/jboss/messaging/core/client/ConnectionParams.java	2008-04-22 12:37:58 UTC (rev 4095)
@@ -14,6 +14,11 @@
    int DEFAULT_REQRES_TIMEOUT = 5; // in seconds
    boolean DEFAULT_INVM_DISABLED = false;
    boolean DEFAULT_SSL_ENABLED = false;
+   public final static String REMOTING_SSL_KEYSTORE_PATH = "remoting.ssl.keystore.path";
+   public final static String REMOTING_SSL_KEYSTORE_PASSWORD = "remoting.ssl.keystore.password";
+   public final static String REMOTING_SSL_TRUSTSTORE_PATH = "remoting.ssl.truststore.path";
+   public final static String REMOTING_SSL_TRUSTSTORE_PASSWORD = "remoting.ssl.truststore.password";
+   public final static String REMOTING_ENABLE_SSL = "remoting.enable.ssl";
 
    int getTimeout();
 

Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionParamsImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionParamsImpl.java	2008-04-21 23:55:18 UTC (rev 4094)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ConnectionParamsImpl.java	2008-04-22 12:37:58 UTC (rev 4095)
@@ -128,7 +128,8 @@
 
    public boolean isSSLEnabled()
    {
-      return sslEnabled;
+      String sslEnabledProperty = System.getProperty(REMOTING_ENABLE_SSL);
+      return sslEnabledProperty==null?sslEnabled:sslEnabledProperty.equalsIgnoreCase("true");
    }
 
    public void setSSLEnabled(boolean sslEnabled)
@@ -148,7 +149,8 @@
 
    public String getKeyStorePath()
    {
-      return keyStorePath;
+      String sslKeystorePath = System.getProperty(REMOTING_SSL_KEYSTORE_PATH);
+      return sslKeystorePath == null?keyStorePath:sslKeystorePath;
    }
 
    public void setKeyStorePath(String keyStorePath)
@@ -158,7 +160,8 @@
 
    public String getKeyStorePassword()
    {
-      return keyStorePassword;
+      String keyStorePass = System.getProperty(REMOTING_SSL_KEYSTORE_PASSWORD);
+      return keyStorePass == null?keyStorePassword:keyStorePass;
    }
 
    public void setKeyStorePassword(String keyStorePassword)
@@ -168,7 +171,8 @@
 
    public String getTrustStorePath()
    {
-      return trustStorePath;
+      String sslTruststorePath = System.getProperty(REMOTING_SSL_TRUSTSTORE_PATH);
+      return sslTruststorePath==null?trustStorePath:sslTruststorePath;
    }
 
    public void setTrustStorePath(String trustStorePath)
@@ -178,7 +182,8 @@
 
    public String getTrustStorePassword()
    {
-      return trustStorePassword;
+      String trustStorePass = System.getProperty(REMOTING_SSL_TRUSTSTORE_PASSWORD);
+      return trustStorePass==null?trustStorePassword:trustStorePass;
    }
 
    public void setTrustStorePassword(String trustStorePassword)

Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java	2008-04-21 23:55:18 UTC (rev 4094)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MinaService.java	2008-04-22 12:37:58 UTC (rev 4095)
@@ -228,7 +228,7 @@
       {
          RemotingException re = (RemotingException) me;
          long sessionID = re.getSessionID();
-         long clientSessionID = factory.getSessions().get(sessionID);
+         long clientSessionID = factory.getSessions().containsKey(sessionID)?factory.getSessions().get(sessionID):0;
          for (FailureListener listener : listeners)
          {
             listener.onFailure(new RemotingException(re.getCode(), re.getMessage(), clientSessionID));




More information about the jboss-cvs-commits mailing list