Added support for AJP1.3 protocoll in Jetty.

Updated version string.
This commit is contained in:
hns 2002-09-20 14:12:26 +00:00
parent 93685a87af
commit 8080570bf7
2 changed files with 94 additions and 23 deletions

View file

@ -71,20 +71,31 @@ public class ApplicationManager {
String oldMountpoint = mountpoints.getProperty (appName); String oldMountpoint = mountpoints.getProperty (appName);
String mountpoint = getMountpoint (appName); String mountpoint = getMountpoint (appName);
String pattern = getPathPattern (mountpoint); String pattern = getPathPattern (mountpoint);
if (!pattern.equals (oldMountpoint)) { if (!pattern.equals (oldMountpoint)) {
Server.getLogger().log("Moving application "+appName+" from "+oldMountpoint+" to "+pattern); Server.getLogger().log("Moving application "+appName+" from "+oldMountpoint+" to "+pattern);
HandlerContext oldContext = server.http.getContext (null, oldMountpoint); HttpContext oldContext = server.http.getContext (null, oldMountpoint);
if (oldContext != null) { if (oldContext != null) {
// oldContext.setContextPath(pattern);
oldContext.stop (); oldContext.stop ();
oldContext.destroy (); oldContext.destroy ();
} }
Application app = (Application) applications.get (appName); Application app = (Application) applications.get (appName);
// if using embedded webserver (not AJP) set application URL prefix
if (server.ajp13Port == 0)
app.setBaseURI (mountpoint);
app.setBaseURI (mountpoint); app.setBaseURI (mountpoint);
ServletHandlerContext context = new ServletHandlerContext (server.http, pattern); ServletHttpContext context = new ServletHttpContext ();
server.http.addContext (null, context); context.setContextPath(pattern);
server.http.addContext (context);
ServletHolder holder = context.addServlet (appName, "/*", "helma.servlet.EmbeddedServletClient"); ServletHolder holder = context.addServlet (appName, "/*", "helma.servlet.EmbeddedServletClient");
holder.setInitParameter ("application", appName); holder.setInitParameter ("application", appName);
holder.setInitParameter ("mountpoint", mountpoint); holder.setInitParameter ("mountpoint", mountpoint);
String cookieDomain = props.getProperty (appName+".cookieDomain");
if (cookieDomain != null)
holder.setInitParameter ("cookieDomain", cookieDomain);
String uploadLimit = props.getProperty (appName+".uploadLimit");
if (uploadLimit != null)
holder.setInitParameter ("uploadLimit", uploadLimit);
// holder.start (); // holder.start ();
context.start (); context.start ();
mountpoints.setProperty (appName, pattern); mountpoints.setProperty (appName, pattern);
@ -127,7 +138,7 @@ public class ApplicationManager {
Naming.unbind ("//:"+port+"/"+appName); Naming.unbind ("//:"+port+"/"+appName);
} else { } else {
String mountpoint = mountpoints.getProperty (appName); String mountpoint = mountpoints.getProperty (appName);
HandlerContext context = server.http.getContext (null, mountpoint); HttpContext context = server.http.getContext (null, mountpoint);
if (context != null) { if (context != null) {
context.stop (); context.stop ();
context.destroy (); context.destroy ();
@ -149,14 +160,22 @@ public class ApplicationManager {
Naming.rebind ("//:"+port+"/"+appName, app); Naming.rebind ("//:"+port+"/"+appName, app);
} else { } else {
String mountpoint = getMountpoint (appName); String mountpoint = getMountpoint (appName);
// set application URL prefix // if using embedded webserver (not AJP) set application URL prefix
app.setBaseURI (mountpoint); if (server.ajp13Port == 0)
app.setBaseURI (mountpoint);
String pattern = getPathPattern (mountpoint); String pattern = getPathPattern (mountpoint);
ServletHandlerContext context = new ServletHandlerContext (server.http, pattern); ServletHttpContext context = new ServletHttpContext ();
server.http.addContext (null, context); context.setContextPath(pattern);
server.http.addContext (context);
ServletHolder holder = context.addServlet (appName, "/*", "helma.servlet.EmbeddedServletClient"); ServletHolder holder = context.addServlet (appName, "/*", "helma.servlet.EmbeddedServletClient");
holder.setInitParameter ("application", appName); holder.setInitParameter ("application", appName);
holder.setInitParameter ("mountpoint", mountpoint); holder.setInitParameter ("mountpoint", mountpoint);
String cookieDomain = props.getProperty (appName+".cookieDomain");
if (cookieDomain != null)
holder.setInitParameter ("cookieDomain", cookieDomain);
String uploadLimit = props.getProperty (appName+".uploadLimit");
if (uploadLimit != null)
holder.setInitParameter ("uploadLimit", uploadLimit);
// holder.start (); // holder.start ();
context.start (); context.start ();
mountpoints.setProperty (appName, pattern); mountpoints.setProperty (appName, pattern);
@ -184,9 +203,10 @@ public class ApplicationManager {
// add handler for static files. // add handler for static files.
File staticContent = new File (server.getHopHome(), "static"); File staticContent = new File (server.getHopHome(), "static");
Server.getLogger().log("Serving static content from "+staticContent.getAbsolutePath()); Server.getLogger().log("Serving static content from "+staticContent.getAbsolutePath());
HandlerContext context = server.http.addContext ("/static/*"); HttpContext context = server.http.addContext ("/static/*");
context.setResourceBase (staticContent.getAbsolutePath()); context.setResourceBase (staticContent.getAbsolutePath());
context.setServingResources (true); ResourceHandler handler = new ResourceHandler();
context.addHandler(handler);
context.start (); context.start ();
} }
lastModified = System.currentTimeMillis (); lastModified = System.currentTimeMillis ();

View file

@ -17,7 +17,7 @@ import helma.xmlrpc.*;
import helma.util.*; import helma.util.*;
import org.mortbay.http.*; import org.mortbay.http.*;
import org.mortbay.util.*; import org.mortbay.util.*;
import org.mortbay.http.ajp.*;
/** /**
* Helma server main class. * Helma server main class.
@ -25,7 +25,7 @@ import org.mortbay.util.*;
public class Server implements IPathElement, Runnable { public class Server implements IPathElement, Runnable {
public static final String version = "1.2pre3+ 2002/09/13"; public static final String version = "1.2pre3+ 2002/09/19";
public long starttime; public long starttime;
// if true we only accept RMI and XML-RPC connections from // if true we only accept RMI and XML-RPC connections from
@ -47,6 +47,7 @@ import org.mortbay.util.*;
int rmiPort = 5055; int rmiPort = 5055;
int xmlrpcPort = 5056; int xmlrpcPort = 5056;
int websrvPort = 0; int websrvPort = 0;
int ajp13Port = 0;
// map of server-wide database sources // map of server-wide database sources
Hashtable dbSources; Hashtable dbSources;
@ -63,6 +64,9 @@ import org.mortbay.util.*;
// protected Serve websrv; // protected Serve websrv;
protected HttpServer http; protected HttpServer http;
// the AJP13 Listener, used for connecting from external webserver to servlet via JK
protected AJP13Listener ajp13;
// the XML-RPC server // the XML-RPC server
protected WebServer xmlrpc; protected WebServer xmlrpc;
@ -127,17 +131,24 @@ import org.mortbay.util.*;
} catch (Exception portx) { } catch (Exception portx) {
usageError = true; usageError = true;
} }
} else if (args[i].equals ("-jk") && i+1<args.length) {
try {
ajp13Port = Integer.parseInt (args[++i]);
} catch (Exception portx) {
usageError = true;
}
} else } else
usageError = true; usageError = true;
} }
if (usageError ) { if (usageError ) {
System.out.println ("usage: java helma.objectmodel.db.Server [-h dir] [-f file] [-p port] [-w port] [-x port]"); System.out.println ("usage: java helma.main.Server [-h dir] [-f file] [-p port] [-w port] [-x port]");
System.out.println (" -h dir Specify hop home directory"); System.out.println (" -h dir Specify hop home directory");
System.out.println (" -f file Specify server.properties file"); System.out.println (" -f file Specify server.properties file");
System.out.println (" -p port Specify RMI port number"); System.out.println (" -p port Specify RMI port number");
System.out.println (" -w port Specify port number for embedded Web server"); System.out.println (" -w port Specify port number for embedded Web server");
System.out.println (" -x port Specify XML-RPC port number"); System.out.println (" -x port Specify XML-RPC port number");
System.out.println (" -jk port Specify AJP13 port number");
System.err.println ("Usage Error - exiting"); System.err.println ("Usage Error - exiting");
System.exit (0); System.exit (0);
} }
@ -248,6 +259,7 @@ import org.mortbay.util.*;
mainThread.start (); mainThread.start ();
} }
/** /**
* The main method of the Server. Basically, we set up Applications and than * The main method of the Server. Basically, we set up Applications and than
* periodically check for changes in the apps.properties file, shutting down * periodically check for changes in the apps.properties file, shutting down
@ -257,15 +269,47 @@ import org.mortbay.util.*;
try { try {
if (websrvPort > 0 || ajp13Port > 0) {
http = new HttpServer ();
// disable Jetty logging FIXME: seems to be a jetty bug; as soon
// as the logging is disabled, the more is logged
Log.instance().disableLog ();
Log.instance().add (new LogSink ()
{
public String getOptions () { return null; }
public void log (String formattedLog) {}
public void log (String tag, Object msg, Frame frame, long time) {}
public void setOptions (String options) {}
public boolean isStarted () { return true; }
public void start () {}
public void stop () {}
}
);
}
// start embedded web server if port is specified // start embedded web server if port is specified
if (websrvPort > 0) { if (websrvPort > 0) {
// websrv = new Acme.Serve.Serve (websrvPort, sysProps); http.addListener (new InetAddrPort (websrvPort));
// disable Jetty logging }
Log.instance().disableLog ();
// create new Jetty server and bind it to the web server port // activate the ajp13-listener
http = new HttpServer (); if (ajp13Port > 0) {
http.addListener (new InetAddrPort (websrvPort)); // create AJP13Listener
// http.setRequestLogSink (new OutputStreamLogSink ()); ajp13 = new AJP13Listener(new InetAddrPort (ajp13Port));
ajp13.setHttpServer(http);
String jkallow = sysProps.getProperty ("allowAJP13");
// by default the AJP13-connection just accepts requests from 127.0.0.1
if (jkallow == null)
jkallow = "127.0.0.1";
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);
getLogger().log ("Starting AJP13-Listener on port "+(ajp13Port));
} }
String xmlparser = sysProps.getProperty ("xmlparser"); String xmlparser = sysProps.getProperty ("xmlparser");
@ -327,6 +371,12 @@ import org.mortbay.util.*;
getLogger().log ("Error starting embedded web server: "+m); getLogger().log ("Error starting embedded web server: "+m);
} }
if (ajp13 != null) try {
ajp13.start ();
} catch (Exception m) {
getLogger().log ("Error starting AJP13 listener: "+m);
}
int count = 0; int count = 0;
while (Thread.currentThread () == mainThread) { while (Thread.currentThread () == mainThread) {
try { try {
@ -338,7 +388,6 @@ import org.mortbay.util.*;
getLogger().log ("Caught in app manager loop: "+x); getLogger().log ("Caught in app manager loop: "+x);
} }
} }
} }
/** /**
@ -469,4 +518,6 @@ import org.mortbay.util.*;
public String getPrototype() { public String getPrototype() {
return "root"; return "root";
} }
} }