r9430 - helma/helma/trunk/src/helma/main

[email protected]
Newsgroups gmane.comp.java.helma.cvs
Message-ID <[email protected]>
Author: hannes
Date: 2008-12-13 03:36:39 +0100 (Sat, 13 Dec 2008)
New Revision: 9430

Modified:
   helma/helma/trunk/src/helma/main/JettyServer.java
   helma/helma/trunk/src/helma/main/Server.java
Log:
Create jetty server in init() so we can open privileged ports when running with jsvc.

Details at http://dev.helma.org/trac/helma/changeset/9430

Modified: helma/helma/trunk/src/helma/main/JettyServer.java
===================================================================
--- helma/helma/trunk/src/helma/main/JettyServer.java	2008-12-13 01:39:10 UTC (rev 9429)
+++ helma/helma/trunk/src/helma/main/JettyServer.java	2008-12-13 02:36:39 UTC (rev 9430)
@@ -18,6 +18,7 @@
 
 import org.mortbay.http.HttpServer;
 import org.mortbay.http.HttpContext;
+import org.mortbay.http.SocketListener;
 import org.mortbay.http.ajp.AJP13Listener;
 import org.mortbay.util.InetAddrPort;
 
@@ -34,8 +35,7 @@
     // the AJP13 Listener, used for connecting from external webserver to servlet via JK
     protected AJP13Listener ajp13;
 
-    public static JettyServer init(Server server)
-            throws MalformedURLException, IOException {
+    public static JettyServer init(Server server) throws IOException {
         if (server.configFile != null && server.configFile.exists()) {
             return new JettyServer(server.configFile.toURI().toURL());
         } else if (server.websrvPort != null || server.ajp13Port != null) {
@@ -52,9 +52,15 @@
             throws IOException {
         http = new HttpServer();
 
-        // start embedded web server if port is specified
+        // create embedded web server if port is specified
         if (webPort != null) {
-            http.addListener(new InetAddrPort(webPort.getInetAddress(), webPort.getPort()));
+            // opening the listener here allows us to run on priviledged port 80 under jsvc
+            // even as non-root user, because init() is called with root privileges
+            // while start() will be called with the user we will actually run as
+            InetAddrPort addr = new InetAddrPort(webPort.getInetAddress(), webPort.getPort());
+            SocketListener listener = new SocketListener(addr);
+            listener.open();
+            http.addListener(listener);
         }
 
         // activate the ajp13-listener

Modified: helma/helma/trunk/src/helma/main/Server.java
===================================================================
--- helma/helma/trunk/src/helma/main/Server.java	2008-12-13 01:39:10 UTC (rev 9429)
+++ helma/helma/trunk/src/helma/main/Server.java	2008-12-13 02:36:39 UTC (rev 9430)
@@ -118,7 +118,7 @@
      * Static main entry point.
      * @param args the command line arguments
      */
-    public static void main(String[] args) {
+    public static void main(String[] args) throws IOException {
         loadServer(args);
         // parse properties files etc
         server.init();
@@ -411,7 +411,7 @@
     /**
       * initialize the server
       */
-    public void init() {
+    public void init() throws IOException {
 
         // set the log factory property
         String logFactory = sysProps.getProperty("loggerFactory",
@@ -490,6 +490,7 @@
         if (sysProps.getProperty("extensions") != null) {
             initExtensions();
         }
+        jetty = JettyServer.init(this);
     }
 
 
@@ -573,8 +574,6 @@
      */
     public void run() {
         try {
-            jetty = JettyServer.init(this);
-
             if (xmlrpcPort != null) {
                 String xmlparser = sysProps.getProperty("xmlparser");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.