From c820cab550dd89d4f79d39ec73e5d4f8ff3303ee Mon Sep 17 00:00:00 2001 From: hns Date: Sat, 13 Dec 2008 02:36:39 +0000 Subject: [PATCH] Create jetty server in init() so we can open privileged ports when running with jsvc. --- src/helma/main/JettyServer.java | 14 ++++++++++---- src/helma/main/Server.java | 7 +++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/helma/main/JettyServer.java b/src/helma/main/JettyServer.java index afc14038..db056867 100644 --- a/src/helma/main/JettyServer.java +++ b/src/helma/main/JettyServer.java @@ -18,6 +18,7 @@ package helma.main; 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 @@ public class JettyServer { // 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 @@ public class JettyServer { 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 diff --git a/src/helma/main/Server.java b/src/helma/main/Server.java index de77d59a..41544eb7 100644 --- a/src/helma/main/Server.java +++ b/src/helma/main/Server.java @@ -118,7 +118,7 @@ public class Server implements Runnable { * 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 @@ public class Server implements Runnable { /** * 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 @@ public class Server implements Runnable { if (sysProps.getProperty("extensions") != null) { initExtensions(); } + jetty = JettyServer.init(this); } @@ -573,8 +574,6 @@ public class Server implements Runnable { */ public void run() { try { - jetty = JettyServer.init(this); - if (xmlrpcPort != null) { String xmlparser = sysProps.getProperty("xmlparser");