JBoss Remoting SVN: r5341 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 23:21:06 -0400 (Fri, 14 Aug 2009)
New Revision: 5341
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java
Log:
JBREM-1139: Adjusts PortUtil range in getInvokerConfigFromXml() and getInvokerConfigFromServerConfiguration().
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java 2009-08-15 03:19:43 UTC (rev 5340)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/Connector.java 2009-08-15 03:21:06 UTC (rev 5341)
@@ -609,6 +609,7 @@
String tempURI = null;
String path = (String) invokerConfig.get("path");
+ PortUtil.updateRange(invokerConfig);
if (homes.isEmpty() && connectHomes.isEmpty())
{
@@ -800,6 +801,7 @@
if (defaultPortString == null) defaultPortString = temp;
String path = (String) locatorParameters.remove("path");
+ PortUtil.updateRange(invokerConfig);
String tempURI = null;
boolean parametersStarted = false;
15 years, 3 months
JBoss Remoting SVN: r5340 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 23:19:43 -0400 (Fri, 14 Aug 2009)
New Revision: 5340
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
Log:
JBREM-1139: Adjusts PortUtil range in setup().
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java 2009-08-15 03:19:03 UTC (rev 5339)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java 2009-08-15 03:19:43 UTC (rev 5340)
@@ -1070,6 +1070,7 @@
protected void setup() throws Exception
{
Map config = getConfiguration();
+ PortUtil.updateRange(config);
setupHomes(config);
String maxNumOfThreads = (String)config.get(MAX_NUM_ONEWAY_THREADS_KEY);
15 years, 3 months
JBoss Remoting SVN: r5339 - remoting2/branches/2.x/src/main/org/jboss/remoting.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 23:19:03 -0400 (Fri, 14 Aug 2009)
New Revision: 5339
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
Log:
JBREM-1139: Adjusts PortUtil range in constructor.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2009-08-15 01:17:04 UTC (rev 5338)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/Client.java 2009-08-15 03:19:03 UTC (rev 5339)
@@ -2049,6 +2049,8 @@
}
}
}
+
+ PortUtil.updateRange(params);
}
private void configureCallbackServerSocketFactory(Map map) throws Exception
15 years, 3 months
JBoss Remoting SVN: r5338 - remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 21:17:04 -0400 (Fri, 14 Aug 2009)
New Revision: 5338
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java
Log:
JBREM-1077: Made changes suggested by Doychin Bondzhev; reuses GZIPInputStream and BufferedInputStream, just replacing the Inflater with each call.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java 2009-08-15 01:16:22 UTC (rev 5337)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java 2009-08-15 01:17:04 UTC (rev 5338)
@@ -22,20 +22,23 @@
package org.jboss.remoting.marshal.compress;
-import org.jboss.remoting.marshal.UnMarshaller;
-import org.jboss.remoting.marshal.VersionedUnMarshaller;
-import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
-import org.jboss.remoting.serialization.SerializationManager;
-import org.jboss.remoting.serialization.SerializationStreamFactory;
-
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
+import java.util.HashMap;
import java.util.Map;
import java.util.zip.GZIPInputStream;
+import java.util.zip.Inflater;
+import org.jboss.remoting.marshal.UnMarshaller;
+import org.jboss.remoting.marshal.VersionedUnMarshaller;
+import org.jboss.remoting.marshal.http.HTTPUnMarshaller;
+import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
+import org.jboss.remoting.serialization.SerializationManager;
+import org.jboss.remoting.serialization.SerializationStreamFactory;
+
/**
* <code>CompressingMarshaller</code> and <code>CompressingUnMarshaller</code> are a general
* purpose compressing marshaller / decompressing unmarshaller pair based on Java's GZIP facilities.
@@ -82,6 +85,13 @@
{
wrappedUnMarshaller = unMarshaller;
}
+
+ public InputStream getMarshallingStream(InputStream inputStream) throws IOException
+ {
+ SelfCleaningGZipInputStream gzis = new SelfCleaningGZipInputStream(inputStream);
+ DecomposableBufferedInputStream bis = new DecomposableBufferedInputStream(gzis);
+ return bis;
+ }
/**
* Restores a compressed, marshalled form of an object to its original state.
@@ -96,8 +106,20 @@
*/
public Object read(InputStream inputStream, Map metadata, int version) throws IOException, ClassNotFoundException
{
- SelfCleaningGZipInputStream gzis = new SelfCleaningGZipInputStream(inputStream);
- BufferedInputStream bis = new BufferedInputStream(gzis);
+ SelfCleaningGZipInputStream gzis = null;
+ DecomposableBufferedInputStream bis = null;
+
+ if (inputStream instanceof DecomposableBufferedInputStream)
+ {
+ bis = (DecomposableBufferedInputStream) inputStream;
+ gzis = (SelfCleaningGZipInputStream) bis.getWrappedStream();
+ }
+ else
+ {
+ gzis = new SelfCleaningGZipInputStream(inputStream);
+ bis = new DecomposableBufferedInputStream(gzis);
+ }
+
SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
ObjectInputStream ois = manager.createRegularInput(bis);
@@ -105,6 +127,16 @@
{
if(wrappedUnMarshaller != null)
{
+ // HACK for JBREM-927.
+ if (wrappedUnMarshaller instanceof HTTPUnMarshaller)
+ {
+ Map map = new HashMap();
+ if (metadata != null)
+ map.putAll(metadata);
+ map.put("Content-Length", Integer.toString(Integer.MAX_VALUE));
+ metadata = map;
+ }
+
if (wrappedUnMarshaller instanceof VersionedUnMarshaller)
return ((VersionedUnMarshaller)wrappedUnMarshaller).read(ois, metadata, version);
else
@@ -139,12 +171,18 @@
*/
static class SelfCleaningGZipInputStream extends GZIPInputStream
{
- public SelfCleaningGZipInputStream(InputStream in) throws IOException
+ SelfCleaningGZipInputStream(InputStream in) throws IOException
{
super(in);
}
+
+ void refreshInflater()
+ {
+ inf = new Inflater(true);
+ crc.reset();
+ }
- public void end() throws IOException
+ void end() throws IOException
{
while(available() > 0) { // This will force input stream to read gzip trailer from input stream
read();
@@ -153,5 +191,22 @@
}
}
+ static class DecomposableBufferedInputStream extends BufferedInputStream
+ {
+ DecomposableBufferedInputStream(InputStream in, int size)
+ {
+ super(in, size);
+ }
+
+ DecomposableBufferedInputStream(InputStream in)
+ {
+ super(in);
+ }
+
+ InputStream getWrappedStream()
+ {
+ return in;
+ }
+ }
}
15 years, 3 months
JBoss Remoting SVN: r5337 - remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 21:16:22 -0400 (Fri, 14 Aug 2009)
New Revision: 5337
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java
Log:
JBREM-1077: Made changes suggested by Doychin Bondzhev; reuses GZIPOutputStream and BufferedOutputStream, just replacing the Deflater with each call.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java 2009-08-15 00:59:57 UTC (rev 5336)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java 2009-08-15 01:16:22 UTC (rev 5337)
@@ -22,18 +22,19 @@
package org.jboss.remoting.marshal.compress;
-import org.jboss.remoting.marshal.Marshaller;
-import org.jboss.remoting.marshal.VersionedMarshaller;
-import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
-import org.jboss.remoting.serialization.SerializationStreamFactory;
-
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
+import java.util.zip.Deflater;
import java.util.zip.GZIPOutputStream;
+import org.jboss.remoting.marshal.Marshaller;
+import org.jboss.remoting.marshal.VersionedMarshaller;
+import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
+import org.jboss.remoting.serialization.SerializationStreamFactory;
+
/**
* <code>CompressingMarshaller</code> and <code>CompressingUnMarshaller</code> are a general
* purpose compressing marshaller / decompressing unmarshaller pair based on Java's GZIP facilities.
@@ -79,6 +80,13 @@
wrappedMarshaller = marshaller;
}
+ public OutputStream getMarshallingStream(OutputStream outputStream) throws IOException
+ {
+ GZIPOutputStream gzos = new SelfCleaningGZipOutputStream(outputStream);
+ DecomposableBufferedOutputStream bos = new DecomposableBufferedOutputStream(gzos);
+ return bos;
+ }
+
/**
* Writes compressed, marshalled form of <code>dataObject</code> to <code>output</code>.
@@ -89,9 +97,19 @@
*/
public void write(Object dataObject, OutputStream output, int version) throws IOException
{
- output.flush();
- GZIPOutputStream gzos = new SelfCleaningGZipOutputStream(output);
- BufferedOutputStream bos = new BufferedOutputStream(gzos);
+ SelfCleaningGZipOutputStream gzos = null;
+ DecomposableBufferedOutputStream bos = null;
+ if (output instanceof DecomposableBufferedOutputStream)
+ {
+ bos = (DecomposableBufferedOutputStream) output;
+ gzos = (SelfCleaningGZipOutputStream) bos.getWrappedStream();
+ gzos.refreshDeflater();
+ }
+ else
+ {
+ gzos = new SelfCleaningGZipOutputStream(output);
+ bos = new DecomposableBufferedOutputStream(gzos);
+ }
ObjectOutputStream oos = SerializationStreamFactory.getManagerInstance(getSerializationType()).createOutput(bos);
if(wrappedMarshaller != null)
@@ -129,10 +147,25 @@
*/
static class SelfCleaningGZipOutputStream extends GZIPOutputStream
{
+ boolean used;
+
public SelfCleaningGZipOutputStream(OutputStream out) throws IOException
{
super(out);
}
+
+ void refreshDeflater()
+ {
+ if (used)
+ {
+ def = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
+ crc.reset();
+ }
+ else
+ {
+ used = true;
+ }
+ }
/**
* Writes remaining compressed data to the output stream and closes the underlying stream.
@@ -144,5 +177,23 @@
def.end(); // This will release all resources used by zlib native code
}
}
+
+ static class DecomposableBufferedOutputStream extends BufferedOutputStream
+ {
+ DecomposableBufferedOutputStream(OutputStream out, int size)
+ {
+ super(out, size);
+ }
+
+ DecomposableBufferedOutputStream(OutputStream out)
+ {
+ super(out);
+ }
+
+ OutputStream getWrappedStream()
+ {
+ return out;
+ }
+ }
}
15 years, 3 months
JBoss Remoting SVN: r5336 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 20:59:57 -0400 (Fri, 14 Aug 2009)
New Revision: 5336
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
Log:
JBREM-1120: Added logging to debug jdk 1.4 failure.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-08-14 21:02:57 UTC (rev 5335)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java 2009-08-15 00:59:57 UTC (rev 5336)
@@ -791,6 +791,7 @@
|| maxPoolSize == 1
|| numberOfCallRetries == 1;
socketWrapper = getConnection(marshaller, unmarshaller, tryPool, timeLeft);
+ log.trace(this + " got socketWrapper: " + socketWrapper);
}
catch (InterruptedException e)
{
@@ -825,10 +826,12 @@
boolean performVersioning = Version.performVersioning(version);
OutputStream outputStream = socketWrapper.getOutputStream();
-
+ log.trace(this + "got outputStream: " + outputStream);
if (performVersioning)
{
+ log.trace(this + " writing version");
writeVersion(outputStream, version);
+ log.trace(this + " wrote version");
}
//TODO: -TME so this is messed up as now ties remoting versioning to using a marshaller type
15 years, 3 months
JBoss Remoting SVN: r5335 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 17:02:57 -0400 (Fri, 14 Aug 2009)
New Revision: 5335
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/SSLBisocketControlConnectionReplacementTestCase.java
Log:
JBREM-1147: New unit test.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/SSLBisocketControlConnectionReplacementTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/SSLBisocketControlConnectionReplacementTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/SSLBisocketControlConnectionReplacementTestCase.java 2009-08-14 21:02:57 UTC (rev 5335)
@@ -0,0 +1,425 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.remoting.transport.bisocket.ssl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+
+import javax.net.ServerSocketFactory;
+import javax.net.ssl.HandshakeCompletedListener;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.security.SSLSocketBuilder;
+import org.jboss.test.remoting.transport.bisocket.BisocketControlConnectionReplacementTestCase;
+
+/**
+ * Unit test for JBREM-1147.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Aug 14, 2009
+ * </p>
+ */
+public class SSLBisocketControlConnectionReplacementTestCase extends BisocketControlConnectionReplacementTestCase
+{
+ private static Logger log = Logger.getLogger(SSLBisocketControlConnectionReplacementTestCase.class);
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ String keyStoreFilePath = getClass().getResource(".keystore").getFile();
+ System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath);
+ System.setProperty("javax.net.ssl.keyStorePassword", "unit-tests-server");
+ String trustStoreFilePath = getClass().getResource(".truststore").getFile();
+ System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", "unit-tests-client");
+ }
+ super.setUp();
+ }
+
+ protected String getTransport()
+ {
+ return "sslbisocket";
+ }
+
+ protected String getServerSocketName()
+ {
+ return SSLTestServerSocketFactory.class.getName();
+ }
+
+ static public class SSLTestServerSocketFactory extends ServerSocketFactory
+ {
+ int timeout;
+ ServerSocketFactory factory;
+ int initialWrites;
+
+ public SSLTestServerSocketFactory() throws IOException
+ {
+ this.timeout = 5000;
+ this.initialWrites = 3;
+ setupFactory();
+ }
+ public SSLTestServerSocketFactory(int timeout, int initialWrites) throws IOException
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ setupFactory();
+ }
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket ss = SSLServerSocketFactory.getDefault().createServerSocket();
+ log.info("returning: " + ss);
+ return ss;
+ }
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket ss = null;
+ if (port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket ss = null;
+ if (port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, backlog, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ ServerSocket ss = null;
+ if (port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, backlog, ifAddress, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ protected void setupFactory() throws IOException
+ {
+ SSLSocketBuilder sslSocketBuilder = new SSLSocketBuilder();
+ sslSocketBuilder.setUseSSLServerSocketFactory(false);
+ factory = sslSocketBuilder.createSSLServerSocketFactory();
+ }
+ }
+
+
+ static class SSLTestServerSocket extends SSLServerSocket
+ {
+ int timeout;
+ int initialWrites;
+ SSLServerSocket serverSocket;
+
+ public SSLTestServerSocket(int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super();
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ }
+ public SSLTestServerSocket(int port, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(port), 50);
+ }
+ public SSLTestServerSocket(int port, int backlog, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port, backlog);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(port), backlog);
+ }
+ public SSLTestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port, backlog, bindAddr);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(bindAddr, port), 50);
+ }
+ public Socket accept() throws IOException
+ {
+ SSLSocket s1 = (SSLSocket) serverSocket.accept();
+ Socket s2 = new SSLTestSocket(timeout, initialWrites, s1);
+ return s2;
+ }
+ public void bind(SocketAddress endpoint, int backlog) throws IOException
+ {
+ log.info("serverSocket: " + serverSocket);
+ if (serverSocket != null) log.info("bound: " + serverSocket.isBound());
+ if (serverSocket != null && !serverSocket.isBound())
+ {
+ log.info("binding " + serverSocket);
+ serverSocket.bind(endpoint, backlog);
+ }
+ }
+ public String toString()
+ {
+ return "SSLTestServerSocket[" + serverSocket.toString() + "]";
+ }
+ public boolean getEnableSessionCreation()
+ {
+ return serverSocket.getEnableSessionCreation();
+ }
+ public String[] getEnabledCipherSuites()
+ {
+ return serverSocket.getEnabledCipherSuites();
+ }
+ public String[] getEnabledProtocols()
+ {
+ return serverSocket.getEnabledProtocols();
+ }
+ public boolean getNeedClientAuth()
+ {
+ return serverSocket.getNeedClientAuth();
+ }
+ public String[] getSupportedCipherSuites()
+ {
+ return serverSocket.getSupportedCipherSuites();
+ }
+ public String[] getSupportedProtocols()
+ {
+ return serverSocket.getSupportedProtocols();
+ }
+ public boolean getUseClientMode()
+ {
+ return serverSocket.getUseClientMode();
+ }
+ public boolean getWantClientAuth()
+ {
+ return serverSocket.getWantClientAuth();
+ }
+ public void setEnableSessionCreation(boolean arg0)
+ {
+ serverSocket.setEnableSessionCreation(arg0);
+ }
+ public void setEnabledCipherSuites(String[] arg0)
+ {
+ serverSocket.setEnabledCipherSuites(arg0);
+ }
+ public void setEnabledProtocols(String[] arg0)
+ {
+ serverSocket.setEnabledProtocols(arg0);
+ }
+ public void setNeedClientAuth(boolean arg0)
+ {
+ serverSocket.setNeedClientAuth(arg0);
+ }
+ public void setUseClientMode(boolean arg0)
+ {
+ serverSocket.setUseClientMode(arg0);
+ }
+ public void setWantClientAuth(boolean arg0)
+ {
+ serverSocket.setWantClientAuth(arg0);
+ }
+ }
+
+ static class SSLTestSocket extends SSLSocket
+ {
+ int timeout;
+ int initialWrites;
+ SSLSocket socket;
+ SocketAddress endpoint;
+
+ public SSLTestSocket(int timeout, int initialWrites, SSLSocket socket)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ }
+ public SSLTestSocket(String host, int port, int timeout, int initialWrites, SSLSocket socket) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ connect(new InetSocketAddress(host, port), timeout);
+ }
+ public SSLTestSocket(InetAddress address, int port, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(address, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ connect(new InetSocketAddress(address, port), timeout);
+ }
+ public SSLTestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ bind(new InetSocketAddress(localAddr, localPort));
+ connect(new InetSocketAddress(host, port), timeout);
+ }
+ public SSLTestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ bind(new InetSocketAddress(localAddr, localPort));
+ connect(new InetSocketAddress(address, port), timeout);
+ }
+ public String toString()
+ {
+ return "SSLTestSocket[" + socket.toString() + "]";
+ }
+ public InputStream getInputStream() throws IOException
+ {
+ return socket.getInputStream();
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(socket.getOutputStream(), timeout, initialWrites);
+ }
+ public void addHandshakeCompletedListener(HandshakeCompletedListener listener)
+ {
+ socket.addHandshakeCompletedListener(listener);
+ }
+ public void bind(SocketAddress bindpoint) throws IOException
+ {
+ if (socket != null)
+ socket.bind(bindpoint);
+ }
+ public void connect(SocketAddress endpoint) throws IOException
+ {
+ if (socket != null)
+ socket.connect(endpoint);
+ }
+ public void connect(SocketAddress endpoint, int timeout) throws IOException
+ {
+ socket.connect(endpoint, timeout);
+ }
+ public boolean getEnableSessionCreation()
+ {
+ return socket.getEnableSessionCreation();
+ }
+ public String[] getEnabledCipherSuites()
+ {
+ return socket.getEnabledCipherSuites();
+ }
+ public String[] getEnabledProtocols()
+ {
+ return socket.getEnabledProtocols();
+ }
+ public InetAddress getInetAddress()
+ {
+ return socket.getInetAddress();
+ }
+ public boolean getNeedClientAuth()
+ {
+ return socket.getNeedClientAuth();
+ }
+ public SSLSession getSession()
+ {
+ return socket.getSession();
+ }
+ public String[] getSupportedCipherSuites()
+ {
+ return socket.getSupportedCipherSuites();
+ }
+ public String[] getSupportedProtocols()
+ {
+ return socket.getSupportedProtocols();
+ }
+ public boolean getUseClientMode()
+ {
+ return socket.getUseClientMode();
+ }
+ public boolean getWantClientAuth()
+ {
+ return socket.getWantClientAuth();
+ }
+ public void removeHandshakeCompletedListener(HandshakeCompletedListener listener)
+ {
+ socket.removeHandshakeCompletedListener(listener);
+ }
+ public void setEnableSessionCreation(boolean flag)
+ {
+ socket.setEnableSessionCreation(flag);
+ }
+ public void setEnabledCipherSuites(String[] suites)
+ {
+ socket.setEnabledCipherSuites(suites);
+ }
+ public void setEnabledProtocols(String[] protocols)
+ {
+ socket.setEnabledProtocols(protocols);
+ }
+ public void setNeedClientAuth(boolean need)
+ {
+ socket.setNeedClientAuth(need);
+ }
+ public void setUseClientMode(boolean mode)
+ {
+ socket.setUseClientMode(mode);
+ }
+ public void setWantClientAuth(boolean want)
+ {
+ socket.setWantClientAuth(want);
+ }
+ public void startHandshake() throws IOException
+ {
+ socket.startHandshake();
+ }
+ }
+}
15 years, 3 months
JBoss Remoting SVN: r5334 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 17:02:40 -0400 (Fri, 14 Aug 2009)
New Revision: 5334
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketControlConnectionReplacementTestCase.java
Log:
JBREM-1147: New unit test.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketControlConnectionReplacementTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketControlConnectionReplacementTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/BisocketControlConnectionReplacementTestCase.java 2009-08-14 21:02:40 UTC (rev 5334)
@@ -0,0 +1,486 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.remoting.transport.bisocket;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.net.ServerSocketFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.DefaultCallbackErrorHandler;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.jboss.remoting.transport.bisocket.Bisocket;
+
+
+/**
+ * Unit test for JBREM-1147.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Aug 14, 2009
+ * </p>
+ */
+public class BisocketControlConnectionReplacementTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(BisocketControlConnectionReplacementTestCase.class);
+
+ protected static boolean firstTime = true;
+ protected static int secondaryServerSocketPort;
+ protected static int numberOfCallbacks = 10;
+ protected static Object lock = new Object();
+ protected static TestCallbackHandler testCallbackHandler;
+
+ protected String host;
+ protected int port;
+ protected String locatorURI;
+ protected InvokerLocator serverLocator;
+ protected Connector connector;
+ protected TestInvocationHandler invocationHandler;
+
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.DEBUG);
+ Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testCreateSocketWithReplacedControlConnection() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ // Start server.
+ setupServer();
+
+ // Create client.
+ InvokerLocator clientLocator = new InvokerLocator(locatorURI);
+ HashMap clientConfig = new HashMap();
+ clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ addExtraClientConfig(clientConfig);
+ Client client = new Client(clientLocator, clientConfig);
+ client.connect();
+ log.info("client is connected");
+
+ // Test connections.
+ assertEquals("abc", client.invoke("abc"));
+ log.info("connection is good");
+
+ // Add callback handler.
+ testCallbackHandler = new TestCallbackHandler();
+ HashMap metadata = new HashMap();
+ metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
+ client.addListener(testCallbackHandler, metadata);
+
+ synchronized (lock)
+ {
+ lock.wait(120000);
+ }
+
+ assertEquals(numberOfCallbacks, testCallbackHandler.counter);
+ assertEquals(numberOfCallbacks - 1, testCallbackHandler.max);
+
+ client.removeListener(testCallbackHandler);
+ client.disconnect();
+ shutdownServer();
+ log.info(getName() + " PASSES");
+ }
+
+
+ protected String getTransport()
+ {
+ return "bisocket";
+ }
+
+
+ protected String getServerSocketName()
+ {
+ return TestServerSocketFactory.class.getName();
+ }
+
+
+ protected void addExtraClientConfig(Map config) {}
+ protected void addExtraServerConfig(Map config) {}
+
+
+ protected void setupServer() throws Exception
+ {
+ host = InetAddress.getLocalHost().getHostAddress();
+ port = PortUtil.findFreePort(host);
+ locatorURI = getTransport() + "://" + host + ":" + port;
+ locatorURI += "/?" + Bisocket.PING_FREQUENCY + "=2000";
+ locatorURI += "&" + DefaultCallbackErrorHandler.CALLBACK_ERRORS_ALLOWED + "=100";
+ String metadata = System.getProperty("remoting.metadata");
+ if (metadata != null)
+ {
+ locatorURI += "&" + metadata;
+ }
+ serverLocator = new InvokerLocator(locatorURI);
+ log.info("Starting remoting server with locator uri of: " + locatorURI);
+ HashMap config = new HashMap();
+ config.put(InvokerLocator.FORCE_REMOTE, "true");
+ secondaryServerSocketPort = PortUtil.findFreePort(host);
+ config.put(Bisocket.SECONDARY_BIND_PORT, Integer.toString(secondaryServerSocketPort));
+ config.put(ServerInvoker.SERVER_SOCKET_FACTORY, getServerSocketName());
+ config.put("numberOfCallRetries", "5");
+ addExtraServerConfig(config);
+ connector = new Connector(serverLocator, config);
+ connector.create();
+ invocationHandler = new TestInvocationHandler();
+ connector.addInvocationHandler("test", invocationHandler);
+ connector.start();
+ }
+
+
+ protected void shutdownServer() throws Exception
+ {
+ if (connector != null)
+ connector.stop();
+ }
+
+
+ static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ int counter;
+
+ public void addListener(final InvokerCallbackHandler callbackHandler)
+ {
+ if (counter++ > 0)
+ return;
+
+ new Thread()
+ {
+ public void run()
+ {
+ for (int i = 0; i < 10 * numberOfCallbacks; i++)
+ {
+ try
+ {
+ if (testCallbackHandler.counter >= numberOfCallbacks)
+ {
+ return;
+ }
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException e)
+ {
+ log.error("Unexpected interrupt", e);
+ }
+ log.info("sending callback: " + i);
+ callbackHandler.handleCallback(new Callback(Integer.toString(i)));
+ log.info("sent callback: " + i);
+ }
+ catch (HandleCallbackException e)
+ {
+ log.error("Callback error", e);
+ }
+ }
+ }
+ }.start();
+ }
+ public Object invoke(final InvocationRequest invocation) throws Throwable
+ {
+ return invocation.getParameter();
+ }
+ public void removeListener(InvokerCallbackHandler callbackHandler) {}
+ public void setMBeanServer(MBeanServer server) {}
+ public void setInvoker(ServerInvoker invoker) {}
+ }
+
+
+ static class TestCallbackHandler implements InvokerCallbackHandler
+ {
+ int counter;
+ int max;
+
+ public void handleCallback(Callback callback) throws HandleCallbackException
+ {
+ log.info("received callback: " + counter++);
+ max = Math.max(Integer.valueOf((String) callback.getParameter()).intValue(), max);
+ log.info("max: " + max);
+ if (counter >= numberOfCallbacks)
+ {
+ synchronized (lock)
+ {
+ lock.notifyAll();
+ }
+ }
+ }
+ }
+
+ static public class TestServerSocketFactory extends ServerSocketFactory
+ {
+ int timeout;
+ int initialWrites;
+
+ public TestServerSocketFactory()
+ {
+ this.timeout = 5000;
+ this.initialWrites = 2;
+ }
+ public TestServerSocketFactory(int timeout, int initialWrites)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket ss = ServerSocketFactory.getDefault().createServerSocket();
+ log.info("returning: " + ss);
+ return ss;
+ }
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket ss = null;
+ if (port != secondaryServerSocketPort)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket ss = null;
+ if (port != secondaryServerSocketPort)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port, backlog);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, backlog, timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ ServerSocket ss = null;
+ if (port != secondaryServerSocketPort)
+ {
+ ss = ServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
+ }
+ else
+ {
+ ss = new TestServerSocket(port, backlog, ifAddress, timeout, initialWrites);
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+ }
+
+
+ static class TestServerSocket extends ServerSocket
+ {
+ int timeout;
+ int initialWrites;
+
+ public TestServerSocket(int timeout, int initialWrites) throws IOException
+ {
+ super();
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestServerSocket(int port, int timeout, int initialWrites) throws IOException
+ {
+ super(port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestServerSocket(int port, int backlog, int timeout, int initialWrites) throws IOException
+ {
+ super(port, backlog);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout, int initialWrites) throws IOException
+ {
+ super(port, backlog, bindAddr);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public Socket accept() throws IOException
+ {
+ Socket s = new TestSocket(timeout, initialWrites);
+ implAccept(s);
+ return s;
+ }
+ public String toString()
+ {
+ return "TestServerSocket[" + getLocalPort() + "]";
+ }
+ }
+
+
+ static class TestSocket extends Socket
+ {
+ int timeout;
+ int initialWrites;
+
+ public TestSocket(int timeout, int initialWrites)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(String host, int port, int timeout, int initialWrites) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(InetAddress address, int port, int timeout, int initialWrites) throws IOException
+ {
+ super(address, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public TestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(super.getOutputStream(), timeout, initialWrites);
+ }
+ public String toString()
+ {
+ return "TestSocket[" + getLocalPort() + "->" + getPort() + "]";
+ }
+ }
+
+ public static class TestOutputStream extends OutputStream
+ {
+ OutputStream os;
+ int timeout;
+ boolean closed;
+ int initialWrites;
+ boolean doCounterTest = true;
+ int counter;
+
+ public TestOutputStream(OutputStream os, int timeout, int initialWrites)
+ {
+ this.os = os;
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ }
+ public void close()throws IOException
+ {
+ closed = true;
+ super.close();
+ log.info(this + " closed");
+ }
+ public void write(int b) throws IOException
+ {
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new SocketException("closed");
+ }
+ if (doCounterTest && ++counter > initialWrites)
+ {
+ close();
+ throw new SocketException("closed");
+ }
+ os.write(b);
+ }
+ public void write(byte b[], int off, int len) throws IOException
+ {
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new SocketException("closed");
+ }
+ log.info("TestOutputStream: counter = " + counter + ", initialWrites = " + initialWrites);
+ if (++counter > initialWrites)
+ {
+ close();
+ throw new SocketException("closed");
+ }
+ try
+ {
+ log.info(this + " writing");
+ doCounterTest = false;
+ os.write(b, off, len);
+ doCounterTest = true;
+ log.info(this + " back from writing");
+ }
+ catch (IOException e)
+ {
+ log.info("exception: ", e);
+ throw e;
+ }
+ }
+ }
+}
\ No newline at end of file
15 years, 3 months
JBoss Remoting SVN: r5333 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 17:01:47 -0400 (Fri, 14 Aug 2009)
New Revision: 5333
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketClientInvoker.java
Log:
JBREM-1147: createSocket() periodically checks for updated controlOuputStream.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketClientInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketClientInvoker.java 2009-08-14 21:00:16 UTC (rev 5332)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/bisocket/BisocketClientInvoker.java 2009-08-14 21:01:47 UTC (rev 5333)
@@ -85,6 +85,8 @@
protected String listenerId;
private int pingFrequency = Bisocket.PING_FREQUENCY_DEFAULT;
+ private int pingWindowFactor = Bisocket.PING_WINDOW_FACTOR_DEFAULT;
+ private int pingWindow = pingWindowFactor * pingFrequency;
private int maxRetries = Bisocket.MAX_RETRIES_DEFAULT;
private Socket controlSocket;
private OutputStream controlOutputStream;
@@ -190,6 +192,26 @@
}
}
+ val = configuration.get(Bisocket.PING_WINDOW_FACTOR);
+ if (val != null && val instanceof String && ((String) val).length() > 0)
+ {
+ try
+ {
+ pingWindowFactor = Integer.valueOf(((String) val)).intValue();
+ log.debug(this + " setting pingWindowFactor to " + pingWindowFactor);
+ }
+ catch (NumberFormatException e)
+ {
+ log.warn("Invalid format for " + "\"" + Bisocket.PING_WINDOW_FACTOR + "\": " + val);
+ }
+ }
+ else if (val != null)
+ {
+ log.warn("\"" + Bisocket.PING_WINDOW_FACTOR + "\" must be specified as a String");
+ }
+
+ pingWindow = pingWindowFactor * pingFrequency;
+
val = configuration.get(Bisocket.MAX_RETRIES);
if (val != null)
{
@@ -231,7 +253,20 @@
this.pingFrequency = pingFrequency;
}
-
+
+ public int getPingWindowFactor()
+ {
+ return pingWindowFactor;
+ }
+
+
+ public void setPingWindowFactor(int pingWindowFactor)
+ {
+ this.pingWindowFactor = pingWindowFactor;
+ pingWindow = pingWindowFactor * pingFrequency;
+ }
+
+
protected void handleConnect() throws ConnectionFailedException
{
// Callback client on server side.
@@ -454,35 +489,47 @@
synchronized (controlLock)
{
- controlOutputStream.write(Bisocket.CREATE_ORDINARY_SOCKET);
- }
-
- synchronized (sockets)
- {
- if (!sockets.isEmpty())
+ if (log.isTraceEnabled()) log.trace(this + " writing Bisocket.CREATE_ORDINARY_SOCKET on " + controlOutputStream);
+ try
{
- Iterator it = sockets.iterator();
- Socket socket = (Socket) it.next();
- it.remove();
- log.debug(this + " found socket (" + listenerId + "): " + socket);
- return socket;
+ controlOutputStream.write(Bisocket.CREATE_ORDINARY_SOCKET);
+ if (log.isTraceEnabled()) log.trace(this + " wrote Bisocket.CREATE_ORDINARY_SOCKET");
+
+ synchronized (sockets)
+ {
+ if (!sockets.isEmpty())
+ {
+ Iterator it = sockets.iterator();
+ Socket socket = (Socket) it.next();
+ it.remove();
+ log.debug(this + " found socket (" + listenerId + "): " + socket);
+ return socket;
+ }
+ }
}
+ catch (IOException e)
+ {
+ log.debug(this + " unable to write Bisocket.CREATE_ORDINARY_SOCKET", e);
+ }
}
long timeRemaining = timeout;
- long start = System.currentTimeMillis();
+ long pingFailedWindow = 2 * pingWindow;
+ long pingFailedTimeRemaining = pingFailedWindow;
+ long start = System.currentTimeMillis();
+ OutputStream savedControlOutputStream = controlOutputStream;
- while (isConnected() && !pingFailed.flag && (timeout == 0 || timeRemaining > 0))
+ while (isConnected() && (!pingFailed.flag || pingFailedTimeRemaining > 0) && (timeout == 0 || timeRemaining > 0))
{
synchronized (sockets)
- {
+ {
try
{
sockets.wait(1000);
}
catch (InterruptedException e)
{
- log.debug("unexpected interrupt");
+ log.debug(this + " unexpected interrupt");
}
if (!sockets.isEmpty())
@@ -494,9 +541,26 @@
return socket;
}
}
-
+
+ if (savedControlOutputStream != controlOutputStream)
+ {
+ savedControlOutputStream = controlOutputStream;
+ log.debug(this + " rewriting Bisocket.CREATE_ORDINARY_SOCKET on " + controlOutputStream);
+ try
+ {
+ controlOutputStream.write(Bisocket.CREATE_ORDINARY_SOCKET);
+ log.debug(this + " rewrote Bisocket.CREATE_ORDINARY_SOCKET");
+ }
+ catch (IOException e)
+ {
+ log.debug(this + " unable to rewrite Bisocket.CREATE_ORDINARY_SOCKET" + e.getMessage());
+ }
+ }
+
+ long elapsed = System.currentTimeMillis() - start;
if (timeout > 0)
- timeRemaining = timeout - (System.currentTimeMillis() - start);
+ timeRemaining = timeout - elapsed;
+ pingFailedTimeRemaining = pingFailedWindow - elapsed;
}
if (!isConnected())
@@ -526,6 +590,7 @@
controlSocket = socket;
log.debug(this + " control socket replaced by: " + socket);
controlOutputStream = controlSocket.getOutputStream();
+ log.debug("controlOutputStream replaced by: " + controlOutputStream);
}
if (pingTimerTask != null)
15 years, 3 months
JBoss Remoting SVN: r5332 - remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/ssl.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 17:00:16 -0400 (Fri, 14 Aug 2009)
New Revision: 5332
Added:
remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/SSLBisocketControlConnectionReplacementTestCase.java
Log:
JBREM-1147: New unit test.
Added: remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/SSLBisocketControlConnectionReplacementTestCase.java
===================================================================
--- remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/SSLBisocketControlConnectionReplacementTestCase.java (rev 0)
+++ remoting2/branches/2.2/src/tests/org/jboss/test/remoting/transport/bisocket/ssl/SSLBisocketControlConnectionReplacementTestCase.java 2009-08-14 21:00:16 UTC (rev 5332)
@@ -0,0 +1,425 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.remoting.transport.bisocket.ssl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+
+import javax.net.ServerSocketFactory;
+import javax.net.ssl.HandshakeCompletedListener;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.security.SSLSocketBuilder;
+import org.jboss.test.remoting.transport.bisocket.BisocketControlConnectionReplacementTestCase;
+
+/**
+ * Unit test for JBREM-1147.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version
+ * <p>
+ * Copyright Aug 14, 2009
+ * </p>
+ */
+public class SSLBisocketControlConnectionReplacementTestCase extends BisocketControlConnectionReplacementTestCase
+{
+ private static Logger log = Logger.getLogger(SSLBisocketControlConnectionReplacementTestCase.class);
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ String keyStoreFilePath = getClass().getResource(".keystore").getFile();
+ System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath);
+ System.setProperty("javax.net.ssl.keyStorePassword", "unit-tests-server");
+ String trustStoreFilePath = getClass().getResource(".truststore").getFile();
+ System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", "unit-tests-client");
+ }
+ super.setUp();
+ }
+
+ protected String getTransport()
+ {
+ return "sslbisocket";
+ }
+
+ protected String getServerSocketName()
+ {
+ return SSLTestServerSocketFactory.class.getName();
+ }
+
+ static public class SSLTestServerSocketFactory extends ServerSocketFactory
+ {
+ int timeout;
+ ServerSocketFactory factory;
+ int initialWrites;
+
+ public SSLTestServerSocketFactory() throws IOException
+ {
+ this.timeout = 5000;
+ this.initialWrites = 2;
+ setupFactory();
+ }
+ public SSLTestServerSocketFactory(int timeout, int initialWrites) throws IOException
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ setupFactory();
+ }
+ public ServerSocket createServerSocket() throws IOException
+ {
+ ServerSocket ss = new SSLTestServerSocket(timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ log.info("returning: " + ss);
+ return ss;
+ }
+ public ServerSocket createServerSocket(int port) throws IOException
+ {
+ ServerSocket ss = null;
+ if (port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog) throws IOException
+ {
+ ServerSocket ss = null;
+ if (port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, backlog, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException
+ {
+ ServerSocket ss = null;
+ if (port != secondaryServerSocketPort)
+ {
+ ss = SSLServerSocketFactory.getDefault().createServerSocket(port, backlog, ifAddress);
+ }
+ else
+ {
+ ss = new SSLTestServerSocket(port, backlog, ifAddress, timeout, initialWrites, ((SSLServerSocket) factory.createServerSocket()));
+ }
+ log.info("returning: " + ss);
+ return ss;
+ }
+
+ protected void setupFactory() throws IOException
+ {
+ SSLSocketBuilder sslSocketBuilder = new SSLSocketBuilder();
+ sslSocketBuilder.setUseSSLServerSocketFactory(false);
+ factory = sslSocketBuilder.createSSLServerSocketFactory();
+ }
+ }
+
+
+ static class SSLTestServerSocket extends SSLServerSocket
+ {
+ int timeout;
+ int initialWrites;
+ SSLServerSocket serverSocket;
+
+ public SSLTestServerSocket(int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super();
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ }
+ public SSLTestServerSocket(int port, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(port), 50);
+ }
+ public SSLTestServerSocket(int port, int backlog, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port, backlog);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(port), backlog);
+ }
+ public SSLTestServerSocket(int port, int backlog, InetAddress bindAddr, int timeout, int initialWrites, SSLServerSocket serverSocket) throws IOException
+ {
+ super(port, backlog, bindAddr);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.serverSocket = serverSocket;
+ bind(new InetSocketAddress(bindAddr, port), 50);
+ }
+ public Socket accept() throws IOException
+ {
+ SSLSocket s1 = (SSLSocket) serverSocket.accept();
+ Socket s2 = new SSLTestSocket(timeout, initialWrites, s1);
+ return s2;
+ }
+ public void bind(SocketAddress endpoint, int backlog) throws IOException
+ {
+ log.info("serverSocket: " + serverSocket);
+ if (serverSocket != null) log.info("bound: " + serverSocket.isBound());
+ if (serverSocket != null && !serverSocket.isBound())
+ {
+ log.info("binding " + serverSocket);
+ serverSocket.bind(endpoint, backlog);
+ }
+ }
+ public String toString()
+ {
+ return "SSLTestServerSocket[" + serverSocket.toString() + "]";
+ }
+ public boolean getEnableSessionCreation()
+ {
+ return serverSocket.getEnableSessionCreation();
+ }
+ public String[] getEnabledCipherSuites()
+ {
+ return serverSocket.getEnabledCipherSuites();
+ }
+ public String[] getEnabledProtocols()
+ {
+ return serverSocket.getEnabledProtocols();
+ }
+ public boolean getNeedClientAuth()
+ {
+ return serverSocket.getNeedClientAuth();
+ }
+ public String[] getSupportedCipherSuites()
+ {
+ return serverSocket.getSupportedCipherSuites();
+ }
+ public String[] getSupportedProtocols()
+ {
+ return serverSocket.getSupportedProtocols();
+ }
+ public boolean getUseClientMode()
+ {
+ return serverSocket.getUseClientMode();
+ }
+ public boolean getWantClientAuth()
+ {
+ return serverSocket.getWantClientAuth();
+ }
+ public void setEnableSessionCreation(boolean arg0)
+ {
+ serverSocket.setEnableSessionCreation(arg0);
+ }
+ public void setEnabledCipherSuites(String[] arg0)
+ {
+ serverSocket.setEnabledCipherSuites(arg0);
+ }
+ public void setEnabledProtocols(String[] arg0)
+ {
+ serverSocket.setEnabledProtocols(arg0);
+ }
+ public void setNeedClientAuth(boolean arg0)
+ {
+ serverSocket.setNeedClientAuth(arg0);
+ }
+ public void setUseClientMode(boolean arg0)
+ {
+ serverSocket.setUseClientMode(arg0);
+ }
+ public void setWantClientAuth(boolean arg0)
+ {
+ serverSocket.setWantClientAuth(arg0);
+ }
+ }
+
+ static class SSLTestSocket extends SSLSocket
+ {
+ int timeout;
+ int initialWrites;
+ SSLSocket socket;
+ SocketAddress endpoint;
+
+ public SSLTestSocket(int timeout, int initialWrites, SSLSocket socket)
+ {
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ }
+ public SSLTestSocket(String host, int port, int timeout, int initialWrites, SSLSocket socket) throws UnknownHostException, IOException
+ {
+ super(host, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ connect(new InetSocketAddress(host, port), timeout);
+ }
+ public SSLTestSocket(InetAddress address, int port, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(address, port);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ connect(new InetSocketAddress(address, port), timeout);
+ }
+ public SSLTestSocket(String host, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(host, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ bind(new InetSocketAddress(localAddr, localPort));
+ connect(new InetSocketAddress(host, port), timeout);
+ }
+ public SSLTestSocket(InetAddress address, int port, InetAddress localAddr, int localPort, int timeout, int initialWrites, SSLSocket socket) throws IOException
+ {
+ super(address, port, localAddr, localPort);
+ this.timeout = timeout;
+ this.initialWrites = initialWrites;
+ this.socket = socket;
+ bind(new InetSocketAddress(localAddr, localPort));
+ connect(new InetSocketAddress(address, port), timeout);
+ }
+ public String toString()
+ {
+ return "SSLTestSocket[" + socket.toString() + "]";
+ }
+ public InputStream getInputStream() throws IOException
+ {
+ return socket.getInputStream();
+ }
+ public OutputStream getOutputStream() throws IOException
+ {
+ return new TestOutputStream(socket.getOutputStream(), timeout, initialWrites);
+ }
+ public void addHandshakeCompletedListener(HandshakeCompletedListener listener)
+ {
+ socket.addHandshakeCompletedListener(listener);
+ }
+ public void bind(SocketAddress bindpoint) throws IOException
+ {
+ if (socket != null)
+ socket.bind(bindpoint);
+ }
+ public void connect(SocketAddress endpoint) throws IOException
+ {
+ if (socket != null)
+ socket.connect(endpoint);
+ }
+ public void connect(SocketAddress endpoint, int timeout) throws IOException
+ {
+ socket.connect(endpoint, timeout);
+ }
+ public boolean getEnableSessionCreation()
+ {
+ return socket.getEnableSessionCreation();
+ }
+ public String[] getEnabledCipherSuites()
+ {
+ return socket.getEnabledCipherSuites();
+ }
+ public String[] getEnabledProtocols()
+ {
+ return socket.getEnabledProtocols();
+ }
+ public InetAddress getInetAddress()
+ {
+ return socket.getInetAddress();
+ }
+ public boolean getNeedClientAuth()
+ {
+ return socket.getNeedClientAuth();
+ }
+ public SSLSession getSession()
+ {
+ return socket.getSession();
+ }
+ public String[] getSupportedCipherSuites()
+ {
+ return socket.getSupportedCipherSuites();
+ }
+ public String[] getSupportedProtocols()
+ {
+ return socket.getSupportedProtocols();
+ }
+ public boolean getUseClientMode()
+ {
+ return socket.getUseClientMode();
+ }
+ public boolean getWantClientAuth()
+ {
+ return socket.getWantClientAuth();
+ }
+ public void removeHandshakeCompletedListener(HandshakeCompletedListener listener)
+ {
+ socket.removeHandshakeCompletedListener(listener);
+ }
+ public void setEnableSessionCreation(boolean flag)
+ {
+ socket.setEnableSessionCreation(flag);
+ }
+ public void setEnabledCipherSuites(String[] suites)
+ {
+ socket.setEnabledCipherSuites(suites);
+ }
+ public void setEnabledProtocols(String[] protocols)
+ {
+ socket.setEnabledProtocols(protocols);
+ }
+ public void setNeedClientAuth(boolean need)
+ {
+ socket.setNeedClientAuth(need);
+ }
+ public void setUseClientMode(boolean mode)
+ {
+ socket.setUseClientMode(mode);
+ }
+ public void setWantClientAuth(boolean want)
+ {
+ socket.setWantClientAuth(want);
+ }
+ public void startHandshake() throws IOException
+ {
+ socket.startHandshake();
+ }
+ }
+}
15 years, 3 months