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));
55 public SocketAddress remoteaddr() {
57 return(new InetSocketAddress(InetAddress.getByName(req.getRemoteAddr()), req.getRemotePort()));
58 } catch(UnknownHostException e) {
59 /* req.getRemoteAddr should always be a valid IP address,
60 * so this should never happen. */
65 public SocketAddress localaddr() {
67 return(new InetSocketAddress(InetAddress.getByName(req.getLocalAddr()), req.getLocalPort()));
68 } catch(UnknownHostException e) {
69 /* req.getRemoteAddr should always be a valid IP address,
70 * so this should never happen. */
79 public String method() {
83 public String path() {
87 public InputStream input() {
89 return(req.getInputStream());
90 } catch(IOException e) {
91 /* It is not obvious why this would happen, so I'll wait
92 * until I know whatever might happen to try and implement
93 * meaningful behavior. */
94 throw(new RuntimeException(e));
98 public MultiMap<String, String> inheaders() {
99 MultiMap<String, String> h = new HeaderTreeMap();
100 Enumeration ki = req.getHeaderNames();
102 while(ki.hasMoreElements()) {
103 String k = (String)ki.nextElement();
104 Enumeration vi = req.getHeaders(k);
106 while(vi.hasMoreElements()) {
107 String v = (String)vi.nextElement();
116 public MultiMap<String, String> params() {
120 protected void backflush() {
121 for(String key : outheaders().keySet()) {
122 boolean first = true;
123 for(String val : outheaders().values(key)) {
125 resp.setHeader(key, val);
128 resp.addHeader(key, val);
134 protected OutputStream realoutput() {
136 return(resp.getOutputStream());
137 } catch(IOException e) {
138 /* It is not obvious why this would happen, so I'll wait
139 * until I know whatever might happen to try and implement
140 * meaningful behavior. */
141 throw(new RuntimeException(e));