A couple of minor cleanups.
[jsvc.git] / src / dolda / jsvc / j2ee / J2eeRequest.java
index a014507..8eb8b90 100644 (file)
@@ -13,9 +13,8 @@ public class J2eeRequest extends ResponseBuffer {
     private HttpServletRequest req;
     private HttpServletResponse resp;
     private String method, path;
-    private URL url;
+    private URL url, context;
     private MultiMap<String, String> params = null;
-    private Map<Object, Object> props = new HashMap<Object, Object>();
     
     public J2eeRequest(ServletConfig cfg, HttpServletRequest req, HttpServletResponse resp) {
        this.cfg = cfg;
@@ -60,6 +59,7 @@ public class J2eeRequest extends ResponseBuffer {
                q = "";
            try {
                url = new URL(scheme, host, port, req.getContextPath() + req.getServletPath() + pi + q);
+               context = new URL(scheme, host, port, req.getContextPath());
            } catch(MalformedURLException e) {
                throw(new Error(e));
            }
@@ -70,17 +70,13 @@ public class J2eeRequest extends ResponseBuffer {
            path = path.substring(1);
     }
     
-    public Map<Object, Object> props() {
-       return(props);
-    }
-    
-    public ServerContext ctx() {
-       return(new J2eeContext(cfg, req, resp));
-    }
-    
     public SocketAddress remoteaddr() {
        try {
-           return(new InetSocketAddress(InetAddress.getByName(req.getRemoteAddr()), req.getRemotePort()));
+           /* Apparently getRemotePort returns -1 when running on Tomcat over AJP. */
+           int port = req.getRemotePort();
+           if(port < 0)
+               port = 0;
+           return(new InetSocketAddress(InetAddress.getByName(req.getRemoteAddr()), port));
        } catch(UnknownHostException e) {
            /* req.getRemoteAddr should always be a valid IP address,
             * so this should never happen. */
@@ -102,6 +98,14 @@ public class J2eeRequest extends ResponseBuffer {
        return(url);
     }
     
+    public URL rooturl() {
+       return(context);
+    }
+    
+    public ServerContext ctx() {
+       return(ThreadContext.current().server());
+    }
+    
     public String method() {
        return(method);
     }
@@ -140,14 +144,8 @@ public class J2eeRequest extends ResponseBuffer {
     }
     
     public MultiMap<String, String> params() {
-       if(params == null) {
-           params = Params.urlparams(this);
-           if(method == "POST") {
-               MultiMap<String, String> pp = Params.postparams(this);
-               if(pp != null)
-                   params.putAll(pp);
-           }
-       }
+       if(params == null)
+           params = Params.stdparams(this);
        return(params);
     }