1 package dolda.jsvc.j2ee;
4 import dolda.jsvc.util.*;
8 import javax.servlet.*;
9 import javax.servlet.http.*;
11 public class J2eeRequest extends ResponseBuffer {
12 private ServletConfig cfg;
13 private HttpServletRequest req;
14 private HttpServletResponse resp;
15 private String method, path;
17 private Map<?, ?> props = new HashMap();
19 public J2eeRequest(ServletConfig cfg, HttpServletRequest req, HttpServletResponse resp) {
24 String host = req.getHeader("Host");
25 if((host == null) || (host.length() < 1))
26 host = req.getLocalAddr();
27 String pi = req.getPathInfo();
30 String q = req.getQueryString();
36 url = new URL(req.getScheme(), host, req.getServerPort(), req.getContextPath() + req.getServletPath() + pi + q);
37 } catch(MalformedURLException e) {
41 method = req.getMethod().toUpperCase().intern();
42 path = req.getPathInfo();
43 while((path.length() > 0) && (path.charAt(0) == '/'))
44 path = path.substring(1);
47 public Map<?, ?> props() {
51 public ServerContext ctx() {
52 return(new J2eeContext(cfg, req, resp));
59 public String method() {
63 public String path() {
67 public InputStream input() {
69 return(req.getInputStream());
70 } catch(IOException e) {
71 /* It is not obvious why this would happen, so I'll wait
72 * until I know whatever might happen to try and implement
73 * meaningful behavior. */
74 throw(new RuntimeException(e));
78 public MultiMap<String, String> inheaders() {
79 MultiMap<String, String> h = new HeaderTreeMap();
80 Enumeration ki = req.getHeaderNames();
82 while(ki.hasMoreElements()) {
83 String k = (String)ki.nextElement();
84 Enumeration vi = req.getHeaders(k);
86 while(vi.hasMoreElements()) {
87 String v = (String)vi.nextElement();
96 public MultiMap<String, String> params() {
100 protected void backflush() {
101 for(String key : outheaders().keySet()) {
102 boolean first = true;
103 for(String val : outheaders().values(key)) {
105 resp.setHeader(key, val);
108 resp.addHeader(key, val);
114 protected OutputStream realoutput() {
116 return(resp.getOutputStream());
117 } catch(IOException e) {
118 /* It is not obvious why this would happen, so I'll wait
119 * until I know whatever might happen to try and implement
120 * meaningful behavior. */
121 throw(new RuntimeException(e));