r9834 - in helma/helma/trunk: lib src/helma/main src/helma/main/launcher
[email protected] Wed, 17 Jun 2009 14:41:22 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090617124122.4E13B3D0E3@mia> |
Author: hannes
Date: 2009-06-17 14:41:22 +0200 (Wed, 17 Jun 2009)
New Revision: 9834
Added:
helma/helma/trunk/lib/jetty-ajp.jar
helma/helma/trunk/lib/jetty-util.jar
Modified:
helma/helma/trunk/lib/jetty.jar
helma/helma/trunk/lib/servlet.jar
helma/helma/trunk/src/helma/main/ApplicationManager.java
helma/helma/trunk/src/helma/main/JettyServer.java
helma/helma/trunk/src/helma/main/Server.java
helma/helma/trunk/src/helma/main/launcher/Main.java
Log:
Merge branch jetty6 back into trunk.
Details at http://dev.helma.org/trac/helma/changeset/9834
Copied: helma/helma/trunk/lib/jetty-ajp.jar (from rev 9833, helma/helma/branches/jetty6/lib/jetty-ajp.jar)
Copied: helma/helma/trunk/lib/jetty-util.jar (from rev 9833, helma/helma/branches/jetty6/lib/jetty-util.jar)
Modified: helma/helma/trunk/lib/jetty.jar
===================================================================
(Binary files differ)
Modified: helma/helma/trunk/lib/servlet.jar
===================================================================
(Binary files differ)
Modified: helma/helma/trunk/src/helma/main/ApplicationManager.java
===================================================================
--- helma/helma/trunk/src/helma/main/ApplicationManager.java 2009-06-17 12:28:52 UTC (rev 9833)
+++ helma/helma/trunk/src/helma/main/ApplicationManager.java 2009-06-17 12:41:22 UTC (rev 9834)
@@ -22,14 +22,17 @@
import helma.util.StringUtils;
import org.apache.xmlrpc.XmlRpcHandler;
import org.apache.commons.logging.Log;
-import org.mortbay.http.*;
-import org.mortbay.http.handler.*;
-import org.mortbay.jetty.servlet.*;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.handler.ContextHandlerCollection;
+import org.mortbay.jetty.handler.ResourceHandler;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+
import java.io.*;
import java.rmi.*;
import java.util.*;
import helma.util.ResourceProperties;
-import helma.util.Logging;
+import helma.servlet.EmbeddedServletClient;
/**
* This class is responsible for starting and stopping Helma applications.
@@ -42,6 +45,7 @@
private ResourceProperties props;
private Server server;
private long lastModified;
+ private ContextHandlerCollection context;
private JettyServer jetty = null;
/**
@@ -279,10 +283,10 @@
}
if (mountpoint.endsWith("/")) {
- return mountpoint + "*";
+ return mountpoint.substring(0, mountpoint.length()-1);
}
- return mountpoint + "/*";
+ return mountpoint;
}
private File getAbsoluteFile(String path) {
@@ -315,6 +319,9 @@
Application app;
+ private ContextHandler staticContext = null;
+ private ContextHandler appContext = null;
+
String appName;
File appDir;
File dbDir;
@@ -491,9 +498,34 @@
// bind to Jetty HTTP server
if (jetty != null) {
+ if(context == null) {
+ context = new ContextHandlerCollection();
+ context.mapContexts();
+ jetty.getHttpServer().setHandler(context);
+ }
- HttpContext context = jetty.addContext(pathPattern);
+ // if there is a static direcory specified, mount it
+ if (staticDir != null) {
+ File staticContent = getAbsoluteFile(staticDir);
+
+ getLogger().info("Serving static from " +
+ staticContent.getPath());
+ getLogger().info("Mounting static at " +
+ staticMountpoint);
+
+ ResourceHandler rhandler = new ResourceHandler();
+ rhandler.setResourceBase(staticContent.getPath());
+ rhandler.setWelcomeFiles(staticHome);
+
+ staticContext = context.addContext(staticMountpoint, "");
+ staticContext.setHandler(rhandler);
+
+ staticContext.start();
+ }
+
+ appContext = context.addContext(pathPattern, "");
+
if (encode) {
// FIXME: ContentEncodingHandler is broken/removed in Jetty 4.2
// context.addHandler(new ContentEncodingHandler());
@@ -502,8 +534,8 @@
ServletHandler handler = new ServletHandler();
- ServletHolder holder = handler.addServlet(appName, "/*",
- "helma.servlet.EmbeddedServletClient");
+ ServletHolder holder = new ServletHolder(EmbeddedServletClient.class);
+ handler.addServletWithMapping(holder, "/*");
holder.setInitParameter("application", appName);
// holder.setInitParameter("mountpoint", mountpoint);
@@ -531,38 +563,17 @@
if (debug != null) {
holder.setInitParameter("debug", debug);
}
+
+ appContext.setHandler(handler);
- context.addHandler(handler);
-
if (protectedStaticDir != null) {
File protectedContent = getAbsoluteFile(protectedStaticDir);
- context.setResourceBase(protectedContent.getPath());
+ appContext.setResourceBase(protectedContent.getPath());
getLogger().info("Serving protected static from " +
protectedContent.getPath());
}
- context.start();
-
- // if there is a static direcory specified, mount it
- if (staticDir != null) {
-
- File staticContent = getAbsoluteFile(staticDir);
-
- getLogger().info("Serving static from " +
- staticContent.getPath());
- getLogger().info("Mounting static at " +
- staticMountpoint);
-
- context = jetty.addContext(staticMountpoint);
- context.setWelcomeFiles(staticHome);
-
- context.setResourceBase(staticContent.getPath());
-
- ResourceHandler rhandler = new ResourceHandler();
- rhandler.setDirAllowed(staticIndex);
- context.addHandler(rhandler);
- context.start();
- }
+ appContext.start();
}
// register as XML-RPC handler
@@ -586,20 +597,16 @@
// unbind from Jetty HTTP server
if (jetty != null) {
- HttpContext context = jetty.getContext(pathPattern);
-
- if (context != null) {
- context.stop();
- context.destroy();
+ if (appContext != null) {
+ appContext.stop();
+ appContext.destroy();
+ appContext = null;
}
- if (staticDir != null) {
- context = jetty.getContext(staticMountpoint);
-
- if (context != null) {
- context.stop();
- context.destroy();
- }
+ if (staticContext != null) {
+ staticContext.stop();
+ staticContext.destroy();
+ staticContext = null;
}
}
Modified: helma/helma/trunk/src/helma/main/JettyServer.java
===================================================================
--- helma/helma/trunk/src/helma/main/JettyServer.java 2009-06-17 12:28:52 UTC (rev 9833)
+++ helma/helma/trunk/src/helma/main/JettyServer.java 2009-06-17 12:41:22 UTC (rev 9834)
@@ -16,14 +16,13 @@
package helma.main;
-import org.mortbay.http.HttpServer;
-import org.mortbay.http.HttpContext;
-import org.mortbay.http.SocketListener;
-import org.mortbay.http.HttpListener;
-import org.mortbay.http.ajp.AJP13Listener;
-import org.mortbay.util.InetAddrPort;
-import java.util.StringTokenizer;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.ajp.Ajp13SocketConnector;
+import org.mortbay.jetty.bio.SocketConnector;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.xml.XmlConfiguration;
+
import java.net.URL;
import java.net.InetSocketAddress;
import java.io.IOException;
@@ -32,10 +31,10 @@
public class JettyServer {
// the embedded web server
- protected HttpServer http;
+ protected org.mortbay.jetty.Server http;
// the AJP13 Listener, used for connecting from external webserver to servlet via JK
- protected AJP13Listener ajp13;
+ protected Ajp13SocketConnector ajp13;
public static JettyServer init(Server server, ServerConfig config) throws IOException {
File configFile = config.getConfigFile();
@@ -48,59 +47,62 @@
}
private JettyServer(URL url) throws IOException {
- http = new org.mortbay.jetty.Server(url);
- openListeners();
+ http = new org.mortbay.jetty.Server();
+
+ try {
+ XmlConfiguration config = new XmlConfiguration(url);
+ config.configure(http);
+
+ openListeners();
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException("Jetty configuration problem: " + e);
+ }
}
private JettyServer(InetSocketAddress webPort, InetSocketAddress ajpPort, Server server)
throws IOException {
- http = new HttpServer();
-
- // create embedded web server if port is specified
+
+ http = new org.mortbay.jetty.Server();
+ http.setServer(http);
+
+ // start embedded web server if port is specified
if (webPort != null) {
- http.addListener(new InetAddrPort(webPort.getAddress(), webPort.getPort()));
+ Connector conn = new SelectChannelConnector();
+ conn.setHost(webPort.getAddress().getHostAddress());
+ conn.setPort(webPort.getPort());
+
+ http.addConnector(conn);
}
// activate the ajp13-listener
if (ajpPort != null) {
// create AJP13Listener
- ajp13 = new AJP13Listener(new InetAddrPort(ajpPort.getAddress(), ajpPort.getPort()));
- ajp13.setHttpServer(http);
+ ajp13 = new Ajp13SocketConnector();
+ ajp13.setHost(ajpPort.getAddress().getHostAddress());
+ ajp13.setPort(ajpPort.getPort());
+
+ http.addConnector(ajp13);
- String jkallow = server.sysProps.getProperty("allowAJP13");
-
- // by default the AJP13-connection just accepts requests from 127.0.0.1
- if (jkallow == null) {
- jkallow = "127.0.0.1";
+ // jetty6 does not support protection of AJP13 connections anymore
+ if (server.sysProps.containsKey("allowAJP13")) {
+ String message = "allowAJP13 property is no longer supported. " +
+ "Please remove it from your config and use a firewall " +
+ "to protect the AJP13 port";
+ server.getLogger().error(message);
+ throw new RuntimeException(message);
}
- StringTokenizer st = new StringTokenizer(jkallow, " ,;");
- String[] jkallowarr = new String[st.countTokens()];
- int cnt = 0;
-
- while (st.hasMoreTokens()) {
- jkallowarr[cnt] = st.nextToken();
- cnt++;
- }
-
- ajp13.setRemoteServers(jkallowarr);
server.getLogger().info("Starting AJP13-Listener on port " + (ajpPort));
}
openListeners();
}
- public HttpServer getHttpServer() {
+ public org.mortbay.jetty.Server getHttpServer() {
return http;
}
- public HttpContext getContext(String contextPath) {
- return http.getContext(contextPath);
- }
-
- public HttpContext addContext(String contextPath) {
- return http.addContext(contextPath);
- }
-
public void start() throws Exception {
http.start();
if (ajp13 != null) {
@@ -108,7 +110,7 @@
}
}
- public void stop() throws InterruptedException {
+ public void stop() throws Exception {
http.stop();
if (ajp13 != null) {
ajp13.stop();
@@ -123,11 +125,11 @@
// 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
- HttpListener[] listeners = http.getListeners();
- for (int i = 0; i < listeners.length; i++) {
- if (listeners[i] instanceof SocketListener) {
- SocketListener listener = (SocketListener) listeners[i];
- listener.open();
+ Connector[] connectors = http.getConnectors();
+ for (int i = 0; i < connectors.length; i++) {
+ if (connectors[i] instanceof SocketConnector) {
+ SocketConnector connector = (SocketConnector) connectors[i];
+ connector.open();
}
}
}
Modified: helma/helma/trunk/src/helma/main/Server.java
===================================================================
--- helma/helma/trunk/src/helma/main/Server.java 2009-06-17 12:28:52 UTC (rev 9833)
+++ helma/helma/trunk/src/helma/main/Server.java 2009-06-17 12:41:22 UTC (rev 9834)
@@ -519,8 +519,8 @@
try {
jetty.stop();
jetty.destroy();
- } catch (InterruptedException irx) {
- // http.stop() interrupted by another thread. ignore.
+ } catch (Exception x) {
+ // exception in jettx stop. ignore.
}
}
Modified: helma/helma/trunk/src/helma/main/launcher/Main.java
===================================================================
--- helma/helma/trunk/src/helma/main/launcher/Main.java 2009-06-17 12:28:52 UTC (rev 9833)
+++ helma/helma/trunk/src/helma/main/launcher/Main.java 2009-06-17 12:41:22 UTC (rev 9834)
@@ -36,8 +36,9 @@
public class Main {
public static final String[] jars = {
"helma.jar", "rhino.jar", "jetty.jar",
- "commons-logging.jar",
- "crimson.jar", "xmlrpc.jar", "servlet.jar",
+ "jetty-util.jar", "jetty-ajp.jar",
+ "commons-logging.jar", "crimson.jar",
+ "xmlrpc.jar", "servlet.jar",
"mail.jar", "activation.jar",
"commons-fileupload.jar", "commons-codec.jar",
"commons-io.jar", "commons-net.jar",