updated for jinetd
authoradam <adam@megacz.com>
Thu, 24 Mar 2005 11:13:58 +0000 (11:13 +0000)
committeradam <adam@megacz.com>
Thu, 24 Mar 2005 11:13:58 +0000 (11:13 +0000)
darcs-hash:20050324111358-5007d-4c7c1a488a43c179cdcdad67e2fe87ede543c5ec.gz

src/org/ibex/jetty/Jetty.java

index 3fc4fc5..cba21a9 100644 (file)
@@ -27,71 +27,52 @@ public class Jetty {
         hs.addListener(sl);
         instance = new Jetty();
         try {
-            ClassLoader cc = Thread.currentThread().getContextClassLoader();
-            Thread.currentThread().setContextClassLoader(Jetty.class.getClassLoader());
             sl.setHttpServer(hs);
-            addContexts(org.ibex.jinetd.Main.ROOT + "/host", null);
+            Host.init();
+            Enumeration e = Host.enumerateHosts();
+            while(e.hasMoreElements()) {
+                Host host = (Host)e.nextElement();
+                try {
+                    createContext(host);
+                } catch (Exception ex) {
+                    Log.warn(Jetty.class, ex);
+                }
+            }
             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 = new WebApplicationContext(path);
-                   context.setContextPath("");
-                    hs.addContext(host, context);
-                    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);
+    private static void createContext(Host host) throws Exception {
+        WebApplicationContext context = new WebApplicationContext(host.path);
+        context.setContextPath("");
+        hs.addContext(host.hostname, context);
+        //context.getServletHandler().getHttpContext().setParentClassLoader(Jetty.class.getClassLoader());   // ???
+        context.setClassLoaderJava2Compliant(true);
+        context.setClassLoader(host);
+        //context.setParentClassLoader(Jetty.class.getClassLoader());
+        context.setResourceBase(host.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.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<list.length; i++) {
-                if (list[i].indexOf('.') != -1) continue;
-                if (!list[i].toLowerCase().equals(list[i])) continue;
-                addContexts(path + File.separatorChar + list[i], (host == null ? list[i] : (list[i] + "." + host)));
-            }
-        } catch (Exception e) {
-            Log.warn(Main.class, e);
-        }
+        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" });
     }
 
     public void accept(Connection conn) {