tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1207695 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/catalina/connector/ java/org/apache/coyote/ java/org/apache/tomcat/util/net/ test/org/apache/catalina/authenticator/ test/org/apache/catalina/connector/ test/org/apache/catalina/core/ ...
Date Mon, 28 Nov 2011 23:20:59 GMT
Author: markt
Date: Mon Nov 28 23:20:46 2011
New Revision: 1207695

URL: http://svn.apache.org/viewvc?rev=1207695&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=52028
Add support for automatic selection of a free port for a connector when the special value of zero is used

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Connector.java
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/mbeans-descriptors.xml
    tomcat/tc7.0.x/trunk/java/org/apache/coyote/AbstractProtocol.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/connector/TestConnector.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/connector/TestRequest.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestStandardContext.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestSwallowAbortedUploads.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/filters/TestExpiresFilter.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/filters/TestRemoteIpFilter.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/mbeans/TestRegistration.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java
    tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
    tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
    tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java
    tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
    tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java
    tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowHttpSeps.java
    tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowNameOnly.java
    tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesDisallowEquals.java
    tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/net/TestXxxEndpoint.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
    tomcat/tc7.0.x/trunk/webapps/docs/config/ajp.xml
    tomcat/tc7.0.x/trunk/webapps/docs/config/http.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov 28 23:20:46 2011
@@ -1 +1 @@
-/tomcat/trunk:1156115,1156171,1156276,1156304,1156519,1156530,1156602,1157015,1157018,1157151,1157198,1157204,1157810,1157832,1157834,1157847,1157908,1157939,1158155,1158160,1158176,1158195,1158198-1158199,1158227,1158331,1158334-1158335,1158426,1160347,1160592,1160611,1160619,1160626,1160639,1160652,1160720-1160721,1160772,1160774,1160776,1161303,1161310,1161322,1161339,1161486,1161540,1161549,1161584,1162082,1162149,1162169,1162721,1162769,1162836,1162932,1163630,1164419,1164438,1164469,1164480,1164567,1165234,1165247-1165248,1165253,1165273,1165282,1165309,1165331,1165338,1165347,1165360-1165361,1165367-1165368,1165602,1165608,1165677,1165693,1165721,1165723,1165728,1165730,1165738,1165746,1165765,1165777,1165918,1165921,1166077,1166150-1166151,1166290,1166366,1166620,1166686,1166693,1166752,1166757,1167368,1167394,1169447,1170647,1171692,1172233-1172234,1172236,1172269,1172278,1172282,1172556,1172610,1172664,1172689,1172711,1173020-1173021,1173082,1173088,1173090,1173096
 ,1173241,1173256,1173288,1173333,1173342,1173461,1173614,1173630,1173659,1173722,1174061,1174239,1174322,1174325,1174329-1174330,1174337-1174339,1174343,1174353,1174799,1174882,1174884,1174983,1175155,1175158,1175167,1175182,1175190,1175201,1175272,1175275,1175283,1175582,1175589-1175590,1175594,1175602,1175613,1175633,1175690,1175713,1175798,1175889,1175896,1175907,1176584,1176590,1176799,1177050,1177060,1177125,1177152,1177160,1177245,1177850,1177862,1177978,1178209,1178228,1178233,1178449,1178542,1178681,1178684,1178721,1179268,1179274,1180261,1180865,1180891,1180894,1180907,1181028,1181123,1181125,1181136,1181291,1181743,1182796,1183078,1183105,1183142,1183328,1183339-1183340,1183492-1183494,1183605,1184917,1184919,1185018,1185020,1185200,1185588,1185626,1185756,1185758,1186011,1186042-1186045,1186104,1186123,1186137,1186153,1186254,1186257,1186377-1186379,1186479-1186480,1186712,1186743,1186750,1186763,1186890-1186892,1186894,1186949,1187018,1187027-1187028,1187381,1187
 753,1187755,1187775,1187801,1187806,1187809,1187827,1188301,1188303-1188305,1188399,1188822,1188930-1188931,1189116,1189129,1189183,1189240,1189256,1189386,1189413-1189414,1189477,1189685,1189805,1189857,1189864,1189882,1190034,1190185,1190279,1190339,1190371,1190388-1190389,1190474,1190481,1194915,1195222-1195223,1195531,1195899,1195905,1195943,1195949,1195953,1195955,1195965,1195968,1196175,1196212,1196223,1196304-1196305,1196735,1196825,1196827,1197158,1197261,1197263,1197299-1197300,1197305,1197339-1197340,1197343,1197382,1197386-1197387,1197480,1197578,1198497,1198528,1198552,1198602,1198604,1198607,1198622,1198640,1198696,1198707,1199418,1199432,1199436,1199513,1199529,1199980,1199996,1200056,1200089,1200106-1200107,1200263,1200316,1200320,1200398-1200399,1200445-1200446,1200555,1200627,1200696,1200725,1200937,1200941,1201069,1201087,1201180,1201235-1201237,1201508,1201521,1201542,1201545-1201546,1201548,1201555-1201556,1201568,1201576,1201608,1201921-1201922,1201931,1
 202035,1202039,1202271,1202565,1202578,1202705,1202828,1202860,1203047-1203052,1203078,1203091,1203253,1203278,1204182,1204856,1204867,1204936,1204938,1204982,1205033,1205065,1205082,1205097,1205112,1206200
+/tomcat/trunk:1156115,1156171,1156276,1156304,1156519,1156530,1156602,1157015,1157018,1157151,1157198,1157204,1157810,1157832,1157834,1157847,1157908,1157939,1158155,1158160,1158176,1158195,1158198-1158199,1158227,1158331,1158334-1158335,1158426,1160347,1160592,1160611,1160619,1160626,1160639,1160652,1160720-1160721,1160772,1160774,1160776,1161303,1161310,1161322,1161339,1161486,1161540,1161549,1161584,1162082,1162149,1162169,1162721,1162769,1162836,1162932,1163630,1164419,1164438,1164469,1164480,1164567,1165234,1165247-1165248,1165253,1165273,1165282,1165309,1165331,1165338,1165347,1165360-1165361,1165367-1165368,1165602,1165608,1165677,1165693,1165721,1165723,1165728,1165730,1165738,1165746,1165765,1165777,1165918,1165921,1166077,1166150-1166151,1166290,1166366,1166620,1166686,1166693,1166752,1166757,1167368,1167394,1169447,1170647,1171692,1172233-1172234,1172236,1172269,1172278,1172282,1172556,1172610,1172664,1172689,1172711,1173020-1173021,1173082,1173088,1173090,1173096
 ,1173241,1173256,1173288,1173333,1173342,1173461,1173614,1173630,1173659,1173722,1174061,1174239,1174322,1174325,1174329-1174330,1174337-1174339,1174343,1174353,1174799,1174882,1174884,1174983,1175155,1175158,1175167,1175182,1175190,1175201,1175272,1175275,1175283,1175582,1175589-1175590,1175594,1175602,1175613,1175633,1175690,1175713,1175798,1175889,1175896,1175907,1176584,1176590,1176799,1177050,1177060,1177125,1177152,1177160,1177245,1177850,1177862,1177978,1178209,1178228,1178233,1178449,1178542,1178681,1178684,1178721,1179268,1179274,1180261,1180865,1180891,1180894,1180907,1181028,1181123,1181125,1181136,1181291,1181743,1182796,1183078,1183105,1183142,1183328,1183339-1183340,1183492-1183494,1183605,1184917,1184919,1185018,1185020,1185200,1185588,1185626,1185756,1185758,1186011,1186042-1186045,1186104,1186123,1186137,1186153,1186254,1186257,1186377-1186379,1186479-1186480,1186712,1186743,1186750,1186763,1186890-1186892,1186894,1186949,1187018,1187027-1187028,1187381,1187
 753,1187755,1187775,1187801,1187806,1187809,1187827,1188301,1188303-1188305,1188399,1188822,1188930-1188931,1189116,1189129,1189183,1189240,1189256,1189386,1189413-1189414,1189477,1189685,1189805,1189857,1189864,1189882,1190034,1190185,1190279,1190339,1190371,1190388-1190389,1190474,1190481,1194915,1195222-1195223,1195531,1195899,1195905,1195943,1195949,1195953,1195955,1195965,1195968,1196175,1196212,1196223,1196304-1196305,1196735,1196825,1196827,1197158,1197261,1197263,1197299-1197300,1197305,1197339-1197340,1197343,1197382,1197386-1197387,1197480,1197578,1198497,1198528,1198552,1198602,1198604,1198607,1198622,1198640,1198696,1198707,1199418,1199432,1199436,1199513,1199529,1199980,1199996,1200056,1200089,1200106-1200107,1200263,1200316,1200320,1200398-1200399,1200445-1200446,1200555,1200627,1200696,1200725,1200937,1200941,1201069,1201087,1201180,1201235-1201237,1201508,1201521,1201542,1201545-1201546,1201548,1201555-1201556,1201568,1201576,1201608,1201921-1201922,1201931,1
 202035,1202039,1202271,1202565,1202578,1202705,1202828,1202860,1203047-1203052,1203078,1203091,1203253,1203278,1204182,1204856,1204867,1204936,1204938,1204982,1205033,1205065,1205082,1205097,1205112,1206200,1207692

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Connector.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Connector.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Connector.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/Connector.java Mon Nov 28 23:20:46 2011
@@ -60,7 +60,6 @@ public class Connector extends Lifecycle
 
     // ------------------------------------------------------------ Constructor
 
-
     public Connector() {
         this(null);
     }
@@ -121,7 +120,7 @@ public class Connector extends Lifecycle
     /**
      * The port number on which we listen for requests.
      */
-    protected int port = 0;
+    protected int port = -1;
 
 
     /**
@@ -264,7 +263,6 @@ public class Connector extends Lifecycle
 
     // ------------------------------------------------------------- Properties
 
-
     /**
      * Return a configured property.
      */
@@ -514,7 +512,9 @@ public class Connector extends Lifecycle
     }
 
     /**
-     * Return the port number on which we listen for requests.
+     * Return the port number on which this connector is configured to listen
+     * for requests. The special value of 0 means select a random free port
+     * when the socket is bound.
      */
     public int getPort() {
 
@@ -537,6 +537,16 @@ public class Connector extends Lifecycle
 
 
     /**
+     * Return the port number on which this connector is listening to requests.
+     * If the special value for {@link #port} of zero is used then this method
+     * will report the actual port bound.
+     */
+    public int getLocalPort() {
+        return ((Integer) getProperty("localPort")).intValue();
+    }
+
+
+    /**
      * Return the Coyote protocol handler in use.
      */
     public String getProtocol() {
@@ -881,7 +891,13 @@ public class Connector extends Lifecycle
         StringBuilder sb = new StringBuilder("type=");
         sb.append(type);
         sb.append(",port=");
-        sb.append(getPort());
+        int port = getPort();
+        if (port > 0) {
+            sb.append(getPort());
+        } else {
+            sb.append("auto-");
+            sb.append(getProperty("nameIndex"));
+        }
         if (addressObj != null) {
             String address = addressObj.toString();
             if (address.length() > 0) {
@@ -955,7 +971,7 @@ public class Connector extends Lifecycle
     protected void startInternal() throws LifecycleException {
 
         // Validate settings before starting
-        if (getPort() < 1) {
+        if (getPort() < 0) {
             throw new LifecycleException(sm.getString(
                     "coyoteConnector.invalidPort", Integer.valueOf(getPort())));
         }
@@ -1031,11 +1047,18 @@ public class Connector extends Lifecycle
         StringBuilder sb = new StringBuilder("Connector[");
         sb.append(getProtocol());
         sb.append('-');
-        sb.append(getPort());
+        int port = getPort();
+        if (port > 0) {
+            sb.append(getPort());
+        } else {
+            sb.append("auto-");
+            sb.append(getProperty("nameIndex"));
+        }
         sb.append(']');
         return sb.toString();
     }
 
+
     // -------------------- JMX registration  --------------------
 
     @Override

Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/mbeans-descriptors.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/mbeans-descriptors.xml?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/mbeans-descriptors.xml (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/mbeans-descriptors.xml Mon Nov 28 23:20:46 2011
@@ -77,6 +77,10 @@
           description="The number of seconds Tomcat will wait for a subsequent request before closing the connection"
                  type="int"/>
 
+    <attribute   name="localPort"
+          description="The port number on which this connector is listening to requests. If the special value for port of zero is used then this method will report the actual port bound."
+                type="int"/>
+
     <attribute   name="maxKeepAliveRequests"
           description="Maximum number of Keep-Alive requests to honor per connection"
                  type="int"/>
@@ -108,7 +112,7 @@
                  type="int"/>
 
     <attribute   name="port"
-          description="The port number on which we listen for requests"
+          description="The port number on which this connector is configured to listen for requests. The special value of 0 means select a random free port when the socket is bound."
                 type="int"/>
 
     <!-- Common -->

Modified: tomcat/tc7.0.x/trunk/java/org/apache/coyote/AbstractProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/AbstractProtocol.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/coyote/AbstractProtocol.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/AbstractProtocol.java Mon Nov 28 23:20:46 2011
@@ -48,6 +48,13 @@ public abstract class AbstractProtocol i
 
 
     /**
+     * Counter used to generate unique JMX names for connectors using automatic
+     * port binding.
+     */
+    private static final AtomicInteger nameCounter = new AtomicInteger(0);
+
+
+    /**
      * Name of MBean for the Global Request Processor.
      */
     protected ObjectName rgOname = null;
@@ -60,6 +67,14 @@ public abstract class AbstractProtocol i
 
     
     /**
+     * Unique ID for this connector. Only used if the connector is configured
+     * to use a random port as the port will change if stop(), start() is
+     * called.
+     */
+    private int nameIndex = 0;
+
+
+    /**
      * Endpoint that provides low-level network I/O - must be matched to the
      * ProtocolHandler implementation (ProtocolHandler using BIO, requires BIO
      * Endpoint etc.).
@@ -194,6 +209,8 @@ public abstract class AbstractProtocol i
     }
 
 
+    public int getLocalPort() { return endpoint.getLocalPort(); }
+
     /*
      * When Tomcat expects data from the client, this is the time Tomcat will
      * wait for that data to arrive before closing the connection.
@@ -220,6 +237,15 @@ public abstract class AbstractProtocol i
 
     // ---------------------------------------------------------- Public methods
 
+    public synchronized int getNameIndex() {
+        if (nameIndex == 0) {
+            nameIndex = nameCounter.incrementAndGet();
+        }
+
+        return nameIndex;
+    }
+
+
     /**
      * The name will be prefix-address-port if address is non-null and
      * prefix-port if the address is null. The name will be appropriately quoted
@@ -232,7 +258,13 @@ public abstract class AbstractProtocol i
             name.append(getAddress());
             name.append('-');
         }
-        name.append(endpoint.getPort());
+        int port = getLocalPort();
+        if (port > 0) {
+            name.append(port);
+        } else {
+            name.append("auto-");
+            name.append(getNameIndex());
+        }
         return ObjectName.quote(name.toString());
     }
 
@@ -313,7 +345,13 @@ public abstract class AbstractProtocol i
 
         StringBuilder name = new StringBuilder(getDomain());
         name.append(":type=ProtocolHandler,port=");
-        name.append(getPort());
+        int port = getPort();
+        if (port > 0) {
+            name.append(getPort());
+        } else {
+            name.append("auto-");
+            name.append(getNameIndex());
+        }
         InetAddress address = getAddress();
         if (address != null) {
             name.append(",address=");
@@ -322,6 +360,7 @@ public abstract class AbstractProtocol i
         return new ObjectName(name.toString());
     }
 
+
     // ------------------------------------------------------- Lifecycle methods
 
     /*

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/AbstractEndpoint.java Mon Nov 28 23:20:46 2011
@@ -186,6 +186,7 @@ public abstract class AbstractEndpoint {
     public int getPort() { return port; }
     public void setPort(int port ) { this.port=port; }
 
+    public abstract int getLocalPort();
 
     /**
      * Address for the server socket.

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Mon Nov 28 23:20:46 2011
@@ -37,6 +37,7 @@ import org.apache.tomcat.jni.Pool;
 import org.apache.tomcat.jni.SSL;
 import org.apache.tomcat.jni.SSLContext;
 import org.apache.tomcat.jni.SSLSocket;
+import org.apache.tomcat.jni.Sockaddr;
 import org.apache.tomcat.jni.Socket;
 import org.apache.tomcat.jni.Status;
 import org.apache.tomcat.util.ExceptionUtils;
@@ -316,8 +317,29 @@ public class AprEndpoint extends Abstrac
     public void setSSLInsecureRenegotiation(boolean SSLInsecureRenegotiation) { this.SSLInsecureRenegotiation = SSLInsecureRenegotiation; }
     public boolean getSSLInsecureRenegotiation() { return SSLInsecureRenegotiation; }
 
-    // --------------------------------------------------------- Public Methods
 
+    /**
+     * Port in use.
+     */
+    @Override
+    public int getLocalPort() {
+        long s = serverSock;
+        if (s == 0) {
+            return -1;
+        } else {
+            long sa;
+            try {
+                sa = Address.get(Socket.APR_LOCAL, s);
+                Sockaddr addr = Address.getInfo(sa);
+                return addr.port;
+            } catch (Exception e) {
+                return -1;
+            }
+        }
+    }
+
+
+    // --------------------------------------------------------- Public Methods
 
     /**
      * Number of keepalive sockets.

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/JIoEndpoint.java Mon Nov 28 23:20:46 2011
@@ -89,6 +89,18 @@ public class JIoEndpoint extends Abstrac
     public void setServerSocketFactory(ServerSocketFactory factory) { this.serverSocketFactory = factory; }
     public ServerSocketFactory getServerSocketFactory() { return serverSocketFactory; }
 
+    /**
+     * Port in use.
+     */
+    @Override
+    public int getLocalPort() {
+        ServerSocket s = serverSocket;
+        if (s == null) {
+            return -1;
+        } else {
+            return s.getLocalPort();
+        }
+    }
 
     /*
      * Optional feature support.

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Mon Nov 28 23:20:46 2011
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.SocketTimeoutException;
 import java.nio.ByteBuffer;
@@ -387,6 +388,26 @@ public class NioEndpoint extends Abstrac
     public SSLContext getSSLContext() { return sslContext;}
     public void setSSLContext(SSLContext c) { sslContext = c;}
 
+
+    /**
+     * Port in use.
+     */
+    @Override
+    public int getLocalPort() {
+        ServerSocketChannel ssc = serverSock;
+        if (ssc == null) {
+            return -1;
+        } else {
+            ServerSocket s = ssc.socket();
+            if (s == null) {
+                return -1;
+            } else {
+                return s.getLocalPort();
+            }
+        }
+    }
+
+
     // --------------------------------------------------------- OOM Parachute Methods
 
     protected void checkParachute() {

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/authenticator/TestFormAuthenticator.java Mon Nov 28 23:20:46 2011
@@ -115,9 +115,10 @@ public class TestFormAuthenticator exten
             realm.addUserRole("tomcat", "tomcat");
             ctx.setRealm(realm);
 
-            setPort(getPort());
-
             tomcat.start();
+
+            // Port only known after Tomcat starts
+            setPort(getPort());
         }
 
         private void doResourceRequest(String method) throws Exception {

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/connector/TestConnector.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/connector/TestConnector.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/connector/TestConnector.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/connector/TestConnector.java Mon Nov 28 23:20:46 2011
@@ -19,6 +19,7 @@ package org.apache.catalina.connector;
 import java.net.SocketTimeoutException;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 
@@ -69,4 +70,26 @@ public class TestConnector extends Tomca
         }
         assertEquals(503, rc);
     }
+
+
+    @Test
+    public void testPort() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        Connector connector1 = tomcat.getConnector();
+        connector1.setPort(0);
+
+        Connector connector2 = new Connector();
+        connector2.setPort(0);
+
+        tomcat.getService().addConnector(connector2);
+
+        tomcat.start();
+
+        int localPort1 = connector1.getLocalPort();
+        int localPort2 = connector2.getLocalPort();
+
+        assertTrue(localPort1 > 0);
+        assertTrue(localPort2 > 0);
+    }
 }

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/connector/TestRequest.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/connector/TestRequest.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/connector/TestRequest.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/connector/TestRequest.java Mon Nov 28 23:20:46 2011
@@ -62,7 +62,6 @@ public class TestRequest extends TomcatB
     @Test
     public void testBug37794() {
         Bug37794Client client = new Bug37794Client(true);
-        client.setPort(getPort());
 
         // Edge cases around zero
         client.doRequest(-1, false); // Unlimited
@@ -111,7 +110,6 @@ public class TestRequest extends TomcatB
     @Test
     public void testBug37794withoutFilter() {
         Bug37794Client client = new Bug37794Client(false);
-        client.setPort(getPort());
 
         // Edge cases around actual content length
         client.reset();
@@ -180,6 +178,8 @@ public class TestRequest extends TomcatB
 
             tomcat.start();
 
+            setPort(tomcat.getConnector().getLocalPort());
+
             init = true;
         }
 
@@ -391,7 +391,6 @@ public class TestRequest extends TomcatB
     @Test
     public void testBug48692() {
         Bug48692Client client = new Bug48692Client();
-        client.setPort(getPort());
 
         // Make sure GET works properly
         client.doRequest("GET", "foo=bar", null, null, false);
@@ -518,6 +517,8 @@ public class TestRequest extends TomcatB
             root.addServletMapping("/echo", "EchoParameters");
             tomcat.start();
 
+            setPort(tomcat.getConnector().getLocalPort());
+
             init = true;
         }
 

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestStandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestStandardContext.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestStandardContext.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestStandardContext.java Mon Nov 28 23:20:46 2011
@@ -97,11 +97,12 @@ public class TestStandardContext extends
         Tomcat.addServlet(root, "Bug46243", new HelloWorldServlet());
         root.addServletMapping("/", "Bug46243");
 
+
         tomcat.start();
 
         // Configure the client
-        Bug46243Client client = new Bug46243Client();
-        client.setPort(getPort());
+        Bug46243Client client =
+                new Bug46243Client(tomcat.getConnector().getLocalPort());
         client.setRequest(new String[] { REQUEST });
 
         client.connect();
@@ -110,6 +111,11 @@ public class TestStandardContext extends
     }
 
     private static final class Bug46243Client extends SimpleHttpClient {
+
+        public Bug46243Client(int port) {
+            setPort(port);
+        }
+
         @Override
         public boolean isResponseBodyOK() {
             // Don't care about the body in this test
@@ -442,7 +448,6 @@ public class TestStandardContext extends
     @Test
     public void testBug49711() {
         Bug49711Client client = new Bug49711Client();
-        client.setPort(getPort());
 
         // Make sure non-multipart works properly
         client.doRequest("/regular", false, false);
@@ -531,6 +536,8 @@ public class TestStandardContext extends
             context.addServletMapping("/multipart", "multipart");
             tomcat.start();
 
+            setPort(tomcat.getConnector().getLocalPort());
+
             init = true;
         }
 

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestSwallowAbortedUploads.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestSwallowAbortedUploads.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestSwallowAbortedUploads.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestSwallowAbortedUploads.java Mon Nov 28 23:20:46 2011
@@ -51,7 +51,6 @@ public class TestSwallowAbortedUploads e
      */
     public Exception doAbortedUploadTest(AbortedUploadClient client, boolean limited,
                             boolean swallow) {
-        client.setPort(getPort());
         Exception ex = client.doRequest(limited, swallow);
         if (log.isDebugEnabled()) {
             log.debug("Response line: " + client.getResponseLine());
@@ -70,7 +69,6 @@ public class TestSwallowAbortedUploads e
      */
     public Exception doAbortedPOSTTest(AbortedPOSTClient client, int status,
                             boolean swallow) {
-        client.setPort(getPort());
         Exception ex = client.doRequest(status, swallow);
         if (log.isDebugEnabled()) {
             log.debug("Response line: " + client.getResponseLine());
@@ -254,6 +252,7 @@ public class TestSwallowAbortedUploads e
             context.setSwallowAbortedUploads(swallow);
 
             tomcat.start();
+            setPort(tomcat.getConnector().getLocalPort());
 
             init = true;
         }
@@ -367,6 +366,8 @@ public class TestSwallowAbortedUploads e
 
             tomcat.start();
 
+            setPort(tomcat.getConnector().getLocalPort());
+
             init = true;
         }
 

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/filters/TestExpiresFilter.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/filters/TestExpiresFilter.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/filters/TestExpiresFilter.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/filters/TestExpiresFilter.java Mon Nov 28 23:20:46 2011
@@ -432,7 +432,7 @@ public class TestExpiresFilter extends T
 
             // TEST
             HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(
-                    "http://localhost:" + tomcat.getConnector().getPort() +
+                    "http://localhost:" + tomcat.getConnector().getLocalPort() +
                             "/test").openConnection();
 
             // VALIDATE

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/filters/TestRemoteIpFilter.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/filters/TestRemoteIpFilter.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/filters/TestRemoteIpFilter.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/filters/TestRemoteIpFilter.java Mon Nov 28 23:20:46 2011
@@ -537,8 +537,9 @@ public class TestRemoteIpFilter extends 
         getTomcatInstance().start();
 
         // TEST
-        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://localhost:" + tomcat.getConnector().getPort() + "/test")
-                .openConnection();
+        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(
+                "http://localhost:" + tomcat.getConnector().getLocalPort() +
+                "/test").openConnection();
         String expectedRemoteAddr = "my-remote-addr";
         httpURLConnection.addRequestProperty("x-forwarded-for", expectedRemoteAddr);
         httpURLConnection.addRequestProperty("x-forwarded-proto", "https");

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/mbeans/TestRegistration.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/mbeans/TestRegistration.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/mbeans/TestRegistration.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/mbeans/TestRegistration.java Mon Nov 28 23:20:46 2011
@@ -147,7 +147,7 @@ public class TestRegistration extends To
         ArrayList<String> expected = new ArrayList<String>(Arrays.asList(basicMBeanNames()));
         expected.addAll(Arrays.asList(hostMBeanNames("localhost")));
         expected.addAll(Arrays.asList(contextMBeanNames("localhost", contextName)));
-        expected.addAll(Arrays.asList(connectorMBeanNames(Integer.toString(getPort()), protocol)));
+        expected.addAll(Arrays.asList(connectorMBeanNames("auto-1", protocol)));
         expected.addAll(Arrays.asList(optionalMBeanNames("localhost")));
 
         // Did we find all expected MBeans?

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/servlets/TestDefaultServlet.java Mon Nov 28 23:20:46 2011
@@ -198,8 +198,8 @@ public class TestDefaultServlet extends 
         tomcat.addWebapp(null, contextPath, appDir.getAbsolutePath());
         tomcat.start();
 
-        TestCustomErrorClient client = new TestCustomErrorClient();
-        client.setPort(getPort());
+        TestCustomErrorClient client =
+                new TestCustomErrorClient(tomcat.getConnector().getLocalPort());
 
         client.reset();
         client.setRequest(new String[] {
@@ -276,8 +276,8 @@ public class TestDefaultServlet extends 
         tomcat.addWebapp(null, contextPath, appDir.getAbsolutePath());
         tomcat.start();
 
-        TestCustomErrorClient client = new TestCustomErrorClient();
-        client.setPort(getPort());
+        TestCustomErrorClient client =
+                new TestCustomErrorClient(tomcat.getConnector().getLocalPort());
 
         client.reset();
         client.setRequest(new String[] {
@@ -294,6 +294,11 @@ public class TestDefaultServlet extends 
     }
 
     private static class TestCustomErrorClient extends SimpleHttpClient {
+
+        public TestCustomErrorClient(int port) {
+            setPort(port);
+        }
+
         @Override
         public boolean isResponseBodyOK() {
             return true;

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/SimpleHttpClient.java Mon Nov 28 23:20:46 2011
@@ -70,7 +70,7 @@ public abstract class SimpleHttpClient {
     private String responseBody;
     private boolean useContentLength;
 
-    public void setPort(int thePort) {
+    protected void setPort(int thePort) {
         port = thePort;
     }
 

Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TomcatBaseTest.java Mon Nov 28 23:20:46 2011
@@ -56,7 +56,6 @@ import org.apache.tomcat.util.buf.ByteCh
 public abstract class TomcatBaseTest extends LoggingBaseTest {
     private Tomcat tomcat;
     private boolean accessLogEnabled = false;
-    private static int port = 8000;
 
     public static final String TEMP_DIR = System.getProperty("java.io.tmpdir");
 
@@ -71,15 +70,7 @@ public abstract class TomcatBaseTest ext
      * Sub-classes need to know port so they can connect
      */
     public int getPort() {
-        return port;
-    }
-
-    /**
-     * Sub-classes may want to add connectors on a new port
-     */
-    public int getNextPort() {
-        port++;
-        return getPort();
+        return tomcat.getConnector().getLocalPort();
     }
 
     /**
@@ -106,9 +97,8 @@ public abstract class TomcatBaseTest ext
 
         String protocol = getProtocol();
         Connector connector = new Connector(protocol);
-        // If each test is running on same port - they
-        // may interfere with each other
-        connector.setPort(getNextPort());
+        // Use random free port
+        connector.setPort(0);
         // Mainly set to reduce timeouts during async tests
         connector.setAttribute("connectionTimeout", "3000");
         tomcat.getService().addConnector(connector);

Modified: tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java Mon Nov 28 23:20:46 2011
@@ -53,8 +53,7 @@ public class TestAbstractHttp11Processor
             SimpleHttpClient.CRLF +
             "test=data";
 
-        Client client = new Client();
-        client.setPort(getPort());
+        Client client = new Client(tomcat.getConnector().getLocalPort());
         client.setRequest(new String[] {request});
 
         client.connect();
@@ -82,8 +81,7 @@ public class TestAbstractHttp11Processor
             SimpleHttpClient.CRLF +
             "test=data";
 
-        Client client = new Client();
-        client.setPort(getPort());
+        Client client = new Client(tomcat.getConnector().getLocalPort());
         client.setRequest(new String[] {request});
 
         client.connect();
@@ -113,8 +111,7 @@ public class TestAbstractHttp11Processor
             SimpleHttpClient.CRLF +
             "test=data";
 
-        Client client = new Client();
-        client.setPort(getPort());
+        Client client = new Client(tomcat.getConnector().getLocalPort());
         client.setRequest(new String[] {request});
 
         client.connect();
@@ -144,8 +141,7 @@ public class TestAbstractHttp11Processor
             SimpleHttpClient.CRLF +
             "test=data";
 
-        Client client = new Client();
-        client.setPort(getPort());
+        Client client = new Client(tomcat.getConnector().getLocalPort());
         client.setRequest(new String[] {request});
 
         client.connect();
@@ -174,8 +170,7 @@ public class TestAbstractHttp11Processor
             SimpleHttpClient.CRLF +
             "test=data";
 
-        Client client = new Client();
-        client.setPort(getPort());
+        Client client = new Client(tomcat.getConnector().getLocalPort());
         client.setRequest(new String[] {request});
 
         client.connect();
@@ -204,8 +199,7 @@ public class TestAbstractHttp11Processor
             "Host: any" + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF;
 
-        final Client client = new Client();
-        client.setPort(getPort());
+        final Client client = new Client(tomcat.getConnector().getLocalPort());
         client.setRequest(new String[] {requestPart1, requestPart2});
         client.setRequestPause(1000);
         client.setUseContentLength(true);
@@ -246,6 +240,11 @@ public class TestAbstractHttp11Processor
     }
 
     private static final class Client extends SimpleHttpClient {
+
+        public Client(int port) {
+            setPort(port);
+        }
+
         @Override
         public boolean isResponseBodyOK() {
             return getResponseBody().contains("test - data");

Modified: tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/TestInternalInputBuffer.java Mon Nov 28 23:20:46 2011
@@ -45,7 +45,6 @@ public class TestInternalInputBuffer ext
     public void testBug48839() {
 
         Bug48839Client client = new Bug48839Client();
-        client.setPort(getPort());
 
         client.doRequest();
         assertTrue(client.isResponse200());
@@ -68,6 +67,7 @@ public class TestInternalInputBuffer ext
 
             try {
                 tomcat.start();
+                setPort(tomcat.getConnector().getLocalPort());
 
                 // Open connection
                 connect();
@@ -131,7 +131,6 @@ public class TestInternalInputBuffer ext
     public void testBug51557NoColon() {
 
         Bug51557Client client = new Bug51557Client("X-Bug51557NoColon");
-        client.setPort(getPort());
 
         client.doRequest();
         assertTrue(client.isResponse200());
@@ -170,7 +169,6 @@ public class TestInternalInputBuffer ext
 
         Bug51557Client client = new Bug51557Client("X-Bug=51557NoColon",
                 "foo" + SimpleHttpClient.CRLF + " bar");
-        client.setPort(getPort());
 
         client.doRequest();
         assertTrue(client.isResponse200());
@@ -184,7 +182,6 @@ public class TestInternalInputBuffer ext
 
         Bug51557Client client = new Bug51557Client("=X-Bug51557",
                 "invalid");
-        client.setPort(getPort());
 
         client.doRequest();
         assertTrue(client.isResponse200());
@@ -198,7 +195,6 @@ public class TestInternalInputBuffer ext
 
         Bug51557Client client = new Bug51557Client("X-Bug51557=",
                 "invalid");
-        client.setPort(getPort());
 
         client.doRequest();
         assertTrue(client.isResponse200());
@@ -211,7 +207,6 @@ public class TestInternalInputBuffer ext
         Bug51557Client client =
             new Bug51557Client("X-Bug" + s + "51557", "invalid");
 
-        client.setPort(getPort());
         client.doRequest();
         assertTrue(client.isResponse200());
         assertEquals("abcd", client.getResponseBody());
@@ -247,6 +242,7 @@ public class TestInternalInputBuffer ext
 
             try {
                 tomcat.start();
+                setPort(tomcat.getConnector().getLocalPort());
 
                 // Open connection
                 connect();

Modified: tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java Mon Nov 28 23:20:46 2011
@@ -68,8 +68,8 @@ public class TestChunkedInputFilter exte
             "x-trailer: Test", "TestTest0123456789abcdefghijABCDEFGHIJopqrstuvwxyz" + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF };
 
-        TrailerClient client = new TrailerClient();
-        client.setPort(getPort());
+        TrailerClient client =
+                new TrailerClient(tomcat.getConnector().getLocalPort());
         client.setRequest(request);
 
         client.connect();
@@ -109,8 +109,8 @@ public class TestChunkedInputFilter exte
             "x-trailer: Test" + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF };
 
-        TrailerClient client = new TrailerClient();
-        client.setPort(getPort());
+        TrailerClient client =
+                new TrailerClient(tomcat.getConnector().getLocalPort());
         client.setRequest(request);
 
         client.connect();
@@ -149,8 +149,8 @@ public class TestChunkedInputFilter exte
             "0" + SimpleHttpClient.CRLF +
             SimpleHttpClient.CRLF;
 
-        TrailerClient client = new TrailerClient();
-        client.setPort(getPort());
+        TrailerClient client =
+                new TrailerClient(tomcat.getConnector().getLocalPort());
         client.setRequest(new String[] {request});
 
         client.connect();
@@ -193,6 +193,10 @@ public class TestChunkedInputFilter exte
 
     private static class TrailerClient extends SimpleHttpClient {
 
+        public TrailerClient(int port) {
+            setPort(port);
+        }
+
         @Override
         public boolean isResponseBodyOK() {
             return getResponseBody().contains("TestTestTest");

Modified: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowEquals.java Mon Nov 28 23:20:46 2011
@@ -60,7 +60,7 @@ public class TestCookiesAllowEquals exte
 
             tomcat.start();
             // Open connection
-            setPort(tomcat.getConnector().getPort());
+            setPort(tomcat.getConnector().getLocalPort());
             connect();
 
             String[] request = new String[1];

Modified: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowHttpSeps.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowHttpSeps.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowHttpSeps.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowHttpSeps.java Mon Nov 28 23:20:46 2011
@@ -58,7 +58,7 @@ public class TestCookiesAllowHttpSeps ex
 
             tomcat.start();
             // Open connection
-            setPort(tomcat.getConnector().getPort());
+            setPort(tomcat.getConnector().getLocalPort());
             connect();
 
             String[] request = new String[1];

Modified: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowNameOnly.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowNameOnly.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowNameOnly.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesAllowNameOnly.java Mon Nov 28 23:20:46 2011
@@ -59,7 +59,7 @@ public class TestCookiesAllowNameOnly ex
 
             tomcat.start();
             // Open connection
-            setPort(tomcat.getConnector().getPort());
+            setPort(tomcat.getConnector().getLocalPort());
             connect();
 
             String[] request = new String[1];

Modified: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesDisallowEquals.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesDisallowEquals.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesDisallowEquals.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/TestCookiesDisallowEquals.java Mon Nov 28 23:20:46 2011
@@ -55,7 +55,7 @@ public class TestCookiesDisallowEquals e
 
             tomcat.start();
             // Open connection
-            setPort(tomcat.getConnector().getPort());
+            setPort(tomcat.getConnector().getLocalPort());
             connect();
 
             String[] request = new String[1];

Modified: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/net/TestXxxEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/net/TestXxxEndpoint.java?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/net/TestXxxEndpoint.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/net/TestXxxEndpoint.java Mon Nov 28 23:20:46 2011
@@ -165,9 +165,9 @@ public class TestXxxEndpoint extends Tom
         File appDir = new File(getBuildDirectory(), "webapps/examples");
         tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
 
-        int port = getPort();
 
         tomcat.start();
+        int port = getPort();
 
         tomcat.getConnector().stop();
         Exception e = null;

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Mon Nov 28 23:20:46 2011
@@ -68,6 +68,15 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name = "Coyote">
+    <changelog>
+      <add>
+        <bug>52028</bug>: Add support for automatic binding to a free port by a
+        connector if the special value of zero is used for the port. This is
+        mainly useful in embedded and testing scenarios. (markt)
+      </add>
+    </changelog>
+  </subsection>
   <subsection name="Web applications">
     <changelog>
       <update>

Modified: tomcat/tc7.0.x/trunk/webapps/docs/config/ajp.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/config/ajp.xml?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/config/ajp.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/config/ajp.xml Mon Nov 28 23:20:46 2011
@@ -143,7 +143,10 @@
       <p>The TCP port number on which this <strong>Connector</strong>
       will create a server socket and await incoming connections.  Your
       operating system will allow only one server application to listen
-      to a particular port number on a particular IP address.</p>
+      to a particular port number on a particular IP address. If the special
+      value of 0 (zero) is used, then Tomcat will select a free port at random
+      to use for this connector. This is typically only useful in embedded and
+      testing applications.</p>
     </attribute>
 
     <attribute name="protocol" required="false">

Modified: tomcat/tc7.0.x/trunk/webapps/docs/config/http.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/config/http.xml?rev=1207695&r1=1207694&r2=1207695&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/config/http.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/config/http.xml Mon Nov 28 23:20:46 2011
@@ -141,7 +141,10 @@
       <p>The TCP port number on which this <strong>Connector</strong>
       will create a server socket and await incoming connections.  Your
       operating system will allow only one server application to listen
-      to a particular port number on a particular IP address.</p>
+      to a particular port number on a particular IP address. If the special
+      value of 0 (zero) is used, then Tomcat will select a free port at random
+      to use for this connector. This is typically only useful in embedded and
+      testing applications.</p>
     </attribute>
 
     <attribute name="protocol" required="false">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message