Added ways to get the addresses of the request's connection.
[jsvc.git] / src / dolda / jsvc / j2ee / J2eeRequest.java
index 1e7d789..9811591 100644 (file)
@@ -52,6 +52,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);
     }