1 package dolda.jsvc.j2ee;
4 import java.lang.reflect.*;
7 import javax.servlet.http.*;
8 import javax.servlet.*;
10 public class Servlet extends HttpServlet {
11 private Responder root;
12 private ThreadGroup workers;
13 private long reqs = 0;
15 public void init() throws ServletException {
16 workers = new ThreadGroup("JSvc worker threads") {
17 public void uncaughtException(Thread t, Throwable e) {
18 log("Worker thread terminated with an uncaught exception", e);
21 Properties sprop = new Properties();
23 InputStream pi = Servlet.class.getClassLoader().getResourceAsStream("jsvc.properties");
29 } catch(IOException e) {
32 String clnm = (String)sprop.get("jsvc.bootstrap");
34 throw(new ServletException("No JSvc bootstrapper specified"));
36 Class<?> rc = Class.forName(clnm);
37 Method cm = rc.getMethod("responder");
38 Object resp = cm.invoke(null);
39 if(!(resp instanceof Responder))
40 throw(new ServletException("JSvc bootstrapper did not return a responder"));
41 root = (Responder)resp;
42 } catch(ClassNotFoundException e) {
43 throw(new ServletException("Invalid JSvc bootstrapper specified", e));
44 } catch(NoSuchMethodException e) {
45 throw(new ServletException("Invalid JSvc bootstrapper specified", e));
46 } catch(IllegalAccessException e) {
47 throw(new ServletException("Invalid JSvc bootstrapper specified", e));
48 } catch(InvocationTargetException e) {
49 throw(new ServletException("JSvc bootstrapper failed", e));
53 public void destroy() {
55 if(root instanceof ContextResponder)
56 ((ContextResponder)root).destroy();
59 public void service(HttpServletRequest req, HttpServletResponse resp) {
61 req.setCharacterEncoding("UTF-8");
62 resp.setCharacterEncoding("UTF-8");
63 } catch(UnsupportedEncodingException e) {
67 Request rr = new J2eeRequest(getServletConfig(), req, resp);
68 RequestThread w = new RequestThread(root, rr, workers, "Worker thread " + mynum);
72 } catch(InterruptedException e) {