jfarcand 2003/12/02 08:27:11 Modified: coyote/src/java/org/apache/coyote Request.java ActionCode.java catalina/src/share/org/apache/coyote/tomcat5 CoyoteRequest.java http11/src/java/org/apache/coyote/http11 Http11Processor.java Log: Implement getLocalPort using ActionCode instead of getServerPort. Associate 1 ActionCode for each getXXX method. Please review. Revision Changes Path 1.24 +11 -1 jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Request.java Index: Request.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Request.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- Request.java 7 Sep 2003 18:03:21 -0000 1.23 +++ Request.java 2 Dec 2003 16:27:11 -0000 1.24 @@ -136,6 +136,7 @@ private String localHost; private int remotePort; + private int localPort; private MessageBytes schemeMB = new MessageBytes(); @@ -303,7 +304,14 @@ public void setRemotePort(int port){ this.remotePort = port; } - + + public int getLocalPort(){ + return localPort; + } + + public void setLocalPort(int port){ + this.localPort = port; + } // -------------------- encoding/type -------------------- @@ -502,6 +510,8 @@ headers.recycle(); serverNameMB.recycle(); serverPort=-1; + localPort = -1; + remotePort = -1; cookies.recycle(); parameters.recycle(); 1.14 +17 -0 jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/ActionCode.java Index: ActionCode.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/ActionCode.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ActionCode.java 1 Oct 2003 07:50:29 -0000 1.13 +++ ActionCode.java 2 Dec 2003 16:27:11 -0000 1.14 @@ -135,7 +135,24 @@ * (including forcing a re-handshake if necessary) */ public static final ActionCode ACTION_REQ_SSL_CERTIFICATE = new ActionCode(15); + + + /** + * Callback for lazy evaluation - socket remote port. + **/ + public static final ActionCode ACTION_REQ_REMOTEPORT_ATTRIBUTE = new ActionCode(16); + + /** + * Callback for lazy evaluation - socket local port. + **/ + public static final ActionCode ACTION_REQ_LOCALPORT_ATTRIBUTE = new ActionCode(17); + + + /** + * Callback for lazy evaluation - local address. + **/ + public static final ActionCode ACTION_REQ_LOCAL_ADDR_ATTRIBUTE = new ActionCode(18); // ----------------------------------------------------------- Constructors int code; 1.24 +23 -7 jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5/CoyoteRequest.java Index: CoyoteRequest.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/coyote/tomcat5/CoyoteRequest.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- CoyoteRequest.java 20 Nov 2003 20:56:28 -0000 1.23 +++ CoyoteRequest.java 2 Dec 2003 16:27:11 -0000 1.24 @@ -366,6 +366,11 @@ /** + * Local port + */ + protected int localPort = -1; + + /** * Remote address. */ protected String remoteAddr = null; @@ -420,6 +425,7 @@ remoteAddr = null; remoteHost = null; remotePort = -1; + localPort = -1; localAddr = null; attributes.clear(); @@ -646,6 +652,7 @@ remoteHost = null; remoteAddr = null; remotePort = -1; + localPort = -1; localAddr = null; } @@ -1236,7 +1243,7 @@ remotePort = socket.getPort(); } else { coyoteRequest.action - (ActionCode.ACTION_REQ_HOST_ATTRIBUTE, coyoteRequest); + (ActionCode.ACTION_REQ_REMOTEPORT_ATTRIBUTE, coyoteRequest); remotePort = coyoteRequest.getRemotePort(); } } @@ -1262,7 +1269,7 @@ localAddr = inet.getHostAddress(); } else { coyoteRequest.action - (ActionCode.ACTION_REQ_HOST_ATTRIBUTE, coyoteRequest); + (ActionCode.ACTION_REQ_LOCAL_ADDR_ATTRIBUTE, coyoteRequest); localAddr = coyoteRequest.localAddr().toString(); } } @@ -1275,7 +1282,16 @@ * on which the request was received. */ public int getLocalPort(){ - return getServerPort(); + if (localPort == -1){ + if (socket != null) { + localPort = socket.getLocalPort(); + } else { + coyoteRequest.action + (ActionCode.ACTION_REQ_LOCALPORT_ATTRIBUTE, coyoteRequest); + localPort = coyoteRequest.getLocalPort(); + } + } + return localPort; } /** 1.91 +23 -15 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java Index: Http11Processor.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v retrieving revision 1.90 retrieving revision 1.91 diff -u -r1.90 -r1.91 --- Http11Processor.java 1 Dec 2003 23:58:53 -0000 1.90 +++ Http11Processor.java 2 Dec 2003 16:27:11 -0000 1.91 @@ -240,6 +240,11 @@ */ protected String remoteHost = null; + /** + * Remote port to which the socket is connected + */ + protected int localPort = -1; + /** * Remote port to which the socket is connected @@ -733,7 +738,8 @@ remoteHost = null; localAddr = null; remotePort = -1; - + localPort = -1; + // Setting up the I/O inputBuffer.setInputStream(input); outputBuffer.setOutputStream(output); @@ -1003,15 +1009,6 @@ request.remoteAddr().setString(remoteAddr); } else if (actionCode == ActionCode.ACTION_REQ_HOST_ATTRIBUTE) { - - if ((remoteAddr == null) && (socket !=null)) { - InetAddress inetAddr = socket.getInetAddress(); - if (inetAddr != null) { - remoteAddr = inetAddr.getHostAddress(); - } - } - request.remoteAddr().setString(remoteAddr); - if ((remoteHost == null) && (socket != null)) { InetAddress inetAddr = socket.getInetAddress(); if (inetAddr != null) { @@ -1019,17 +1016,28 @@ } } request.remoteHost().setString(remoteHost); + + } else if (actionCode == ActionCode.ACTION_REQ_LOCAL_ADDR_ATTRIBUTE) { - if (remotePort == -1) - remotePort = socket.getPort(); - - request.setRemotePort(remotePort); - if (localAddr == null) localAddr = socket.getLocalAddress().getHostAddress(); request.localAddr().setString(localAddr); + + } else if (actionCode == ActionCode.ACTION_REQ_REMOTEPORT_ATTRIBUTE) { + + if ((remotePort == -1 ) && (socket !=null)) { + remotePort = socket.getPort(); + } + request.setRemotePort(remotePort); + } else if (actionCode == ActionCode.ACTION_REQ_LOCALPORT_ATTRIBUTE) { + + if ((localPort == -1 ) && (socket !=null)) { + localPort = socket.getLocalPort(); + } + request.setLocalPort(localPort); + } else if (actionCode == ActionCode.ACTION_REQ_SSL_CERTIFICATE) { if( sslSupport != null) { /*
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]