This is the first set of modifications I made to the Catalina code to allow
port < 1024 binding under Unix. Basically, I added an "initialize()" method
to Server, Service and Connector, and that gets called appropriately before
"start()". Now, the only thing left to do is to move the ServerSocket
creation within connectors in "initialize()", and launch Catalina with a
wrapper around the Service code I committed last week.

Basically, during "load()" in service, we build the whole components tree
and call "initialize()" on the Server. Then during "start()" and "stop()" we
call the same methods in Server, and (in theory) the trick should be done.

I'd need to modify Remy's BootstrapService and CatalinaService to perform a
two-stage initialization process (and I don't know what JavaService, the one
he's using under Windows does), but, more or less, that should be it...

This patch actually starts fixing things, but doesn't break the build
neither compromises functionality (checked it already), but I would like
someone (Craig/Remy/Amy/Glenn...) to review it and, if ok, apply it...

Cheers...

    Pier (back from the cops)


Index: Connector.java
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Connector.java,v
retrieving revision 1.5
diff -c -3 -r1.5 Connector.java
*** Connector.java      2001/05/09 23:42:07     1.5
--- Connector.java      2001/07/20 17:38:25
***************
*** 240,244 ****
--- 240,252 ----
       */
      public Response createResponse();
  
+     /**
+      * Invoke a pre-startup initialization. This is used to allow connectors
+      * to bind to restricted ports under Unix operating environments.
+      *
+      * @exception LifecycleException If this server was already initialized.
+      */
+     public void initialize()
+     throws LifecycleException;
  
  }
Index: Server.java
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Server.java,v
retrieving revision 1.2
diff -c -3 -r1.2 Server.java
*** Server.java 2000/09/30 19:15:43     1.2
--- Server.java 2001/07/20 17:38:25
***************
*** 163,167 ****
       */
      public void removeService(Service service);
  
! 
  }
--- 163,174 ----
       */
      public void removeService(Service service);
  
!     /**
!      * Invoke a pre-startup initialization. This is used to allow connectors
!      * to bind to restricted ports under Unix operating environments.
!      *
!      * @exception LifecycleException If this server was already initialized.
!      */
!     public void initialize()
!     throws LifecycleException;
  }
Index: Service.java
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Service.java,v
retrieving revision 1.2
diff -c -3 -r1.2 Service.java
*** Service.java        2000/12/14 02:56:13     1.2
--- Service.java        2001/07/20 17:38:25
***************
*** 150,154 ****
--- 150,162 ----
       */
      public void removeConnector(Connector connector);
  
+     /**
+      * Invoke a pre-startup initialization. This is used to allow connectors
+      * to bind to restricted ports under Unix operating environments.
+      *
+      * @exception LifecycleException If this server was already initialized.
+      */
+     public void initialize()
+     throws LifecycleException;
  
  }
Index: connector/http/HttpConnector.java
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpConnector.java,v
retrieving revision 1.18
diff -c -3 -r1.18 HttpConnector.java
*** connector/http/HttpConnector.java   2001/07/10 07:36:42     1.18
--- connector/http/HttpConnector.java   2001/07/20 17:38:26
***************
*** 258,263 ****
--- 258,269 ----
  
  
      /**
+      * Has this component been initialized yet?
+      */
+     private boolean initialized = false;
+ 
+ 
+     /**
       * Has this component been started yet?
       */
      private boolean started = false;
***************
*** 1055,1060 ****
--- 1061,1079 ----
  
        lifecycle.removeLifecycleListener(listener);
  
+     }
+ 
+ 
+     /**
+      * Initialize this connector (create ServerSocket here!)
+      */
+     public void initialize()
+     throws LifecycleException {
+       if (initialized)
+           throw new LifecycleException (
+               sm.getString("httpConnector.alreadyInitialized"));
+       this.initialized=true;
+       System.err.println("HTTP Connector initialized");
      }
  
  
Index: connector/http/LocalStrings.properties
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/LocalStrings.properties,v
retrieving revision 1.3
diff -c -3 -r1.3 LocalStrings.properties
*** connector/http/LocalStrings.properties      2000/12/31 16:35:16     1.3
--- connector/http/LocalStrings.properties      2001/07/20 17:38:26
***************
*** 5,10 ****
--- 5,11 ----
  # package org.apache.catalina.connector.http
  
  
+ httpConnector.alreadyInitialized=HTTP connector has already been initialized
  httpConnector.alreadyStarted=HTTP connector has already been started
  httpConnector.allAddresses=Opening server socket on all host IP addresses
  httpConnector.failedSocketFactoryLoading=Failed to load socket factory
Index: connector/http10/HttpConnector.java
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http10/HttpConnector.java,v
retrieving revision 1.7
diff -c -3 -r1.7 HttpConnector.java
*** connector/http10/HttpConnector.java 2001/07/10 07:37:05     1.7
--- connector/http10/HttpConnector.java 2001/07/20 17:38:27
***************
*** 257,262 ****
--- 257,268 ----
  
  
      /**
+      * Has this component been initialized yet?
+      */
+     private boolean initialized = false;
+ 
+ 
+     /**
       * Has this component been started yet?
       */
      private boolean started = false;
***************
*** 961,966 ****
--- 967,983 ----
  
      }
  
+ 
+     /**
+      * Initialize this connector (create ServerSocket here!)
+      */
+     public void initialize()
+     throws LifecycleException {
+         if (initialized)
+             throw new LifecycleException (
+                 sm.getString("httpConnector.alreadyInitialized"));
+         this.initialized=true;
+     }
  
      /**
       * Begin processing requests via this Connector.
Index: connector/http10/LocalStrings.properties
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http10/LocalStrings.properties,v
retrieving revision 1.1
diff -c -3 -r1.1 LocalStrings.properties
*** connector/http10/LocalStrings.properties    2001/01/23 03:55:54     1.1
--- connector/http10/LocalStrings.properties    2001/07/20 17:38:28
***************
*** 1,3 ****
--- 1,4 ----
+ httpConnector.alreadyInitialized=HTTP connector has already been initialized
  httpConnector.alreadyStarted=HTTP connector has already been started
  httpConnector.allAddresses=Opening server socket on all host IP addresses
  httpConnector.anAddress=Opening server socket on host IP address {0}
Index: connector/warp/WarpConnector.java
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/warp/WarpConnector.java,v
retrieving revision 1.12
diff -c -3 -r1.12 WarpConnector.java
*** connector/warp/WarpConnector.java   2001/07/20 00:01:00     1.12
--- connector/warp/WarpConnector.java   2001/07/20 17:38:28
***************
*** 130,135 ****
--- 130,137 ----
  
      /** The lifecycle event support for this component. */
      private LifecycleSupport lifecycle=new LifecycleSupport(this);
+     /** The "initialized" flag. */
+     private boolean initialized=false;
      /** The "started" flag. */
      private boolean started=false;
  
***************
*** 428,433 ****
--- 430,445 ----
       */
      public void removeLifecycleListener(LifecycleListener listener) {
          lifecycle.removeLifecycleListener(listener);
+     }
+ 
+     /**
+      * Initialize this connector (create ServerSocket here!)
+      */
+     public void initialize()
+     throws LifecycleException {
+         if (initialized)
+             throw new LifecycleException("Already initialized");
+         this.initialized=true;
      }
  
      /**
Index: core/LocalStrings.properties
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings.properties,v
retrieving revision 1.33
diff -c -3 -r1.33 LocalStrings.properties
*** core/LocalStrings.properties        2001/05/11 23:20:09     1.33
--- core/LocalStrings.properties        2001/07/20 17:38:29
***************
*** 109,117 ****
--- 109,119 ----
  standardPipeline.notStarted=Pipeline has not been started
  standardPipeline.noValve=No more Valves in the Pipeline processing this request
  standardServer.addContainer.ise=No connectors available to associate this container 
with
+ standardServer.initialize.initialized=This server has already been initialized
  standardServer.start.connectors=At least one connector is not associated with any 
container
  standardServer.start.started=This server has already been started
  standardServer.stop.notStarted=This server has not yet been started
+ standardService.initialize.initialized=This service has already been initialized
  standardService.start.name=Starting service {0}
  standardService.start.started=This service has already been started
  standardService.stop.name=Stopping service {0}
Index: core/StandardServer.java
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardServer.java,v
retrieving revision 1.5
diff -c -3 -r1.5 StandardServer.java
*** core/StandardServer.java    2001/03/31 15:26:21     1.5
--- core/StandardServer.java    2001/07/20 17:38:29
***************
*** 141,146 ****
--- 141,152 ----
      private boolean started = false;
  
  
+     /**
+      * Has this component been initialized?
+      */
+     private boolean initialized = false;
+ 
+ 
      // ------------------------------------------------------------- Properties
  
  
***************
*** 215,220 ****
--- 221,235 ----
              System.arraycopy(services, 0, results, 0, services.length);
              results[services.length] = service;
              services = results;
+ 
+           if (initialized) {
+               try {
+                   service.initialize();
+               } catch (LifecycleException e) {
+                   e.printStackTrace(System.err);
+               }
+           }
+ 
              if (started && (service instanceof Lifecycle)) {
                  try {
                      ((Lifecycle) service).start();
***************
*** 489,493 ****
--- 504,524 ----
  
      }
  
+     /**
+      * Invoke a pre-startup initialization. This is used to allow connectors
+      * to bind to restricted ports under Unix operating environments.
+      */
+     public void initialize()
+     throws LifecycleException {
+         if (initialized)
+             throw new LifecycleException (
+               sm.getString("standardServer.initialize.initialized"));
+       initialized = true;
+ 
+       // Initialize our defined Services
+       for (int i = 0; i < services.length; i++) {
+           services[i].initialize();
+       }
+     }
  
  }
Index: core/StandardService.java
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardService.java,v
retrieving revision 1.2
diff -c -3 -r1.2 StandardService.java
*** core/StandardService.java   2000/12/14 02:56:14     1.2
--- core/StandardService.java   2001/07/20 17:38:30
***************
*** 137,142 ****
--- 137,148 ----
      private boolean started = false;
  
  
+     /**
+      * Has this component been initialized?
+      */
+     private boolean initialized = false;
+ 
+ 
      // ------------------------------------------------------------- Properties
  
  
***************
*** 236,241 ****
--- 242,256 ----
              System.arraycopy(connectors, 0, results, 0, connectors.length);
              results[connectors.length] = connector;
              connectors = results;
+ 
+           if (initialized) {
+               try {
+                   connector.initialize();
+               } catch (LifecycleException e) {
+                   e.printStackTrace(System.err);
+               }
+           }
+ 
              if (started && (connector instanceof Lifecycle)) {
                  try {
                      ((Lifecycle) connector).start();
***************
*** 402,406 ****
--- 417,439 ----
  
      }
  
+     /**
+      * Invoke a pre-startup initialization. This is used to allow connectors
+      * to bind to restricted ports under Unix operating environments.
+      */
+     public void initialize()
+     throws LifecycleException {
+         if (initialized)
+             throw new LifecycleException (
+                 sm.getString("standardService.initialize.initialized"));
+         initialized = true;
+ 
+         // Initialize our defined Connectors
+         synchronized (connectors) {
+               for (int i = 0; i < connectors.length; i++) {
+                   connectors[i].initialize();
+               }
+         }
+     }
  
  }
Index: startup/Catalina.java
===================================================================
RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Catalina.java,v
retrieving revision 1.27
diff -c -3 -r1.27 Catalina.java
*** startup/Catalina.java       2001/07/17 16:32:38     1.27
--- startup/Catalina.java       2001/07/20 17:38:31
***************
*** 734,739 ****
--- 734,740 ----
        // Start the new server
        if (server instanceof Lifecycle) {
            try {
+               server.initialize();
                ((Lifecycle) server).start();
            } catch (LifecycleException e) {
                System.out.println("Catalina.start: " + e);

Reply via email to