From 8280c3aadad02de389ff061c3676542128b03e33 Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 20 Mar 2005 21:42:49 +0000 Subject: [PATCH] import darcs-hash:20050320214249-5007d-c61d83da0f48cfda34642cc2bea4ade3425d3acb.gz --- src/org/ibex/jetty/Jetty.java | 130 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 src/org/ibex/jetty/Jetty.java diff --git a/src/org/ibex/jetty/Jetty.java b/src/org/ibex/jetty/Jetty.java new file mode 100644 index 0000000..b5fa5fe --- /dev/null +++ b/src/org/ibex/jetty/Jetty.java @@ -0,0 +1,130 @@ +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the Apache Public Source License 2.0 ("the License"). +// You may not use this file except in compliance with the License. + +package org.ibex.jetty; +import org.mortbay.jetty.servlet.*; +import org.mortbay.jetty.*; +import org.mortbay.http.handler.*; +import org.mortbay.http.*; +import org.ibex.util.*; +import org.ibex.jinetd.*; +import org.ibex.io.*; +import java.io.*; +import java.net.*; +import java.util.*; + +public class Jetty { + + private static Jetty instance = null; + private static Server hs = null; + private static SocketListener sl = null; + + public static synchronized Jetty instance() { + if (instance != null) return instance; + hs = new Server(); + sl = new SocketListener(); + hs.addListener(sl); + instance = new Jetty(); + try { + ClassLoader cc = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(Jetty.class.getClassLoader()); + sl.setHttpServer(hs); + addContexts(Root.root + "/host", null); + hs.start(); + Thread.currentThread().setContextClassLoader(cc); + } catch (Exception e) { Log.error(Main.class, e); } + return instance; + } + + private static void addContexts(String path, String host) { + try { + File webinf = new File(path + "/WEB-INF"); + if (webinf.exists()) { + String pad = ""; + while(pad.length() + host.length() < 30) pad += " "; + try { + InetAddress.getByName(host); + Log.info(Main.class, pad + host + " => " + path); + WebApplicationContext context = hs.addWebApplication(host, "", path); + context.getServletHandler().getHttpContext().setParentClassLoader(Jetty.class.getClassLoader()); + context.setClassLoaderJava2Compliant(true); + context.setClassLoader(new TreeClassLoader(webinf, Jetty.class.getClassLoader())); + context.setParentClassLoader(Jetty.class.getClassLoader()); + context.setResourceBase(path+"/"); + + ServletHolder sh = context.addServlet("jsp", "*.jsp", "org.apache.jasper.servlet.JspServlet"); + sh.setInitParameter("fork", "false"); + sh.setInitParameter("mappedfile", "true"); + sh.setInitParameter("keepgenerated", "false"); + sh.setInitOrder(0); + + context.setWelcomeFiles(new String[] { "index.jsp", "index.html", "index.xt", "index.txt" }); + ServletHolder def = context.addServlet("default", "/", "org.mortbay.jetty.servlet.Default"); + def.setInitParameter("acceptRanges", "true"); + def.setInitParameter("dirAllowed", "true"); + def.setInitParameter("putAllowed", "false"); + def.setInitParameter("delAllowed", "false"); + def.setInitParameter("redirectWelcome", "false"); + def.setInitParameter("minGzipLength", "8192"); + def.setInitOrder(0); + + context.setDefaultsDescriptor(null); + context.addHandler(new ResourceHandler()); + context.addHandler(new NotFoundHandler()); + context.setWelcomeFiles(new String[] { "index.jsp", "index.html", "index.xt", "index.txt" }); + + } catch (UnknownHostException e) { + Log.warn(Main.class, pad + host + " => " + e.getClass().getName()); + } + //return; + } + File f = new File(path); + if (!f.isDirectory()) return; + String[] list = f.list(); + for(int i=0; i