Added a general-purpose root error handler.
[jsvc.git] / src / dolda / jsvc / test / TestResponder.java
1 package dolda.jsvc.test;
2
3 import dolda.jsvc.*;
4 import java.io.*;
5
6 public class TestResponder implements Responder {
7     public void respond(Request req) {
8         req.outheaders().put("Content-Type", "text/html; charset=utf-8");
9         PrintWriter out;
10         try {
11             out = new PrintWriter(new OutputStreamWriter(req.output(), "UTF-8"));
12         } catch(UnsupportedEncodingException e) {
13             throw(new Error(e));
14         }
15
16         if(req.path().equals("bard1"))
17             throw(new RuntimeException("bard1"));
18
19         out.println("<html>");
20         out.println("<head><title>Barda</title></head>");
21         out.println("<body>");
22         out.println("<h1>Barda</h1>");
23         out.println("Bardslen.");
24         out.println(req.inheaders());
25         out.println(req.ctx().starttime());
26         out.println(req.remoteaddr() + "<->" + req.localaddr());
27         out.println("</body>");
28         out.println("</html>");
29
30         if(req.path().equals("bard2"))
31             throw(new RuntimeException("bard2"));
32         out.flush();
33     }
34 }