1 package org.ibex.xt.shell;
4 import javax.servlet.*;
5 import javax.servlet.http.*;
7 import org.ibex.xt.Prevalence;
10 import org.prevayler.*;
12 public class Servlet extends HttpServlet {
13 private ServletContext cx = null;
14 private Prevayler prevayler;
17 // FIXME: destroy() counter with normal Servlet
18 public void init(ServletConfig sc) throws ServletException {
19 cx = sc.getServletContext();
20 prevayler = Prevalence.getPrevayler(cx);
21 prevalent = (JS)prevayler.prevalentSystem();
24 public void doPost(HttpServletRequest rq, HttpServletResponse rs) throws IOException {
26 try { r = (Request)new ObjectInputStream(rq.getInputStream()).readObject(); }
27 catch (ClassNotFoundException e) {
29 throw new IOException("exception receiving request, class not found");
32 JSScope scope = (JSScope)rq.getSession().getAttribute("scope");
35 scope = new JSScope(null) {
36 { super.put("prevalent", prevalent); }
38 public void put(String k, String v) throws JSExn {
39 if (k != null && k.equals("prevalent")) throw new JSExn(
40 "can not replace key prevalent");
46 throw new IOException("unexpected JSExn");
48 rq.getSession().setAttribute("scope", scope);
51 try { ret = r.process(scope); } catch (JSExn e) { ret = new Request.Response(e); }
52 new ObjectOutputStream(rs.getOutputStream()).writeObject(ret);