Author: rjung
Date: Thu Jul 10 23:52:22 2014
New Revision: 1609593

URL: http://svn.apache.org/r1609593
Log:
BZ 56661: Fix Servlet API getLocalAddr().

Use new custom request attribute "AJP_LOCAL_ADDR"
forwarded by the next mod_jk 1.2.41 to set the local
IP address returned by getLocalAddr():

Before this change Tomcat handled getLocalAddr() like
getLocalName().

Needs some testing before backport.

Modified:
    tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
    tomcat/trunk/java/org/apache/coyote/ajp/Constants.java

Modified: tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java?rev=1609593&r1=1609592&r2=1609593&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java Thu Jul 
10 23:52:22 2014
@@ -486,13 +486,17 @@ public abstract class AbstractAjpProcess
             break;
         }
         case REQ_LOCAL_ADDR_ATTRIBUTE: {
-            // Copy from local name for now, which should simply be an address
-            request.localAddr().setString(request.localName().toString());
+            // Automatically populated during prepareRequest() when using
+            // modern AJP forwarder, otherwise copy from local name
+            if (request.localAddr().isNull()) {
+                request.localAddr().setString(request.localName().toString());
+            }
             break;
         }
         case REQ_REMOTEPORT_ATTRIBUTE: {
             // NO-OP
-            // This information is not available when using the AJP protocol
+            // Automatically populated during prepareRequest() when using
+            // modern AJP forwarder, otherwise not available
             break;
         }
         case REQ_LOCALPORT_ATTRIBUTE: {
@@ -1221,13 +1225,15 @@ public abstract class AbstractAjpProcess
                 requestHeaderMessage.getBytes(tmpMB);
                 String v = tmpMB.toString();
                 /*
-                 * AJP13 misses to forward the remotePort.
-                 * Allow the AJP connector to add this info via
-                 * a private request attribute.
-                 * We will accept the forwarded data as the remote port,
-                 * and remove it from the public list of request attributes.
+                 * AJP13 misses to forward the local IP address and the
+                 * remote port. Allow the AJP connector to add this info via
+                 * private request attributes.
+                 * We will accept the forwarded data and remove it from the
+                 * public list of request attributes.
                  */
-                if(n.equals(Constants.SC_A_REQ_REMOTE_PORT)) {
+                if(n.equals(Constants.SC_A_REQ_LOCAL_ADDR)) {
+                    request.localAddr().setString(v);
+                } else if(n.equals(Constants.SC_A_REQ_REMOTE_PORT)) {
                     try {
                         request.setRemotePort(Integer.parseInt(v));
                     } catch (NumberFormatException nfe) {

Modified: tomcat/trunk/java/org/apache/coyote/ajp/Constants.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/Constants.java?rev=1609593&r1=1609592&r2=1609593&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/Constants.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/Constants.java Thu Jul 10 23:52:22 
2014
@@ -81,6 +81,7 @@ public final class Constants {
     /**
      * AJP private request attributes
      */
+    public static final String SC_A_REQ_LOCAL_ADDR  = "AJP_LOCAL_ADDR";
     public static final String SC_A_REQ_REMOTE_PORT = "AJP_REMOTE_PORT";
 
     // Terminates list of attributes



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to