X-Git-Url: http://git.megacz.com/?p=org.ibex.xt-crawshaw.git;a=blobdiff_plain;f=src%2Fjava%2Forg%2Fibex%2Fxt%2FShellServlet.java;fp=src%2Fjava%2Forg%2Fibex%2Fxt%2FShellServlet.java;h=bc53366805a3750310783b8d23bf15fe1d89f7f1;hp=0000000000000000000000000000000000000000;hb=934297f510d5d8c584a83635f328273a6cfd7000;hpb=d55d42a0b70f398fd424010ca2cb6301016c4449 diff --git a/src/java/org/ibex/xt/ShellServlet.java b/src/java/org/ibex/xt/ShellServlet.java new file mode 100644 index 0000000..bc53366 --- /dev/null +++ b/src/java/org/ibex/xt/ShellServlet.java @@ -0,0 +1,53 @@ +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); + } +}