1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
5 package org.ibex.jetty;
6 import org.mortbay.jetty.servlet.*;
7 import org.mortbay.jetty.*;
8 import org.mortbay.http.handler.*;
9 import org.mortbay.http.*;
10 import org.ibex.util.*;
11 import org.ibex.jinetd.*;
19 private static Jetty instance = null;
20 private static Server hs = null;
21 private static SocketListener sl = null;
23 public static synchronized Jetty instance() {
24 if (instance != null) return instance;
26 sl = new SocketListener();
28 instance = new Jetty();
32 Enumeration e = Host.enumerateHosts();
33 while(e.hasMoreElements()) {
34 Host host = (Host)e.nextElement();
37 } catch (Exception ex) {
38 Log.warn(Jetty.class, ex);
42 } catch (Exception e) { Log.error(Main.class, e); }
46 private static void createContext(Host host) throws Exception {
47 WebApplicationContext context = new WebApplicationContext(host.path);
48 context.setContextPath("");
49 hs.addContext(host.hostname, context);
50 //context.getServletHandler().getHttpContext().setParentClassLoader(Jetty.class.getClassLoader()); // ???
51 context.setClassLoaderJava2Compliant(true);
52 context.setClassLoader(host);
53 //context.setParentClassLoader(Jetty.class.getClassLoader());
54 context.setResourceBase(host.path+"/");
56 ServletHolder sh = context.addServlet("jsp", "*.jsp", "org.apache.jasper.servlet.JspServlet");
57 sh.setInitParameter("fork", "false");
58 sh.setInitParameter("mappedfile", "true");
59 sh.setInitParameter("keepgenerated", "false");
62 context.setWelcomeFiles(new String[] { "index.jsp", "index.html", "index.xt", "index.txt" });
63 ServletHolder def = context.addServlet("default", "/", "org.mortbay.jetty.servlet.Default");
64 def.setInitParameter("acceptRanges", "true");
65 def.setInitParameter("dirAllowed", "true");
66 def.setInitParameter("putAllowed", "false");
67 def.setInitParameter("delAllowed", "false");
68 def.setInitParameter("redirectWelcome", "false");
69 def.setInitParameter("minGzipLength", "8192");
72 context.setDefaultsDescriptor(null);
73 context.addHandler(new ResourceHandler());
74 context.addHandler(new NotFoundHandler());
75 context.setWelcomeFiles(new String[] { "index.jsp", "index.html", "index.xt", "index.txt" });
78 public void accept(Connection conn) {
80 try { sl.handleConnection(conn.getSocket()); } finally { conn.close(); }
81 } catch (Exception e) {
83 if (e instanceof javax.servlet.ServletException) Log.error(this, ((javax.servlet.ServletException)e).getRootCause());
88 // Logging //////////////////////////////////////////////////////////////////////////////
90 static { System.setProperty("org.apache.commons.logging.Log", "org.ibex.jetty.Jetty$LogAdapter"); }
91 public static class LogAdapter implements org.apache.commons.logging.Log {
92 public LogAdapter(String s) { }
93 public void trace(Object o) { /* Log.debug("[jetty]", o); */ }
94 public void trace(Object o, Throwable t) { /* Log.debug("[jetty]", o); Log.debug("[jetty]", t); */ }
95 public void debug(Object o) { /* Log.debug("[jetty]", o); */ }
96 public void debug(Object o, Throwable t) { /* Log.debug("[jetty]", o); Log.debug("[jetty]", t); */ }
97 public void info(Object o) { /* Log.info("[jetty]", o); */ }
98 public void info(Object o, Throwable t) { /* Log.info("[jetty]", o); Log.info("[jetty]", t); */ }
99 public void warn(Object o) { Log.warn("[jetty]", o); }
100 public void warn(Object o, Throwable t) { Log.warn("[jetty]", o); Log.warn("[jetty]", t); }
101 public void error(Object o) { Log.error("[jetty]", o); }
102 public void error(Object o, Throwable t) { Log.error("[jetty]", o); Log.error("[jetty]", t); }
103 public void fatal(Object o) { Log.error("[jetty]", o); }
104 public void fatal(Object o, Throwable t) { Log.error("[jetty]", o); Log.error("[jetty]", t); }
105 public boolean isTraceEnabled() { return false; }
106 public boolean isDebugEnabled() { return false; }
107 public boolean isInfoEnabled() { return false; }
108 public boolean isWarnEnabled() { return true; }
109 public boolean isErrorEnabled() { return true; }
110 public boolean isFatalEnabled() { return true; }