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 req.setCharacterEncoding("UTF-8");
25 resp.setCharacterEncoding("UTF-8");
26 } catch(UnsupportedEncodingException e) {
27 throw(new AssertionError(e));
30 String host = req.getHeader("Host");
31 if((host == null) || (host.length() < 1))
32 host = req.getLocalAddr();
33 String pi = req.getPathInfo();
36 String q = req.getQueryString();
42 url = new URL(req.getScheme(), host, req.getServerPort(), req.getContextPath() + req.getServletPath() + pi + q);
43 } catch(MalformedURLException e) {
47 method = req.getMethod().toUpperCase().intern();
48 path = req.getPathInfo();
49 while((path.length() > 0) && (path.charAt(0) == '/'))
50 path = path.substring(1);
53 public Map<?, ?> props() {
61 public String method() {
65 public String path() {
69 public InputStream input() {
71 return(req.getInputStream());
72 } catch(IOException e) {
73 /* It is not obvious why this would happen, so I'll wait
74 * until I know whatever might happen to try and implement
75 * meaningful behavior. */
76 throw(new RuntimeException(e));
80 public MultiMap<String, String> inheaders() {
81 MultiMap<String, String> h = new HeaderTreeMap();
82 Enumeration ki = req.getHeaderNames();
84 while(ki.hasMoreElements()) {
85 String k = (String)ki.nextElement();
86 Enumeration vi = req.getHeaders(k);
88 while(vi.hasMoreElements()) {
89 String v = (String)vi.nextElement();
98 public MultiMap<String, String> params() {
102 protected void backflush() {
103 for(String key : outheaders().keySet()) {
104 boolean first = true;
105 for(String val : outheaders().values(key)) {
107 resp.setHeader(key, val);
110 resp.addHeader(key, val);
116 protected OutputStream realoutput() {
118 return(resp.getOutputStream());
119 } catch(IOException e) {
120 /* It is not obvious why this would happen, so I'll wait
121 * until I know whatever might happen to try and implement
122 * meaningful behavior. */
123 throw(new RuntimeException(e));