Commit | Line | Data |
---|---|---|
78f5d120 FT |
1 | package dolda.jsvc.j2ee; |
2 | ||
3 | import dolda.jsvc.*; | |
104fa785 FT |
4 | import java.lang.reflect.*; |
5 | import java.util.*; | |
78f5d120 FT |
6 | import java.io.*; |
7 | import javax.servlet.http.*; | |
104fa785 | 8 | import javax.servlet.*; |
78f5d120 FT |
9 | |
10 | public class Servlet extends HttpServlet { | |
c9837b5e | 11 | private ThreadContext tg; |
104fa785 | 12 | |
4b8346e1 | 13 | public void init(ServletConfig cfg) throws ServletException { |
6a0cb6cb | 14 | J2eeContext ctx = J2eeContext.create(cfg); |
104fa785 FT |
15 | try { |
16 | InputStream pi = Servlet.class.getClassLoader().getResourceAsStream("jsvc.properties"); | |
17 | try { | |
6a0cb6cb | 18 | ctx.loadconfig(pi); |
104fa785 FT |
19 | } finally { |
20 | pi.close(); | |
21 | } | |
22 | } catch(IOException e) { | |
23 | throw(new Error(e)); | |
24 | } | |
6a0cb6cb | 25 | String clnm = ctx.libconfig("jsvc.bootstrap", null); |
104fa785 FT |
26 | if(clnm == null) |
27 | throw(new ServletException("No JSvc bootstrapper specified")); | |
c9837b5e | 28 | Class<?> bc; |
104fa785 | 29 | try { |
c9837b5e | 30 | bc = Class.forName(clnm); |
104fa785 FT |
31 | } catch(ClassNotFoundException e) { |
32 | throw(new ServletException("Invalid JSvc bootstrapper specified", e)); | |
104fa785 | 33 | } |
83f55da4 FT |
34 | String tgn; |
35 | if(ctx.name() != null) | |
36 | tgn = "JSvc service for " + ctx.name(); | |
37 | else | |
38 | tgn = "JSvc service"; | |
39 | tg = new ThreadContext(null, tgn, ctx, bc); | |
104fa785 | 40 | } |
78f5d120 | 41 | |
104fa785 | 42 | public void destroy() { |
c9837b5e | 43 | tg.shutdown(); |
78f5d120 FT |
44 | } |
45 | ||
46 | public void service(HttpServletRequest req, HttpServletResponse resp) { | |
47 | try { | |
48 | req.setCharacterEncoding("UTF-8"); | |
49 | resp.setCharacterEncoding("UTF-8"); | |
50 | } catch(UnsupportedEncodingException e) { | |
51 | throw(new Error(e)); | |
52 | } | |
53 | Request rr = new J2eeRequest(getServletConfig(), req, resp); | |
c9837b5e | 54 | RequestThread w = tg.respond(rr); |
104fa785 FT |
55 | w.start(); |
56 | try { | |
57 | w.join(); | |
58 | } catch(InterruptedException e) { | |
59 | w.interrupt(); | |
60 | return; | |
61 | } | |
78f5d120 FT |
62 | } |
63 | } |