--- /dev/null
+package org.ibex.xt;
+
+import java.io.*;
+import java.net.*;
+import java.util.*;
+import java.util.regex.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import org.ibex.util.*;
+import org.ibex.util.Collections;
+import org.ibex.js.*;
+
+import org.prevayler.*;
+
+
+public class ShellServlet extends HttpServlet {
+ private ServletContext cx = null;
+ private Prevayler prevayler;
+ private JS prevalent;
+
+ // FIXME: destroy() counter with normal Servlet
+ public void init(ServletConfig sc) throws ServletException {
+ cx = sc.getServletContext();
+ prevayler = Prevalence.getPrevayler(cx);
+ prevalent = (JS)prevayler.prevalentSystem();
+ }
+
+ public void doPost(HttpServletRequest rq, HttpServletResponse rs) throws IOException {
+ Shell.Request r;
+ try { r = (Shell.Request)new ObjectInputStream(rq.getInputStream()).readObject(); }
+ catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ throw new IOException("exception receiving request, class not found");
+ }
+
+ JSScope scope = (JSScope)rq.getSession().getAttribute("scope");
+ if (scope == null) {
+ System.out.println("creating new scope");
+ try {
+ scope = new JSScope(null);
+ scope.put("prevalent", prevalent);
+ } catch (JSExn e) {
+ e.printStackTrace();
+ throw new IOException("unexpected JSExn");
+ }
+ rq.getSession().setAttribute("scope", scope);
+ }
+ Object ret;
+ try { ret = r.process(scope); } catch (JSExn e) { ret = e; }
+ new ObjectOutputStream(rs.getOutputStream()).writeObject(ret);
+ }
+}