1 4 package gnu.kawa.servlet; 5 import javax.servlet.*; 6 import javax.servlet.http.*; 7 import gnu.mapping.*; 8 import gnu.xml.*; 9 import java.io.IOException ; 10 11 public abstract class KawaServlet 12 extends HttpServlet 13 { 14 public abstract void run(CallContext ctx) throws Throwable ; 15 16 public void doPost (HttpServletRequest request, 17 HttpServletResponse response) 18 throws ServletException, IOException 19 { 20 doGet(request, response); 21 } 22 23 public void doGet(HttpServletRequest request, HttpServletResponse response) 24 throws ServletException, IOException 25 { 26 CallContext ct = CallContext.getOnlyInstance(); 27 ServletCallContext ctx; 28 if (ct instanceof ServletCallContext) 29 { 30 ctx = (ServletCallContext) ct; 31 } 32 else 33 { 34 ctx = new ServletCallContext(); 35 CallContext.setInstance(ctx); 36 } 37 ctx.consumer = new ServletPrinter(response); ctx.request = request; 39 ctx.response = response; 40 ctx.servlet = this; 41 ctx.values = Values.noArgs; 42 43 62 63 ctx.consumer.beginDocument(); 64 try 65 { 66 run(ctx); 67 } 68 catch (Throwable throwable) 69 { 70 response.resetBuffer(); 72 if (throwable instanceof WrappedException) 73 { 74 Throwable cause = ((WrappedException) throwable).getCause(); 75 if (cause != null) 76 throwable = cause; 77 } 78 throw new ServletException(throwable); 79 } 80 ctx.consumer.endDocument(); 81 } 82 } 83 84 | Popular Tags |