Merge branch jetty6 back into trunk.

This commit is contained in:
hns 2009-06-17 12:41:22 +00:00
parent b48fb4e277
commit ed6db227cc
8 changed files with 107 additions and 97 deletions

BIN
lib/jetty-ajp.jar Normal file

Binary file not shown.

BIN
lib/jetty-util.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -22,14 +22,17 @@ import helma.framework.repository.FileRepository;
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 @@ public class ApplicationManager implements XmlRpcHandler {
private ResourceProperties props;
private Server server;
private long lastModified;
private ContextHandlerCollection context;
private JettyServer jetty = null;
/**
@ -279,10 +283,10 @@ public class ApplicationManager implements XmlRpcHandler {
}
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 @@ public class ApplicationManager implements XmlRpcHandler {
Application app;
private ContextHandler staticContext = null;
private ContextHandler appContext = null;
String appName;
File appDir;
File dbDir;
@ -491,8 +498,33 @@ public class ApplicationManager implements XmlRpcHandler {
// 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
@ -502,8 +534,8 @@ public class ApplicationManager implements XmlRpcHandler {
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 @@ public class ApplicationManager implements XmlRpcHandler {
if (debug != null) {
holder.setInitParameter("debug", debug);
}
context.addHandler(handler);
appContext.setHandler(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 @@ public class ApplicationManager implements XmlRpcHandler {
// 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;
}
}

View file

@ -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 @@ import java.io.File;
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 @@ public class JettyServer {
}
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 class JettyServer {
}
}
public void stop() throws InterruptedException {
public void stop() throws Exception {
http.stop();
if (ajp13 != null) {
ajp13.stop();
@ -123,11 +125,11 @@ public class JettyServer {
// 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();
}
}
}

View file

@ -519,8 +519,8 @@ public class Server implements Runnable {
try {
jetty.stop();
jetty.destroy();
} catch (InterruptedException irx) {
// http.stop() interrupted by another thread. ignore.
} catch (Exception x) {
// exception in jettx stop. ignore.
}
}

View file

@ -36,8 +36,9 @@ import java.util.ArrayList;
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",