Author: rjung
Date: Fri Jul 11 01:43:33 2014
New Revision: 1609606

URL: http://svn.apache.org/r1609606
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().

Backport of r1609593 from trunk.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
    tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/Constants.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1609593

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java?rev=1609606&r1=1609605&r2=1609606&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java 
Fri Jul 11 01:43:33 2014
@@ -423,8 +423,11 @@ 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_SET_BODY_REPLAY: {
@@ -791,13 +794,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/tc7.0.x/trunk/java/org/apache/coyote/ajp/Constants.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/Constants.java?rev=1609606&r1=1609605&r2=1609606&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/Constants.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/ajp/Constants.java Fri Jul 11 
01:43:33 2014
@@ -104,6 +104,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

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1609606&r1=1609605&r2=1609606&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Fri Jul 11 01:43:33 2014
@@ -208,6 +208,11 @@
         Allow to configure <code>maxSwallowSize</code> attribute of an HTTP
         connector via JMX. (kkolinko)
       </update>
+      <fix>
+        <bug>56661</bug>: Fix <code>getLocalAddr()</code> for AJP connectors.
+        The complete fix is only available with a recent AJP forwarder like
+        the forthcoming mod_jk 1.2.41. (rjung)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">



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

Reply via email to