Merge branch jetty6 back into trunk.
This commit is contained in:
parent
b48fb4e277
commit
ed6db227cc
8 changed files with 107 additions and 97 deletions
BIN
lib/jetty-ajp.jar
Normal file
BIN
lib/jetty-ajp.jar
Normal file
Binary file not shown.
BIN
lib/jetty-util.jar
Normal file
BIN
lib/jetty-util.jar
Normal file
Binary file not shown.
BIN
lib/jetty.jar
BIN
lib/jetty.jar
Binary file not shown.
BIN
lib/servlet.jar
BIN
lib/servlet.jar
Binary file not shown.
|
@ -22,14 +22,17 @@ import helma.framework.repository.FileRepository;
|
||||||
import helma.util.StringUtils;
|
import helma.util.StringUtils;
|
||||||
import org.apache.xmlrpc.XmlRpcHandler;
|
import org.apache.xmlrpc.XmlRpcHandler;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.mortbay.http.*;
|
import org.mortbay.jetty.handler.ContextHandler;
|
||||||
import org.mortbay.http.handler.*;
|
import org.mortbay.jetty.handler.ContextHandlerCollection;
|
||||||
import org.mortbay.jetty.servlet.*;
|
import org.mortbay.jetty.handler.ResourceHandler;
|
||||||
|
import org.mortbay.jetty.servlet.ServletHandler;
|
||||||
|
import org.mortbay.jetty.servlet.ServletHolder;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.rmi.*;
|
import java.rmi.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import helma.util.ResourceProperties;
|
import helma.util.ResourceProperties;
|
||||||
import helma.util.Logging;
|
import helma.servlet.EmbeddedServletClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is responsible for starting and stopping Helma applications.
|
* This class is responsible for starting and stopping Helma applications.
|
||||||
|
@ -42,6 +45,7 @@ public class ApplicationManager implements XmlRpcHandler {
|
||||||
private ResourceProperties props;
|
private ResourceProperties props;
|
||||||
private Server server;
|
private Server server;
|
||||||
private long lastModified;
|
private long lastModified;
|
||||||
|
private ContextHandlerCollection context;
|
||||||
private JettyServer jetty = null;
|
private JettyServer jetty = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,10 +283,10 @@ public class ApplicationManager implements XmlRpcHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mountpoint.endsWith("/")) {
|
if (mountpoint.endsWith("/")) {
|
||||||
return mountpoint + "*";
|
return mountpoint.substring(0, mountpoint.length()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mountpoint + "/*";
|
return mountpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getAbsoluteFile(String path) {
|
private File getAbsoluteFile(String path) {
|
||||||
|
@ -315,6 +319,9 @@ public class ApplicationManager implements XmlRpcHandler {
|
||||||
|
|
||||||
Application app;
|
Application app;
|
||||||
|
|
||||||
|
private ContextHandler staticContext = null;
|
||||||
|
private ContextHandler appContext = null;
|
||||||
|
|
||||||
String appName;
|
String appName;
|
||||||
File appDir;
|
File appDir;
|
||||||
File dbDir;
|
File dbDir;
|
||||||
|
@ -491,8 +498,33 @@ public class ApplicationManager implements XmlRpcHandler {
|
||||||
|
|
||||||
// bind to Jetty HTTP server
|
// bind to Jetty HTTP server
|
||||||
if (jetty != null) {
|
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) {
|
if (encode) {
|
||||||
// FIXME: ContentEncodingHandler is broken/removed in Jetty 4.2
|
// FIXME: ContentEncodingHandler is broken/removed in Jetty 4.2
|
||||||
|
@ -502,8 +534,8 @@ public class ApplicationManager implements XmlRpcHandler {
|
||||||
|
|
||||||
ServletHandler handler = new ServletHandler();
|
ServletHandler handler = new ServletHandler();
|
||||||
|
|
||||||
ServletHolder holder = handler.addServlet(appName, "/*",
|
ServletHolder holder = new ServletHolder(EmbeddedServletClient.class);
|
||||||
"helma.servlet.EmbeddedServletClient");
|
handler.addServletWithMapping(holder, "/*");
|
||||||
|
|
||||||
holder.setInitParameter("application", appName);
|
holder.setInitParameter("application", appName);
|
||||||
// holder.setInitParameter("mountpoint", mountpoint);
|
// holder.setInitParameter("mountpoint", mountpoint);
|
||||||
|
@ -532,37 +564,16 @@ public class ApplicationManager implements XmlRpcHandler {
|
||||||
holder.setInitParameter("debug", debug);
|
holder.setInitParameter("debug", debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.addHandler(handler);
|
appContext.setHandler(handler);
|
||||||
|
|
||||||
if (protectedStaticDir != null) {
|
if (protectedStaticDir != null) {
|
||||||
File protectedContent = getAbsoluteFile(protectedStaticDir);
|
File protectedContent = getAbsoluteFile(protectedStaticDir);
|
||||||
context.setResourceBase(protectedContent.getPath());
|
appContext.setResourceBase(protectedContent.getPath());
|
||||||
getLogger().info("Serving protected static from " +
|
getLogger().info("Serving protected static from " +
|
||||||
protectedContent.getPath());
|
protectedContent.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
context.start();
|
appContext.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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// register as XML-RPC handler
|
// register as XML-RPC handler
|
||||||
|
@ -586,20 +597,16 @@ public class ApplicationManager implements XmlRpcHandler {
|
||||||
|
|
||||||
// unbind from Jetty HTTP server
|
// unbind from Jetty HTTP server
|
||||||
if (jetty != null) {
|
if (jetty != null) {
|
||||||
HttpContext context = jetty.getContext(pathPattern);
|
if (appContext != null) {
|
||||||
|
appContext.stop();
|
||||||
if (context != null) {
|
appContext.destroy();
|
||||||
context.stop();
|
appContext = null;
|
||||||
context.destroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (staticDir != null) {
|
if (staticContext != null) {
|
||||||
context = jetty.getContext(staticMountpoint);
|
staticContext.stop();
|
||||||
|
staticContext.destroy();
|
||||||
if (context != null) {
|
staticContext = null;
|
||||||
context.stop();
|
|
||||||
context.destroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,13 @@
|
||||||
|
|
||||||
package helma.main;
|
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.URL;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -32,10 +31,10 @@ import java.io.File;
|
||||||
public class JettyServer {
|
public class JettyServer {
|
||||||
|
|
||||||
// the embedded web server
|
// 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
|
// 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 {
|
public static JettyServer init(Server server, ServerConfig config) throws IOException {
|
||||||
File configFile = config.getConfigFile();
|
File configFile = config.getConfigFile();
|
||||||
|
@ -48,59 +47,62 @@ public class JettyServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private JettyServer(URL url) throws IOException {
|
private JettyServer(URL url) throws IOException {
|
||||||
http = new org.mortbay.jetty.Server(url);
|
http = new org.mortbay.jetty.Server();
|
||||||
openListeners();
|
|
||||||
|
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)
|
private JettyServer(InetSocketAddress webPort, InetSocketAddress ajpPort, Server server)
|
||||||
throws IOException {
|
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) {
|
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
|
// activate the ajp13-listener
|
||||||
if (ajpPort != null) {
|
if (ajpPort != null) {
|
||||||
// create AJP13Listener
|
// create AJP13Listener
|
||||||
ajp13 = new AJP13Listener(new InetAddrPort(ajpPort.getAddress(), ajpPort.getPort()));
|
ajp13 = new Ajp13SocketConnector();
|
||||||
ajp13.setHttpServer(http);
|
ajp13.setHost(ajpPort.getAddress().getHostAddress());
|
||||||
|
ajp13.setPort(ajpPort.getPort());
|
||||||
|
|
||||||
String jkallow = server.sysProps.getProperty("allowAJP13");
|
http.addConnector(ajp13);
|
||||||
|
|
||||||
// by default the AJP13-connection just accepts requests from 127.0.0.1
|
// jetty6 does not support protection of AJP13 connections anymore
|
||||||
if (jkallow == null) {
|
if (server.sysProps.containsKey("allowAJP13")) {
|
||||||
jkallow = "127.0.0.1";
|
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));
|
server.getLogger().info("Starting AJP13-Listener on port " + (ajpPort));
|
||||||
}
|
}
|
||||||
openListeners();
|
openListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpServer getHttpServer() {
|
public org.mortbay.jetty.Server getHttpServer() {
|
||||||
return http;
|
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 {
|
public void start() throws Exception {
|
||||||
http.start();
|
http.start();
|
||||||
if (ajp13 != null) {
|
if (ajp13 != null) {
|
||||||
|
@ -108,7 +110,7 @@ public class JettyServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() throws InterruptedException {
|
public void stop() throws Exception {
|
||||||
http.stop();
|
http.stop();
|
||||||
if (ajp13 != null) {
|
if (ajp13 != null) {
|
||||||
ajp13.stop();
|
ajp13.stop();
|
||||||
|
@ -123,11 +125,11 @@ public class JettyServer {
|
||||||
// opening the listener here allows us to run on priviledged port 80 under jsvc
|
// 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
|
// 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
|
// while start() will be called with the user we will actually run as
|
||||||
HttpListener[] listeners = http.getListeners();
|
Connector[] connectors = http.getConnectors();
|
||||||
for (int i = 0; i < listeners.length; i++) {
|
for (int i = 0; i < connectors.length; i++) {
|
||||||
if (listeners[i] instanceof SocketListener) {
|
if (connectors[i] instanceof SocketConnector) {
|
||||||
SocketListener listener = (SocketListener) listeners[i];
|
SocketConnector connector = (SocketConnector) connectors[i];
|
||||||
listener.open();
|
connector.open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -519,8 +519,8 @@ public class Server implements Runnable {
|
||||||
try {
|
try {
|
||||||
jetty.stop();
|
jetty.stop();
|
||||||
jetty.destroy();
|
jetty.destroy();
|
||||||
} catch (InterruptedException irx) {
|
} catch (Exception x) {
|
||||||
// http.stop() interrupted by another thread. ignore.
|
// exception in jettx stop. ignore.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,9 @@ import java.util.ArrayList;
|
||||||
public class Main {
|
public class Main {
|
||||||
public static final String[] jars = {
|
public static final String[] jars = {
|
||||||
"helma.jar", "rhino.jar", "jetty.jar",
|
"helma.jar", "rhino.jar", "jetty.jar",
|
||||||
"commons-logging.jar",
|
"jetty-util.jar", "jetty-ajp.jar",
|
||||||
"crimson.jar", "xmlrpc.jar", "servlet.jar",
|
"commons-logging.jar", "crimson.jar",
|
||||||
|
"xmlrpc.jar", "servlet.jar",
|
||||||
"mail.jar", "activation.jar",
|
"mail.jar", "activation.jar",
|
||||||
"commons-fileupload.jar", "commons-codec.jar",
|
"commons-fileupload.jar", "commons-codec.jar",
|
||||||
"commons-io.jar", "commons-net.jar",
|
"commons-io.jar", "commons-net.jar",
|
||||||
|
|
Loading…
Add table
Reference in a new issue