X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Fj2ee%2FServlet.java;h=d726474bc87746c8765f052a37da5eb3f228a987;hb=83f55da4bce455a30c7519c9a74cad30fb395e11;hp=d050c017f05059e33af06b2f889dfe3925cedbd5;hpb=78f5d1201f8d3aecb660b7877b08d9bfbe650911;p=jsvc.git diff --git a/src/dolda/jsvc/j2ee/Servlet.java b/src/dolda/jsvc/j2ee/Servlet.java index d050c01..d726474 100644 --- a/src/dolda/jsvc/j2ee/Servlet.java +++ b/src/dolda/jsvc/j2ee/Servlet.java @@ -1,14 +1,47 @@ package dolda.jsvc.j2ee; import dolda.jsvc.*; +import java.lang.reflect.*; +import java.util.*; import java.io.*; import javax.servlet.http.*; +import javax.servlet.*; public class Servlet extends HttpServlet { - private Responder root; + private ThreadContext tg; + + public void init(ServletConfig cfg) throws ServletException { + Properties sprop = new Properties(); + try { + InputStream pi = Servlet.class.getClassLoader().getResourceAsStream("jsvc.properties"); + try { + sprop.load(pi); + } finally { + pi.close(); + } + } catch(IOException e) { + throw(new Error(e)); + } + String clnm = (String)sprop.get("jsvc.bootstrap"); + if(clnm == null) + throw(new ServletException("No JSvc bootstrapper specified")); + Class bc; + try { + bc = Class.forName(clnm); + } catch(ClassNotFoundException e) { + throw(new ServletException("Invalid JSvc bootstrapper specified", e)); + } + ServerContext ctx = J2eeContext.create(cfg); + String tgn; + if(ctx.name() != null) + tgn = "JSvc service for " + ctx.name(); + else + tgn = "JSvc service"; + tg = new ThreadContext(null, tgn, ctx, bc); + } - public void init() { - + public void destroy() { + tg.shutdown(); } public void service(HttpServletRequest req, HttpServletResponse resp) { @@ -19,6 +52,13 @@ public class Servlet extends HttpServlet { throw(new Error(e)); } Request rr = new J2eeRequest(getServletConfig(), req, resp); - root.respond(rr); + RequestThread w = tg.respond(rr); + w.start(); + try { + w.join(); + } catch(InterruptedException e) { + w.interrupt(); + return; + } } }