X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2Fj2ee%2FJ2eeRequest.java;h=a0145079f8573be0aa96d0965e42103004b9dcee;hb=ca045757135b00baa1f9161d2fb1e2e9e4f2bb5e;hp=1e7d789de80d0bbc25f9995c2cb0b06dbefa1fd1;hpb=6f1acdb2f8879097cdd8c6cedfc0d6752f2b29ef;p=jsvc.git diff --git a/src/dolda/jsvc/j2ee/J2eeRequest.java b/src/dolda/jsvc/j2ee/J2eeRequest.java index 1e7d789..a014507 100644 --- a/src/dolda/jsvc/j2ee/J2eeRequest.java +++ b/src/dolda/jsvc/j2ee/J2eeRequest.java @@ -14,16 +14,42 @@ public class J2eeRequest extends ResponseBuffer { private HttpServletResponse resp; private String method, path; private URL url; - private Map props = new HashMap(); + private MultiMap params = null; + private Map props = new HashMap(); public J2eeRequest(ServletConfig cfg, HttpServletRequest req, HttpServletResponse resp) { this.cfg = cfg; this.req = req; this.resp = resp; { + /* Ewwww, this is disgusting! */ + String scheme = req.getScheme(); + int port = -1; String host = req.getHeader("Host"); - if((host == null) || (host.length() < 1)) + if((host == null) || (host.length() < 1)) { host = req.getLocalAddr(); + port = req.getLocalPort(); + if((port == 80) && scheme.equals("http")) + port = -1; + else if((port == 443) && scheme.equals("https")) + port = -1; + } else { + int p; + if((host.charAt(0) == '[') && ((p = host.indexOf(']', 1)) > 1)) { + String newhost = host.substring(1, p); + if((p = host.indexOf(':', p + 1)) >= 0) { + try { + port = Integer.parseInt(host.substring(p + 1)); + } catch(NumberFormatException e) {} + } + host = newhost; + } else if((p = host.indexOf(':')) >= 0) { + try { + port = Integer.parseInt(host.substring(p + 1)); + host = host.substring(0, p); + } catch(NumberFormatException e) {} + } + } String pi = req.getPathInfo(); if(pi == null) pi = ""; @@ -33,7 +59,7 @@ public class J2eeRequest extends ResponseBuffer { else q = ""; try { - url = new URL(req.getScheme(), host, req.getServerPort(), req.getContextPath() + req.getServletPath() + pi + q); + url = new URL(scheme, host, port, req.getContextPath() + req.getServletPath() + pi + q); } catch(MalformedURLException e) { throw(new Error(e)); } @@ -44,7 +70,7 @@ public class J2eeRequest extends ResponseBuffer { path = path.substring(1); } - public Map props() { + public Map props() { return(props); } @@ -52,6 +78,26 @@ public class J2eeRequest extends ResponseBuffer { return(new J2eeContext(cfg, req, resp)); } + public SocketAddress remoteaddr() { + try { + return(new InetSocketAddress(InetAddress.getByName(req.getRemoteAddr()), req.getRemotePort())); + } catch(UnknownHostException e) { + /* req.getRemoteAddr should always be a valid IP address, + * so this should never happen. */ + throw(new Error(e)); + } + } + + public SocketAddress localaddr() { + try { + return(new InetSocketAddress(InetAddress.getByName(req.getLocalAddr()), req.getLocalPort())); + } catch(UnknownHostException e) { + /* req.getRemoteAddr should always be a valid IP address, + * so this should never happen. */ + throw(new Error(e)); + } + } + public URL url() { return(url); } @@ -94,10 +140,19 @@ public class J2eeRequest extends ResponseBuffer { } public MultiMap params() { - return(null); + if(params == null) { + params = Params.urlparams(this); + if(method == "POST") { + MultiMap pp = Params.postparams(this); + if(pp != null) + params.putAll(pp); + } + } + return(params); } protected void backflush() { + resp.setStatus(respcode); for(String key : outheaders().keySet()) { boolean first = true; for(String val : outheaders().values(key)) {