JBoss Remoting SVN: r5351 - remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-17 22:17:27 -0400 (Mon, 17 Aug 2009)
New Revision: 5351
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java
Log:
JBREM-1145: Uses "remotingContentType" to determine of payload is a String.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java 2009-08-17 22:27:22 UTC (rev 5350)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java 2009-08-18 02:17:27 UTC (rev 5351)
@@ -26,7 +26,6 @@
import org.jboss.remoting.marshal.UnMarshaller;
import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
import org.jboss.remoting.transport.http.HTTPMetadataConstants;
-import org.jboss.remoting.transport.web.WebUtil;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
@@ -234,23 +233,22 @@
if(metadata != null)
{
// need to get the content type
- Object value = metadata.get("Content-Type");
- if(value == null)
+ String remotingContentType = null;
+ Object o = metadata.get(HTTPMetadataConstants.REMOTING_CONTENT_TYPE);
+ if (o instanceof List)
{
- value = metadata.get("content-type");
+ remotingContentType = (String) ((List) o).get(0);
}
- if(value != null)
+ else if (o instanceof String)
{
- if(value instanceof List)
- {
- List valueList = (List) value;
- if(valueList != null && valueList.size() > 0)
- {
- value = valueList.get(0);
- }
- }
- isBinary = WebUtil.isBinary((String) value);
+ remotingContentType = (String) o;
}
+ else
+ {
+ log.warn(this + " unrecognized remotingContentType: " + o);
+ }
+
+ isBinary = HTTPMetadataConstants.REMOTING_CONTENT_TYPE_NON_STRING.equals(remotingContentType);
}
return isBinary;
}
15 years, 2 months
JBoss Remoting SVN: r5350 - remoting2/branches/2.2/src/main/org/jboss/remoting/transport/servlet.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-17 18:27:22 -0400 (Mon, 17 Aug 2009)
New Revision: 5350
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java
Log:
JBREM-1146: Removed calls to log.info().
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java 2009-08-17 21:11:26 UTC (rev 5349)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java 2009-08-17 22:27:22 UTC (rev 5350)
@@ -311,9 +311,7 @@
// UnMarshaller may not be an HTTPUnMarshaller, in which case it
// can ignore this parameter.
- log.info("configuration: " + configuration);
Object o = configuration.get(HTTPUnMarshaller.PRESERVE_LINES);
- log.info("preserveLines: " + o);
if (o != null)
{
if (o instanceof String[])
15 years, 2 months
JBoss Remoting SVN: r5349 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-17 17:11:26 -0400 (Mon, 17 Aug 2009)
New Revision: 5349
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java
Log:
JBREM-1120: Various fixes.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java 2009-08-17 21:10:24 UTC (rev 5348)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/SSLWriteTimeoutTestParent.java 2009-08-17 21:11:26 UTC (rev 5349)
@@ -333,26 +333,86 @@
}
public Socket createSocket() throws IOException
{
- return new SSLTestSocket(timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest)
+ {
+ s = factory.createSocket();
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
}
public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
{
- return new SSLTestSocket(arg0, arg1, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
}
public Socket createSocket(InetAddress arg0, int arg1) throws IOException
{
- return new SSLTestSocket(arg0, arg1, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
}
public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
{
- return new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
}
public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
{
- return new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = factory.createSocket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ s = new SSLTestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites, ((SSLSocket) factory.createSocket()));
+ }
+ log.info(this + " returning " + s);
+ return s;
}
protected void setupFactory() throws IOException
15 years, 2 months
JBoss Remoting SVN: r5348 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-17 17:10:24 -0400 (Mon, 17 Aug 2009)
New Revision: 5348
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
Log:
JBREM-1120: Various fixes.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java 2009-08-16 01:48:47 UTC (rev 5347)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/socket/timeout/WriteTimeoutTestParent.java 2009-08-17 21:10:24 UTC (rev 5348)
@@ -102,6 +102,7 @@
}
TestOutputStream.counter = 0;
+ callbackTest = false;
}
@@ -110,7 +111,7 @@
}
- public void xtestClientWriteTimeout() throws Throwable
+ public void testClientWriteTimeout() throws Throwable
{
log.info("entering " + getName());
@@ -122,7 +123,7 @@
HashMap clientConfig = new HashMap();
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
clientConfig.put(SocketWrapper.WRITE_TIMEOUT, "1000");
- SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(-1)});
+ SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(1)});
clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
addExtraClientConfig(clientConfig);
Client client = new Client(clientLocator, clientConfig);
@@ -160,12 +161,12 @@
}
- public void xtestServerWriteTimeout() throws Throwable
+ public void testServerWriteTimeout() throws Throwable
{
log.info("entering " + getName());
// Start server.
- setupServer(true, false, "1000", 5000, -1);
+ setupServer(true, false, "1000", 5000, 1);
// Create client.
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
@@ -219,12 +220,27 @@
log.info("entering " + getName());
// Start server.
+ if (isBisocket(getTransport()))
+ {
+ callbackTest = true;
+ }
setupServer(false, false, "", -1, -1);
// Create client.
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
HashMap clientConfig = new HashMap();
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
+ clientConfig.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+ if (isBisocket(getTransport()))
+ {
+ SocketFactory sf = (SocketFactory) getSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(1)});
+ clientConfig.put(Remoting.CUSTOM_SOCKET_FACTORY, sf);
+ }
+ else
+ {
+ ServerSocketFactory ssf = (ServerSocketFactory) getServerSocketFactoryConstructor().newInstance(new Object[]{new Integer(5000), new Integer(-1)});
+ clientConfig.put(Remoting.CUSTOM_SERVER_SOCKET_FACTORY, ssf);
+ }
addExtraClientConfig(clientConfig);
Client client = new Client(clientLocator, clientConfig);
client.connect();
@@ -243,7 +259,7 @@
HashMap metadata = new HashMap();
if (isBisocket(getTransport()))
{
- metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+// metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
metadata.put(Remoting.SOCKET_FACTORY_NAME, getSocketFactoryClassName());
metadata.put("numberOfCallRetries", "1");
metadata.put(Bisocket.IS_CALLBACK_SERVER, "true");
@@ -251,7 +267,7 @@
}
else
{
- metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
+// metadata.put(SocketWrapper.WRITE_TIMEOUT, "1000");
metadata.put(ServerInvoker.SERVER_SOCKET_FACTORY, getServerSocketFactoryClassName());
metadata.put("numberOfCallRetries", "1");
}
@@ -278,7 +294,7 @@
}
- public void xtestServerCallbackWriteTimeout() throws Throwable
+ public void testServerCallbackWriteTimeout() throws Throwable
{
log.info("entering " + getName());
@@ -290,7 +306,7 @@
}
else
{
- setupServer(false, true, "1000", 5000, -1);
+ setupServer(false, true, "1000", 5000, 1);
}
// Create client.
@@ -341,7 +357,10 @@
assertTrue(t.getCause() instanceof CannotConnectException);
log.info("t.getCause().getCause(): ", t.getCause().getCause());
assertTrue(t.getCause().getCause() instanceof InvocationTargetException);
- assertTrue(t.getCause().getCause().getCause() instanceof SSLProtocolException);
+ log.info("t.getCause().getCause().getCause(): ", t.getCause().getCause().getCause());
+// assertTrue(t.getCause().getCause().getCause() instanceof SSLProtocolException);
+ assertTrue(t.getCause().getCause().getCause() instanceof IOException);
+ assertEquals("closed", t.getCause().getCause().getCause().getMessage());
}
log.info("got expected Exception");
@@ -611,26 +630,81 @@
}
public Socket createSocket()
{
- return new TestSocket(timeout, initialWrites);
+ log.info("callbackTest: " + callbackTest);
+ Socket s = null;
+ if (callbackTest)
+ {
+ s = new Socket();
+ }
+ else
+ {
+ s = new TestSocket(timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
}
public Socket createSocket(String arg0, int arg1) throws IOException, UnknownHostException
{
- return new TestSocket(arg0, arg1, timeout, initialWrites);
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
}
public Socket createSocket(InetAddress arg0, int arg1) throws IOException
{
- return new TestSocket(arg0, arg1, timeout, initialWrites);
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
}
public Socket createSocket(String arg0, int arg1, InetAddress arg2, int arg3) throws IOException, UnknownHostException
{
- return new TestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites);
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
}
public Socket createSocket(InetAddress arg0, int arg1, InetAddress arg2, int arg3) throws IOException
{
- return new TestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites);
+ log.info("callbackTest: " + callbackTest + ", port: " + arg1);
+ Socket s = null;
+ if (callbackTest && arg1 != secondaryServerSocketPort)
+ {
+ s = new Socket(arg0, arg1);
+ }
+ else
+ {
+ s = new TestSocket(arg0, arg1, arg2, arg3, timeout, initialWrites);
+ }
+ log.info(this + " returning " + s);
+ return s;
}
}
@@ -701,6 +775,7 @@
}
public void write(int b) throws IOException
{
+ System.out.print("b: " + b);
if (closed)
{
log.info("TestOutputStream closed, cannot write");
@@ -722,6 +797,12 @@
}
public void write(byte b[], int off, int len) throws IOException
{
+ System.out.print("b: ");
+ for (int i = 0; i < len; i++)
+ {
+ System.out.print(b[i] + " ");
+ }
+ System.out.println("");
if (closed)
{
log.info("TestOutputStream closed, cannot write");
@@ -740,13 +821,19 @@
e.printStackTrace();
}
}
+ if (closed)
+ {
+ log.info("TestOutputStream closed, cannot write");
+ throw new IOException("closed");
+ }
try
{
- log.info(this + " writing");
+ log.info(this + " calling write()");
doWait = false;
os.write(b, off, len);
+ os.flush();
doWait = true;
- log.info(this + " back from writing");
+ log.info(this + " back from write()");
}
catch (IOException e)
{
15 years, 2 months
JBoss Remoting SVN: r5347 - remoting2/branches/2.2/docs/guide/en.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-15 21:48:47 -0400 (Sat, 15 Aug 2009)
New Revision: 5347
Modified:
remoting2/branches/2.2/docs/guide/en/chap5.xml
Log:
JBREM-1142: Added discussion of the role of the "clientConnectAddress" and "clientConnectPort" parameters.
Modified: remoting2/branches/2.2/docs/guide/en/chap5.xml
===================================================================
--- remoting2/branches/2.2/docs/guide/en/chap5.xml 2009-08-16 01:44:24 UTC (rev 5346)
+++ remoting2/branches/2.2/docs/guide/en/chap5.xml 2009-08-16 01:48:47 UTC (rev 5347)
@@ -931,6 +931,27 @@
<para>If no client connect address or server bind address specified,
will use the local host's address (via
<code>InetAddress.getLocalHost().getHostAddress()</code> ).</para>
+
+ <para><emphasis role="bold">Note</emphasis> The role played by "clientConnectAddress"
+ and "clientConnectPort" deserves some further elaboration. When a server
+ is set up, it is either given an <classname>InvokerLocator</classname> explicitly,
+ or it is given enough information in an MBean XML file from which to construct an
+ <classname>InvokerLocator</classname>, and a client uses the host field and
+ port field in the <classname>InvokerLocator</classname> to determine how to connect to
+ the server. It follows that if an explicit <classname>InvokerLocator</classname>
+ is passed to the server, then the host and port fields are either given explicitly
+ or are generated, so there is no need for "clientConnectAddress" or "clientConnectPort"
+ fields. However, if the server is configured by way of an MBean XML file, and no explicit
+ <classname>InvokerLocator</classname> is specified, then the "clientConnectAddress"
+ and "clientConnectPort" parameters can be used to specify the host and port
+ fields in the <classname>InvokerLocator</classname>. If they are omitted, then
+ the host and port fields will be derived from the values of the "serverBindAddress"
+ and "serverBindPort" parameters (or generated, if those fields are omitted).
+ Therefore, there is a role for the "clientConnectAddress" and "clientConnectPort"
+ parameters <emphasis role="bold">only if</emphasis> clients are meant to connect
+ to a host and port different than the bind host and bind port. Such a situation
+ might occur in the presence of a translating firewall between the client and the
+ server.</para>
</section>
<section>
15 years, 2 months
JBoss Remoting SVN: r5346 - remoting2/branches/2.x/docs/guide/en.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-15 21:44:24 -0400 (Sat, 15 Aug 2009)
New Revision: 5346
Modified:
remoting2/branches/2.x/docs/guide/en/chap5.xml
Log:
JBREM-1142: Added discussion of the role of the "clientConnectAddress" and "clientConnectPort" parameters.
Modified: remoting2/branches/2.x/docs/guide/en/chap5.xml
===================================================================
--- remoting2/branches/2.x/docs/guide/en/chap5.xml 2009-08-16 01:19:13 UTC (rev 5345)
+++ remoting2/branches/2.x/docs/guide/en/chap5.xml 2009-08-16 01:44:24 UTC (rev 5346)
@@ -1273,6 +1273,29 @@
<para>If no client connect address or server bind address specified,
will use the local host's address (via
<code>InetAddress.getLocalHost().getHostAddress()</code> ).</para>
+
+ <para><emphasis role="bold">Note</emphasis> The role played by "clientConnectAddress"
+ and "clientConnectPort" deserves some further elaboration. When a server
+ is set up, it is either given an <classname>InvokerLocator</classname> explicitly,
+ or it is given enough information in an MBean XML file or a
+ <classname>ServerConfiguration</classname> POJO from which to construct an
+ <classname>InvokerLocator</classname>, and a client uses the host field and
+ port field in the <classname>InvokerLocator</classname> to determine how to connect to
+ the server. It follows that if an explicit <classname>InvokerLocator</classname>
+ is passed to the server, then the host and port fields are either given explicitly
+ or are generated, so there is no need for "clientConnectAddress" or "clientConnectPort"
+ fields. However, if the server is configured by way of an MBean XML file or
+ a <classname>ServerConfiguration</classname>, and no explicit
+ <classname>InvokerLocator</classname> is specified, then the "clientConnectAddress"
+ and "clientConnectPort" parameters can be used to specify the host and port
+ fields in the <classname>InvokerLocator</classname>. If they are omitted, then
+ the host and port fields will be derived from the values of the "serverBindAddress"
+ and "serverBindPort" parameters (or generated, if those fields are omitted).
+ Therefore, there is a role for the "clientConnectAddress" and "clientConnectPort"
+ parameters <emphasis role="bold">only if</emphasis> clients are meant to connect
+ to a host and port different than the bind host and bind port. Such a situation
+ might occur in the presence of a translating firewall between the client and the
+ server.</para>
</section>
<section>
15 years, 2 months
JBoss Remoting SVN: r5345 - remoting2/branches/2.2/docs/guide/en.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-15 21:19:13 -0400 (Sat, 15 Aug 2009)
New Revision: 5345
Modified:
remoting2/branches/2.2/docs/guide/en/chap5.xml
Log:
JBREM-1139: Added paragraph about adjustability of PortUtil search range.
Modified: remoting2/branches/2.2/docs/guide/en/chap5.xml
===================================================================
--- remoting2/branches/2.2/docs/guide/en/chap5.xml 2009-08-16 01:13:58 UTC (rev 5344)
+++ remoting2/branches/2.2/docs/guide/en/chap5.xml 2009-08-16 01:19:13 UTC (rev 5345)
@@ -988,6 +988,22 @@
because either the serverBindPort or the original InvokerLocator port
value was either 0 or negative, the InvokerLocator will be updated to
reflect the new port value.</para>
+
+ <para><emphasis role="bold">Note.</emphasis>
+ In the case that a bind port isn't specified, the utility class
+ <classname>org.jboss.remoting.transport.PortUtil</classname> is used to
+ supply an available port. By default, it will look for a port in the range
+ 1024 to 65535, inclusively. As of release 2.2.3.SP1, PortUtil can be configured
+ to search a smaller range by setting the values PortUtil.MIN_PORT (actual
+ value "minPort") and / or PortUtil.MAX_PORT (actual value "maxPort") in
+ the InvokerLocator, a configuration map, an MBean XML file. The range is static;
+ that is, whenever "minPort" or "maxPort" are set, they affect all
+ subsequent calls in the JVM. Note that <classname>PortUtil</classname>
+ will apply a new "minPort" value only if it is greater than the current
+ value, and it will apply a new "maxPort" value only if it is less than
+ the current value. And it will never apply a new value when the result
+ would be such that the value of "maxPort" would be less than the value
+ of "minPort".</para>
</section>
<section>
15 years, 2 months
JBoss Remoting SVN: r5344 - remoting2/branches/2.x/docs/guide/en.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-15 21:13:58 -0400 (Sat, 15 Aug 2009)
New Revision: 5344
Modified:
remoting2/branches/2.x/docs/guide/en/chap5.xml
Log:
JBREM-1139: Added paragraph about adjustability of PortUtil search range.
Modified: remoting2/branches/2.x/docs/guide/en/chap5.xml
===================================================================
--- remoting2/branches/2.x/docs/guide/en/chap5.xml 2009-08-15 03:22:19 UTC (rev 5343)
+++ remoting2/branches/2.x/docs/guide/en/chap5.xml 2009-08-16 01:13:58 UTC (rev 5344)
@@ -1322,6 +1322,23 @@
because either the serverBindPort or the original InvokerLocator port
value was either 0 or negative, the InvokerLocator will be updated to
reflect the new port value.</para>
+
+ <para><emphasis role="bold">Note.</emphasis>
+ In the case that a bind port isn't specified, the utility class
+ <classname>org.jboss.remoting.transport.PortUtil</classname> is used to
+ supply an available port. By default, it will look for a port in the range
+ 1024 to 65535, inclusively. As of release 2.5.2, PortUtil can be configured
+ to search a smaller range by setting the values PortUtil.MIN_PORT (actual
+ value "minPort") and / or PortUtil.MAX_PORT (actual value "maxPort") in
+ the InvokerLocator, a configuration map, an MBean XML file, or a
+ <classname>ServerConfiguration</classname> object. The range is static;
+ that is, whenever "minPort" or "maxPort" are set, they affect all
+ subsequent calls in the JVM. Note that <classname>PortUtil</classname>
+ will apply a new "minPort" value only if it is greater than the current
+ value, and it will apply a new "maxPort" value only if it is less than
+ the current value. And it will never apply a new value when the result
+ would be such that the value of "maxPort" would be less than the value
+ of "minPort".</para>
</section>
<section>
15 years, 2 months
JBoss Remoting SVN: r5343 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-08-14 23:22:19 -0400 (Fri, 14 Aug 2009)
New Revision: 5343
Added:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnClientTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithServerConfigurationTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithXMLTestCase.java
Log:
JBREM-1139: New unit tests.
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnClientTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnClientTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnClientTestCase.java 2009-08-15 03:22:19 UTC (rev 5343)
@@ -0,0 +1,148 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.remoting.util;
+
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.transport.PortUtil;
+
+/**
+ * Unit test for JBREM-1139.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 2320 $
+ * <p>
+ * Copyright July 13, 2009.
+ * </p>
+ */
+public class PortUtilRangeOnClientTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(PortUtilRangeOnClientTestCase.class);
+
+
+ public void testUpdateRangeOnClient() throws Exception
+ {
+ log.info("entering " + getName());
+
+ // Test initial values.
+ assertEquals(1024, PortUtil.getMinPort());
+ assertEquals(65535, PortUtil.getMaxPort());
+
+ // Set new values using configuration map.
+ Map clientConfig = new HashMap();
+ clientConfig.put(PortUtil.MIN_PORT, "2000");
+ clientConfig.put(PortUtil.MAX_PORT, "60000");
+ String host = InetAddress.getLocalHost().getHostAddress();
+ InvokerLocator locator = new InvokerLocator("socket://" + host);
+ Client client = new Client(locator, clientConfig);
+ assertEquals(2000, PortUtil.getMinPort());
+ assertEquals(60000, PortUtil.getMaxPort());
+
+ // Set more restrictive values using configuration map.
+ clientConfig.put(PortUtil.MIN_PORT, "3000");
+ clientConfig.put(PortUtil.MAX_PORT, "50000");
+ client = new Client(locator, clientConfig);
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+
+ // Set more restrictive values with InvokerLocator overriding configuration map.
+ clientConfig.put(PortUtil.MIN_PORT, "3500");
+ clientConfig.put(PortUtil.MAX_PORT, "45000");
+ locator = new InvokerLocator("socket://" + host + "/?" + PortUtil.MIN_PORT + "=4000&" + PortUtil.MAX_PORT + "=40000");
+ client = new Client(locator, clientConfig);
+ assertEquals(4000, PortUtil.getMinPort());
+ assertEquals(40000, PortUtil.getMaxPort());
+
+ // Try to set less restrictive values - should have no effect.
+ clientConfig.put(PortUtil.MIN_PORT, "2000");
+ clientConfig.put(PortUtil.MAX_PORT, "60000");
+ locator = new InvokerLocator("socket://" + host);
+ client = new Client(locator, clientConfig);
+ assertEquals(4000, PortUtil.getMinPort());
+ assertEquals(40000, PortUtil.getMaxPort());
+
+ // Try to set invalid minPort - should have no effect.
+ clientConfig.put(PortUtil.MIN_PORT, "60000");
+ clientConfig.remove(PortUtil.MAX_PORT);
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ client = new Client(locator, clientConfig);
+ }
+ catch (Exception e)
+ {
+ log.info(e.getMessage());
+ if (e instanceof IllegalStateException
+ && e.getMessage() != null
+ && e.getMessage().startsWith("trying to set minPort"))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ else
+ {
+ fail("expected IllegalStateException");
+ }
+ }
+ assertEquals(4000, PortUtil.getMinPort());
+ assertEquals(40000, PortUtil.getMaxPort());
+
+ // Try to set invalid maxPort - should have no effect.
+ clientConfig.remove(PortUtil.MIN_PORT);
+ clientConfig.put(PortUtil.MAX_PORT, "2000");
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ client = new Client(locator, clientConfig);
+ }
+ catch (Exception e)
+ {
+ log.info(e.getMessage());
+ if (e instanceof IllegalStateException
+ && e.getMessage() != null
+ && e.getMessage().startsWith("trying to set maxPort"))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ else
+ {
+ fail("expected IllegalStateException");
+ }
+ }
+ assertEquals(4000, PortUtil.getMinPort());
+ assertEquals(40000, PortUtil.getMaxPort());
+
+ log.info(getName()+ " PASSES");
+ }
+
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerTestCase.java 2009-08-15 03:22:19 UTC (rev 5343)
@@ -0,0 +1,166 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.remoting.util;
+
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+/**
+ * Unit test for JBREM-1139.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 2320 $
+ * <p>
+ * Copyright July 13, 2009.
+ * </p>
+ */
+public class PortUtilRangeOnServerTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(PortUtilRangeOnServerTestCase.class);
+
+
+
+ public void testUpdateRangeOnServer() throws Exception
+ {
+ log.info("entering " + getName());
+
+ // Test initial values.
+ assertEquals(1024, PortUtil.getMinPort());
+ assertEquals(65535, PortUtil.getMaxPort());
+
+ // Set new values using configuration mapr.
+ Map serverConfig = new HashMap();
+ serverConfig.put(PortUtil.MIN_PORT, "2000");
+ serverConfig.put(PortUtil.MAX_PORT, "60000");
+ String host = InetAddress.getLocalHost().getHostAddress();
+ InvokerLocator locator = new InvokerLocator("socket://" + host);
+ Connector connector = new Connector(locator, serverConfig);
+ connector.start();
+ log.info("InvokerLocator: " + connector.getInvokerLocator());
+ assertEquals(2000, PortUtil.getMinPort());
+ assertEquals(60000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Set more restrictive values using configuration map.
+ serverConfig.put(PortUtil.MIN_PORT, "3000");
+ serverConfig.put(PortUtil.MAX_PORT, "50000");
+ connector = new Connector(locator, serverConfig);
+ connector.start();
+ log.info("InvokerLocator: " + connector.getInvokerLocator());
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Set more restrictive values with InvokerLocator overriding configuration map.
+ serverConfig.put(PortUtil.MIN_PORT, "3500");
+ serverConfig.put(PortUtil.MAX_PORT, "45000");
+ locator = new InvokerLocator("socket://" + host + "/?" + PortUtil.MIN_PORT + "=4000&" + PortUtil.MAX_PORT + "=40000");
+ connector = new Connector(locator, serverConfig);
+ connector.start();
+ log.info("InvokerLocator: " + connector.getInvokerLocator());
+ assertEquals(4000, PortUtil.getMinPort());
+ assertEquals(40000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Try to set less restrictive values - should have no effect.
+ serverConfig.put(PortUtil.MIN_PORT, "2000");
+ serverConfig.put(PortUtil.MAX_PORT, "60000");
+ locator = new InvokerLocator("socket://" + host);
+ connector = new Connector(locator, serverConfig);
+ connector.start();
+ log.info("InvokerLocator: " + connector.getInvokerLocator());
+ assertEquals(4000, PortUtil.getMinPort());
+ assertEquals(40000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Try to set invalid minPort - should have no effect.
+ serverConfig.put(PortUtil.MIN_PORT, "60000");
+ serverConfig.remove(PortUtil.MAX_PORT);
+ connector = new Connector(locator, serverConfig);
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.info(e.getCause());
+ if (e.getCause() instanceof IllegalStateException
+ && e.getCause().getMessage() != null
+ && e.getCause().getMessage().startsWith("trying to set minPort"))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ else
+ {
+ fail("expected IllegalStateException");
+ }
+ }
+ log.info("InvokerLocator: " + connector.getInvokerLocator());
+ assertEquals(4000, PortUtil.getMinPort());
+ assertEquals(40000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Try to set invalid maxPort - should have no effect.
+ serverConfig.remove(PortUtil.MIN_PORT);
+ serverConfig.put(PortUtil.MAX_PORT, "2000");
+ connector = new Connector(locator, serverConfig);
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.info(e.getCause());
+ if (e.getCause() instanceof IllegalStateException
+ && e.getCause().getMessage() != null
+ && e.getCause().getMessage().startsWith("trying to set maxPort"))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ else
+ {
+ fail("expected IllegalStateException");
+ }
+ }
+ log.info("InvokerLocator: " + connector.getInvokerLocator());
+ assertEquals(4000, PortUtil.getMinPort());
+ assertEquals(40000, PortUtil.getMaxPort());
+ connector.stop();
+
+ log.info(getName()+ " PASSES");
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithServerConfigurationTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithServerConfigurationTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithServerConfigurationTestCase.java 2009-08-15 03:22:19 UTC (rev 5343)
@@ -0,0 +1,233 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.remoting.util;
+
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+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.InvocationRequest;
+import org.jboss.remoting.ServerConfiguration;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+
+/**
+ * Unit test for JBREM-1139.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 2320 $
+ * <p>
+ * Copyright July 13, 2009.
+ * </p>
+ */
+public class PortUtilRangeOnServerWithServerConfigurationTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(PortUtilRangeOnServerWithServerConfigurationTestCase.class);
+ private static boolean firstTime = true;
+
+
+ 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 testUpdateRangeOnServer() throws Exception
+ {
+ log.info("entering " + getName());
+
+ // Test initial values.
+ assertEquals(1024, PortUtil.getMinPort());
+ assertEquals(65535, PortUtil.getMaxPort());
+
+ // Set new values.
+ Connector connector = new Connector();
+ connector.setServerConfiguration(getServerConfiguration(2000, 60000));
+ connector.start();
+ assertEquals(2000, PortUtil.getMinPort());
+ assertEquals(60000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Set more restrictive values.
+ connector = new Connector();
+ connector.setServerConfiguration(getServerConfiguration(3000, 50000));
+ connector.start();
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Try to set less restrictive values - should have no effect.
+ connector = new Connector();
+ connector.setServerConfiguration(getServerConfiguration(2000, 60000));
+ connector.start();
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Try to set invalid minPort - should have no effect.
+ connector = new Connector();
+ connector.setServerConfiguration(getServerConfiguration(60000, -1));
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.info(e.getMessage());
+ if (e instanceof RuntimeException
+ && e.getMessage().startsWith("Error setting up server invoker")
+ && e.getCause() instanceof IllegalStateException
+ && e.getCause().getMessage() != null
+ && e.getCause().getMessage().startsWith("trying to set minPort to value greater than maxPort:"))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ else
+ {
+ fail("expected IllegalStateException: " + e.getMessage());
+ }
+ }
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Try to set invalid maxPort - should have no effect.
+ connector = new Connector();
+ connector.setServerConfiguration(getServerConfiguration(-1, 2000));
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.info(e.getMessage());
+ if (e instanceof RuntimeException
+ && e.getMessage().startsWith("Error setting up server invoker")
+ && e.getCause() instanceof IllegalStateException
+ && e.getCause().getMessage() != null
+ && e.getCause().getMessage().startsWith("trying to set maxPort to value less than minPort:"))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ else
+ {
+ fail("expected IllegalStateException");
+ }
+ }
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+ connector.stop();
+
+ log.info(getName()+ " PASSES");
+ }
+
+
+// Element getXML(int minPort, int maxPort) throws SAXException, IOException, ParserConfigurationException
+// {
+// String host = InetAddress.getLocalHost().getHostAddress();
+// StringBuffer buf = new StringBuffer();
+// buf.append("<?xml version=\"1.0\"?>\n");
+// buf.append("<config>\n");
+// buf.append(" <invoker transport=\"socket\">\n");
+// buf.append(" <attribute name=\"serverBindAddress\">" + host + "</attribute>\n");
+// if (minPort > -1)
+// {
+// buf.append(" <attribute name=\"" + PortUtil.MIN_PORT + "\">" + minPort + "</attribute>\n");
+// }
+// if (maxPort > -1)
+// {
+// buf.append(" <attribute name=\"" + PortUtil.MAX_PORT + "\">" + maxPort + "</attribute>\n");
+// }
+// buf.append(" </invoker>\n");
+// buf.append(" <handlers>\n");
+// buf.append(" <handler subsystem=\"test\">" + TestInvocationHandler.class.getName() + "</handler>\n");
+// buf.append(" </handlers>\n");
+// buf.append("</config>\n");
+// log.info("\n\n" + buf.toString());
+// ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
+// Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
+// return xml.getDocumentElement();
+// }
+
+
+ ServerConfiguration getServerConfiguration(int minPort, int maxPort) throws UnknownHostException
+ {
+ ServerConfiguration serverConfiguration = new ServerConfiguration("socket");
+ Map invokerLocatorParameters = new HashMap();
+ invokerLocatorParameters.put("serverBindAddress", InetAddress.getLocalHost().getHostAddress());
+ serverConfiguration.setInvokerLocatorParameters(invokerLocatorParameters);
+ Map serverParameters = new HashMap();
+ if (minPort > -1)
+ {
+ serverParameters.put(PortUtil.MIN_PORT, Integer.toString(minPort));
+ }
+ if (maxPort > -1)
+ {
+ serverParameters.put(PortUtil.MAX_PORT, Integer.toString(maxPort));
+ }
+ serverConfiguration.setServerParameters(serverParameters);
+ Map invocationHandlers = new HashMap();
+ invocationHandlers.put("test", TestInvocationHandler.class.getName());
+ serverConfiguration.setInvocationHandlers(invocationHandlers);
+ return serverConfiguration;
+ }
+
+ public static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ 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) {}
+ }
+}
\ No newline at end of file
Added: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithXMLTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithXMLTestCase.java (rev 0)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/util/PortUtilRangeOnServerWithXMLTestCase.java 2009-08-15 03:22:19 UTC (rev 5343)
@@ -0,0 +1,192 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.remoting.util;
+
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.InetAddress;
+
+import javax.management.MBeanServer;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.ServerInvocationHandler;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.transport.Connector;
+import org.jboss.remoting.transport.PortUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+/**
+ * Unit test for JBREM-1139.
+ *
+ * @author <a href="ron.sigal(a)jboss.com">Ron Sigal</a>
+ * @version $Revision: 2320 $
+ * <p>
+ * Copyright July 13, 2009.
+ * </p>
+ */
+public class PortUtilRangeOnServerWithXMLTestCase extends TestCase
+{
+ private static Logger log = Logger.getLogger(PortUtilRangeOnServerWithXMLTestCase.class);
+
+
+
+ public void testUpdateRangeOnServer() throws Exception
+ {
+ log.info("entering " + getName());
+
+ // Test initial values.
+ assertEquals(1024, PortUtil.getMinPort());
+ assertEquals(65535, PortUtil.getMaxPort());
+
+ // Set new values.
+ Connector connector = new Connector();
+ connector.setConfiguration(getXML(2000, 60000));
+ connector.start();
+ assertEquals(2000, PortUtil.getMinPort());
+ assertEquals(60000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Set more restrictive values.
+ connector = new Connector();
+ connector.setConfiguration(getXML(3000, 50000));
+ connector.start();
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Try to set less restrictive values - should have no effect.
+ connector = new Connector();
+ connector.setConfiguration(getXML(2000, 60000));
+ connector.start();
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Try to set invalid minPort - should have no effect.
+ connector = new Connector();
+ connector.setConfiguration(getXML(60000, -1));
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.info(e.getMessage());
+ if (e instanceof IllegalStateException
+ && e.getMessage() != null
+ && e.getMessage().startsWith("Error configuring invoker for connector."))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ else
+ {
+ fail("expected IllegalStateException");
+ }
+ }
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+ connector.stop();
+
+ // Try to set invalid maxPort - should have no effect.
+ connector = new Connector();
+ connector.setConfiguration(getXML(-1, 2000));
+ try
+ {
+ log.info("=====================================");
+ log.info("EXPECT ILLEGAL_STATE_EXCEPTION");
+ connector.start();
+ }
+ catch (Exception e)
+ {
+ log.info(e.getMessage());
+ if (e instanceof IllegalStateException
+ && e.getMessage() != null
+ && e.getMessage().startsWith("Error configuring invoker for connector."))
+ {
+ log.info("GOT EXPECTED ILLEGAL_STATE_EXCEPTION");
+ log.info("=====================================");
+ }
+ else
+ {
+ fail("expected IllegalStateException");
+ }
+ }
+ assertEquals(3000, PortUtil.getMinPort());
+ assertEquals(50000, PortUtil.getMaxPort());
+ connector.stop();
+
+ log.info(getName()+ " PASSES");
+ }
+
+
+ Element getXML(int minPort, int maxPort) throws SAXException, IOException, ParserConfigurationException
+ {
+ String host = InetAddress.getLocalHost().getHostAddress();
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\"?>\n");
+ buf.append("<config>\n");
+ buf.append(" <invoker transport=\"socket\">\n");
+ buf.append(" <attribute name=\"serverBindAddress\">" + host + "</attribute>\n");
+ if (minPort > -1)
+ {
+ buf.append(" <attribute name=\"" + PortUtil.MIN_PORT + "\">" + minPort + "</attribute>\n");
+ }
+ if (maxPort > -1)
+ {
+ buf.append(" <attribute name=\"" + PortUtil.MAX_PORT + "\">" + maxPort + "</attribute>\n");
+ }
+ buf.append(" </invoker>\n");
+ buf.append(" <handlers>\n");
+ buf.append(" <handler subsystem=\"test\">" + TestInvocationHandler.class.getName() + "</handler>\n");
+ buf.append(" </handlers>\n");
+ buf.append("</config>\n");
+ log.info("\n\n" + buf.toString());
+ ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
+ Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
+ return xml.getDocumentElement();
+ }
+
+
+ public static class TestInvocationHandler implements ServerInvocationHandler
+ {
+ public void addListener(InvokerCallbackHandler callbackHandler) {}
+ 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) {}
+ }
+}
\ No newline at end of file
15 years, 2 months
JBoss Remoting SVN: r5342 - 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:43 -0400 (Fri, 14 Aug 2009)
New Revision: 5342
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java
Log:
JBREM-1139: Supports configuration of range from which ports may be chosen.
Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java 2009-08-15 03:21:06 UTC (rev 5341)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/PortUtil.java 2009-08-15 03:21:43 UTC (rev 5342)
@@ -29,6 +29,7 @@
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.util.Map;
import java.util.Random;
import org.jboss.logging.Logger;
@@ -42,12 +43,18 @@
*/
public class PortUtil
{
+ public static final String MIN_PORT = "minPort";
+ public static final String MAX_PORT = "maxPort";
+
private static final Logger log = Logger.getLogger(PortUtil.class);
private static final int MIN_UNPRIVILEGED_PORT = 1024;
private static final int MAX_LEGAL_PORT = 65535;
private static int portCounter = 0;
private static int retryMax = 50;
+
+ private static int minPort = MIN_UNPRIVILEGED_PORT;
+ private static int maxPort = MAX_LEGAL_PORT;
static
{
@@ -163,20 +170,111 @@
private static synchronized int getNextPort()
{
- if (portCounter < MAX_LEGAL_PORT)
+ if (portCounter < maxPort)
return portCounter++;
- portCounter = MIN_UNPRIVILEGED_PORT;
- return MAX_LEGAL_PORT;
+ portCounter = minPort;
+ return maxPort;
}
public static int getRandomStartingPort()
{
- int range = MAX_LEGAL_PORT - MIN_UNPRIVILEGED_PORT + 1;
- int port = new Random(System.currentTimeMillis()).nextInt(range) + MIN_UNPRIVILEGED_PORT;
+ int range = maxPort - minPort + 1;
+ int port = new Random(System.currentTimeMillis()).nextInt(range) + minPort;
return port;
}
+
+ public static synchronized int getMinPort()
+ {
+ return minPort;
+ }
+ public static synchronized void setMinPort(int minPort) throws IllegalStateException
+ {
+ if (minPort > PortUtil.maxPort)
+ {
+ String msg = "trying to set minPort to value greater than maxPort: " + minPort + " > " + PortUtil.maxPort;
+ log.debug(msg);
+ throw new IllegalStateException(msg);
+ }
+ if (minPort < PortUtil.minPort)
+ {
+ log.debug("will not set minPort to " + minPort + ": minPort is already " + PortUtil.minPort);
+ return;
+ }
+ log.debug("setting minPort to " + minPort);
+ PortUtil.minPort = minPort;
+ }
+
+ public static synchronized int getMaxPort()
+ {
+ return maxPort;
+ }
+
+ public static synchronized void setMaxPort(int maxPort)
+ {
+ if (maxPort < PortUtil.minPort)
+ {
+ String msg = "trying to set maxPort to value less than minPort: " + maxPort + " < " + PortUtil.minPort;
+ log.debug(msg);
+ throw new IllegalStateException(msg);
+ }
+ if (maxPort > PortUtil.maxPort)
+ {
+ log.debug("will not set maxPort to " + maxPort + ": maxPort is already " + PortUtil.maxPort);
+ return;
+ }
+ log.debug("setting maxPort to " + maxPort);
+ PortUtil.maxPort = maxPort;
+ }
+
+ public static synchronized void updateRange(Map config)
+ {
+ if (config != null)
+ {
+ int savedMinPort = getMinPort();
+ Object o = config.get(MIN_PORT);
+ if (o instanceof String)
+ {
+ try
+ {
+ setMinPort(Integer.parseInt((String) o));
+ }
+ catch (NumberFormatException e)
+ {
+ log.error("minPort parameter has invalid format: " + o);
+ }
+ }
+ else if (o != null)
+ {
+ log.error("minPort parameter must be a string in integer format: " + o);
+ }
+
+ int savedMaxPort = getMaxPort();
+ o = config.get(MAX_PORT);
+ if (o instanceof String)
+ {
+ try
+ {
+ setMaxPort(Integer.parseInt((String) o));
+ }
+ catch (NumberFormatException e)
+ {
+ log.error("maxPort parameter has invalid format: " + o);
+ }
+ }
+ else if (o != null)
+ {
+ log.error("maxPort parameter must be a string in integer format: " + o);
+ }
+
+ if (savedMinPort != getMinPort() || savedMaxPort != getMaxPort())
+ {
+ portCounter = getRandomStartingPort();
+ }
+ }
+ }
+
public static void main(String args[])
{
try
15 years, 2 months