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() {
55 public String method() {
59 public String path() {
63 public InputStream input() {
65 return(req.getInputStream());
66 } catch(IOException e) {
67 /* It is not obvious why this would happen, so I'll wait
68 * until I know whatever might happen to try and implement
69 * meaningful behavior. */
70 throw(new RuntimeException(e));
74 public MultiMap<String, String> inheaders() {
75 MultiMap<String, String> h = new HeaderTreeMap();
76 Enumeration ki = req.getHeaderNames();
78 while(ki.hasMoreElements()) {
79 String k = (String)ki.nextElement();
80 Enumeration vi = req.getHeaders(k);
82 while(vi.hasMoreElements()) {
83 String v = (String)vi.nextElement();
92 public MultiMap<String, String> params() {
96 protected void backflush() {
97 for(String key : outheaders().keySet()) {
99 for(String val : outheaders().values(key)) {
101 resp.setHeader(key, val);
104 resp.addHeader(key, val);
110 protected OutputStream realoutput() {
112 return(resp.getOutputStream());
113 } catch(IOException e) {
114 /* It is not obvious why this would happen, so I'll wait
115 * until I know whatever might happen to try and implement
116 * meaningful behavior. */
117 throw(new RuntimeException(e));