894bbbffd89e6e953caab7ad18824eb91972f9a4
[jrw.git] / src / jrw / Dispatch.java
1 package jrw;
2
3 import java.util.*;
4 import java.io.*;
5 import jrw.resp.*;
6
7 public class Dispatch {
8     public static Map<Object, Object> handle(Handler handler, Request req) {
9         try(Environment.Frame f = new Environment().frame()) {
10             while(true) {
11                 try {
12                     return(handler.handle(req));
13                 } catch(Restart r) {
14                     handler = r;
15                 } catch(Throwable t) {
16                     t.printStackTrace((PrintStream)req.env.get("jagi.errors"));
17                     handler = new jrw.resp.HttpError(500);
18                 }
19             }
20         }
21     }
22 }