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 {
+ J2eeContext ctx = J2eeContext.create(cfg);
+ try {
+ InputStream pi = Servlet.class.getClassLoader().getResourceAsStream("jsvc.properties");
+ try {
+ ctx.loadconfig(pi);
+ } finally {
+ pi.close();
+ }
+ } catch(IOException e) {
+ throw(new Error(e));
+ }
+ String clnm = ctx.libconfig("jsvc.bootstrap", null);
+ 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));
+ }
+ 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) {
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;
+ }
}
}