activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r389536 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/transport/tcp/ main/resources/META-INF/services/org/apache/activemq/transport/ test/java/org/apache/activemq/transport/tcp/ test/resources/
Date Tue, 28 Mar 2006 16:29:44 GMT
Author: jstrachan
Date: Tue Mar 28 08:29:41 2006
New Revision: 389536

URL: http://svn.apache.org/viewcvs?rev=389536&view=rev
Log:
moved the SSL transport into the main core module and switched to using our own TCP transport
by default (as well as refactoring to make the [Server]SocketFactory objects pluggable

Added:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java
  (with props)
    incubator/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/transport/activeiossl
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportBrokerTest.java
  (with props)
    incubator/activemq/trunk/activemq-core/src/test/resources/client.keystore   (with props)
    incubator/activemq/trunk/activemq-core/src/test/resources/server.keystore   (with props)
Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportFactory.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
    incubator/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/transport/ssl
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/InactivityMonitorTest.java

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java?rev=389536&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java
Tue Mar 28 08:29:41 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * 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.activemq.transport.tcp;
+
+import javax.net.ServerSocketFactory;
+import javax.net.SocketFactory;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSocketFactory;
+
+/**
+ * An implementation of the TCP Transport using SSL
+ * 
+ * @version $Revision: $
+ */
+public class SslTransportFactory extends TcpTransportFactory {
+
+    public SslTransportFactory() {
+    }
+
+    protected ServerSocketFactory createServerSocketFactory() {
+        return SSLServerSocketFactory.getDefault();
+    }
+
+    protected SocketFactory createSocketFactory() {
+        return SSLSocketFactory.getDefault();
+    }
+    
+}

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java?rev=389536&r1=389535&r2=389536&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java
Tue Mar 28 08:29:41 2006
@@ -38,6 +38,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.net.SocketFactory;
+
 /**
  * An implementation of the {@link Transport} interface using raw tcp/ip
  * 
@@ -76,24 +78,25 @@
      * @throws IOException
      * @throws UnknownHostException
      */
-    public TcpTransport(WireFormat wireFormat, URI remoteLocation) throws UnknownHostException,
IOException {
+    public TcpTransport(WireFormat wireFormat, SocketFactory socketFactory, URI remoteLocation)
throws UnknownHostException, IOException {
         this(wireFormat);
-        this.socket = createSocket(remoteLocation);
+        this.socket = createSocket(socketFactory, remoteLocation);
     }
 
     /**
      * Connect to a remote Node - e.g. a Broker
      * 
      * @param wireFormat
+     * @param socketFactory 
      * @param remoteLocation
      * @param localLocation -
      *            e.g. local InetAddress and local port
      * @throws IOException
      * @throws UnknownHostException
      */
-    public TcpTransport(WireFormat wireFormat, URI remoteLocation, URI localLocation) throws
UnknownHostException, IOException {
+    public TcpTransport(WireFormat wireFormat, SocketFactory socketFactory, URI remoteLocation,
URI localLocation) throws UnknownHostException, IOException {
         this(wireFormat);
-        this.socket = createSocket(remoteLocation, localLocation);
+        this.socket = createSocket(socketFactory, remoteLocation, localLocation);
     }
 
     /**
@@ -229,10 +232,10 @@
      * @throws UnknownHostException
      * @throws IOException
      */
-    protected Socket createSocket(URI remoteLocation) throws UnknownHostException, IOException
{
+    protected Socket createSocket(SocketFactory socketFactory, URI remoteLocation) throws
UnknownHostException, IOException {
         String host = resolveHostName(remoteLocation.getHost());
         socketAddress = new InetSocketAddress(host, remoteLocation.getPort());
-        Socket sock = new Socket();
+        Socket sock = socketFactory.createSocket();
         return sock;
     }
 
@@ -246,11 +249,11 @@
      * @throws IOException
      * @throws UnknownHostException
      */
-    protected Socket createSocket(URI remoteLocation, URI localLocation) throws IOException,
UnknownHostException {
+    protected Socket createSocket(SocketFactory socketFactory, URI remoteLocation, URI localLocation)
throws IOException, UnknownHostException {
         String host = resolveHostName(remoteLocation.getHost());
         SocketAddress sockAddress = new InetSocketAddress(host, remoteLocation.getPort());
         SocketAddress localAddress = new InetSocketAddress(InetAddress.getByName(localLocation.getHost()),
localLocation.getPort());
-        Socket sock = new Socket();
+        Socket sock = socketFactory.createSocket();
         initialiseSocket(sock);
         sock.bind(localAddress);
         sock.connect(sockAddress);

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportFactory.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportFactory.java?rev=389536&r1=389535&r2=389536&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportFactory.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportFactory.java
Tue Mar 28 08:29:41 2006
@@ -48,7 +48,8 @@
         try {
             Map options = new HashMap(URISupport.parseParamters(location));
 
-            TcpTransportServer server = new TcpTransportServer(location);
+            ServerSocketFactory serverSocketFactory = createServerSocketFactory();
+            TcpTransportServer server = new TcpTransportServer(location, serverSocketFactory);
             server.setWireFormatFactory(createWireFormatFactory(options));
             IntrospectionSupport.setProperties(server, options);
 
@@ -99,20 +100,22 @@
         URI localLocation=null;
         String path=location.getPath();
         // see if the path is a local URI location
-        if(path!=null&&path.length()>0){
-            int localPortIndex=path.indexOf(':');
-            try{
-                Integer.parseInt(path.substring((localPortIndex+1),path.length()));
-                String localString=location.getScheme()+ ":/" + path;
-                localLocation=new URI(localString);
-            }catch(Exception e){
-                log.warn("path isn't a valid local location for TcpTransport to use",e);
+        if (path != null && path.length() > 0) {
+            int localPortIndex = path.indexOf(':');
+            try {
+                Integer.parseInt(path.substring((localPortIndex + 1), path.length()));
+                String localString = location.getScheme() + ":/" + path;
+                localLocation = new URI(localString);
+            }
+            catch (Exception e) {
+                log.warn("path isn't a valid local location for TcpTransport to use", e);
             }
         }
-        if(localLocation!=null){
-            return new TcpTransport(wf,location,localLocation);
+        SocketFactory socketFactory = createSocketFactory();
+        if (localLocation != null) {
+            return new TcpTransport(wf, socketFactory, location, localLocation);
         }
-        return new TcpTransport(wf,location);
+        return new TcpTransport(wf, socketFactory, location);
     }
 
     protected ServerSocketFactory createServerSocketFactory() {

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java?rev=389536&r1=389535&r2=389536&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransportServer.java
Tue Mar 28 08:29:41 2006
@@ -38,6 +38,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.net.ServerSocketFactory;
+
 /**
  * A TCP based implementation of {@link TransportServer}
  * 
@@ -54,16 +56,9 @@
     private int minmumWireFormatVersion;
     private boolean trace;
     
-    /**
-     * Constructor
-     * 
-     * @param location
-     * @throws IOException
-     * @throws URISyntaxException
-     */
-    public TcpTransportServer(URI location) throws IOException, URISyntaxException {
+    public TcpTransportServer(URI location, ServerSocketFactory serverSocketFactory) throws
IOException, URISyntaxException {
         super(location);
-        serverSocket = createServerSocket(location);
+        serverSocket = createServerSocket(location, serverSocketFactory);
         serverSocket.setSoTimeout(2000);
         updatePhysicalUri(location);
     }
@@ -194,16 +189,16 @@
      * @throws UnknownHostException
      * @throws IOException
      */
-    protected ServerSocket createServerSocket(URI bind) throws UnknownHostException, IOException
{
+    protected ServerSocket createServerSocket(URI bind, ServerSocketFactory factory) throws
UnknownHostException, IOException {
         ServerSocket answer = null;
         String host = bind.getHost();
         host = (host == null || host.length() == 0) ? "localhost" : host;
         InetAddress addr = InetAddress.getByName(host);
         if (host.trim().equals("localhost") || addr.equals(InetAddress.getLocalHost())) {
-            answer = new ServerSocket(bind.getPort(), backlog);
+            answer = factory.createServerSocket(bind.getPort(), backlog);
         }
         else {
-            answer = new ServerSocket(bind.getPort(), backlog, addr);
+            answer = factory.createServerSocket(bind.getPort(), backlog, addr);
         }
         return answer;
     }

Added: incubator/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/transport/activeiossl
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/transport/activeiossl?rev=389536&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/transport/activeiossl
(added)
+++ incubator/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/transport/activeiossl
Tue Mar 28 08:29:41 2006
@@ -0,0 +1 @@
+class=org.apache.activemq.transport.activeio.ActiveIOTransportFactory

Modified: incubator/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/transport/ssl
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/transport/ssl?rev=389536&r1=389535&r2=389536&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/transport/ssl
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/resources/META-INF/services/org/apache/activemq/transport/ssl
Tue Mar 28 08:29:41 2006
@@ -1 +1 @@
-class=org.apache.activemq.transport.activeio.ActiveIOTransportFactory
+class=org.apache.activemq.transport.tcp.SslTransportFactory

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/InactivityMonitorTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/InactivityMonitorTest.java?rev=389536&r1=389535&r2=389536&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/InactivityMonitorTest.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/InactivityMonitorTest.java
Tue Mar 28 08:29:41 2006
@@ -29,6 +29,8 @@
 import org.apache.activemq.transport.TransportListener;
 import org.apache.activemq.transport.TransportServer;
 
+import javax.net.SocketFactory;
+
 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
 
@@ -146,7 +148,7 @@
         // 
         // Manually create a client transport so that it does not send KeepAlive packets.
         // this should simulate a client hang.
-        clientTransport = new TcpTransport(new OpenWireFormat(), new URI("tcp://localhost:61616"));
+        clientTransport = new TcpTransport(new OpenWireFormat(), SocketFactory.getDefault(),
new URI("tcp://localhost:61616"));
         clientTransport.setTransportListener(new TransportListener() {
             public void onCommand(Command command) {
                 clientReceiveCount.incrementAndGet();

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportBrokerTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportBrokerTest.java?rev=389536&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportBrokerTest.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportBrokerTest.java
Tue Mar 28 08:29:41 2006
@@ -0,0 +1,51 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * 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.activemq.transport.tcp;
+
+import org.apache.activemq.transport.TransportBrokerTestSupport;
+
+import junit.framework.Test;
+import junit.textui.TestRunner;
+
+public class SslTransportBrokerTest extends TransportBrokerTestSupport {
+
+    protected String getBindLocation() {
+        return "ssl://localhost:0";
+    }
+
+    protected void setUp() throws Exception {
+        System.setProperty("javax.net.ssl.trustStore", "src/test/resources/client.keystore");
+        System.setProperty("javax.net.ssl.trustStorePassword", "password");
+        System.setProperty("javax.net.ssl.trustStoreType", "jks");        
+        System.setProperty("javax.net.ssl.keyStore", "src/test/resources/server.keystore");
+        System.setProperty("javax.net.ssl.keyStorePassword", "password");
+        System.setProperty("javax.net.ssl.keyStoreType", "jks");        
+        //System.setProperty("javax.net.debug", "ssl,handshake,data,trustmanager");     
  
+
+        MAX_WAIT = 2000;
+        super.setUp();
+    }
+
+    public static Test suite() {
+        return suite(SslTransportBrokerTest.class);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+
+}

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportBrokerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportBrokerTest.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/activemq/trunk/activemq-core/src/test/resources/client.keystore
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/resources/client.keystore?rev=389536&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/activemq/trunk/activemq-core/src/test/resources/client.keystore
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/activemq/trunk/activemq-core/src/test/resources/client.keystore
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/activemq/trunk/activemq-core/src/test/resources/server.keystore
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/resources/server.keystore?rev=389536&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/activemq/trunk/activemq-core/src/test/resources/server.keystore
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/activemq/trunk/activemq-core/src/test/resources/server.keystore
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message