Author: markt Date: Tue Jul 29 09:38:57 2014 New Revision: 1614294 URL: http://svn.apache.org/r1614294 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56661 Support using AJP request attribute AJP_LOCAL_ADDR to fix getLocalAddr(). Backport of r1609593 from trunk resp. r1609606 from tc7.
Modified: tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java tomcat/tc6.0.x/trunk/java/org/apache/jk/common/AjpConstants.java tomcat/tc6.0.x/trunk/java/org/apache/jk/common/HandlerRequest.java tomcat/tc6.0.x/trunk/java/org/apache/jk/core/MsgContext.java tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Modified: tomcat/tc6.0.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1614294&r1=1614293&r2=1614294&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Tue Jul 29 09:38:57 2014 @@ -51,13 +51,6 @@ PATCHES PROPOSED TO BACKPORT: +1: kkolinko -1: -* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56661 - Support using AJP request attribute AJP_LOCAL_ADDR to fix getLocalAddr(). - Backport of r1609593 from trunk resp. r1609606 from tc7. - http://people.apache.org/~rjung/patches/getLocalAddr-tc6.patch - +1: rjung, kkolinko, schultz - -1: - PATCHES/ISSUES THAT ARE STALLED: Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java?rev=1614294&r1=1614293&r2=1614294&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java Tue Jul 29 09:38:57 2014 @@ -620,8 +620,11 @@ public class AjpAprProcessor implements } else if (actionCode == ActionCode.ACTION_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()); + } } else if (actionCode == ActionCode.ACTION_REQ_SET_BODY_REPLAY) { @@ -767,13 +770,15 @@ public class AjpAprProcessor implements 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/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java?rev=1614294&r1=1614293&r2=1614294&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java Tue Jul 29 09:38:57 2014 @@ -625,8 +625,11 @@ public class AjpProcessor implements Act } else if (actionCode == ActionCode.ACTION_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()); + } } else if (actionCode == ActionCode.ACTION_REQ_SET_BODY_REPLAY) { @@ -772,13 +775,15 @@ public class AjpProcessor implements Act 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/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java?rev=1614294&r1=1614293&r2=1614294&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java Tue Jul 29 09:38:57 2014 @@ -91,6 +91,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/tc6.0.x/trunk/java/org/apache/jk/common/AjpConstants.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jk/common/AjpConstants.java?rev=1614294&r1=1614293&r2=1614294&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jk/common/AjpConstants.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jk/common/AjpConstants.java Tue Jul 29 09:38:57 2014 @@ -99,6 +99,7 @@ public class AjpConstants { /** * 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"; /** Modified: tomcat/tc6.0.x/trunk/java/org/apache/jk/common/HandlerRequest.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jk/common/HandlerRequest.java?rev=1614294&r1=1614293&r2=1614294&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jk/common/HandlerRequest.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jk/common/HandlerRequest.java Tue Jul 29 09:38:57 2014 @@ -476,13 +476,15 @@ public class HandlerRequest extends JkHa msg.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(AjpConstants.SC_A_REQ_REMOTE_PORT)) { + if(n.equals(AjpConstants.SC_A_REQ_LOCAL_ADDR)) { + req.localAddr().setString(v); + } else if(n.equals(AjpConstants.SC_A_REQ_REMOTE_PORT)) { try { req.setRemotePort(Integer.parseInt(v)); } catch (NumberFormatException nfe) { Modified: tomcat/tc6.0.x/trunk/java/org/apache/jk/core/MsgContext.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jk/core/MsgContext.java?rev=1614294&r1=1614293&r2=1614294&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/jk/core/MsgContext.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/jk/core/MsgContext.java Tue Jul 29 09:38:57 2014 @@ -378,9 +378,12 @@ public class MsgContext implements Actio req.setContentLength(bc.getLength()); jkIS.setReplay(bc); } else if (actionCode == ActionCode.ACTION_REQ_LOCAL_ADDR_ATTRIBUTE) { - // Copy from local name for now, which should simply be an address Request req=(Request)param; - req.localAddr().setString(req.localName().toString()); + // Automatically populated during prepareRequest() when using + // modern AJP forwarder, otherwise copy from local name + if (req.localAddr().isNull()) { + req.localAddr().setString(req.localName().toString()); + } } } Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1614294&r1=1614293&r2=1614294&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Tue Jul 29 09:38:57 2014 @@ -69,6 +69,10 @@ error messages and adding an error flag to allow subsequent attempts at reading after an error to fail fast. (markt) </fix> + <fix> + <bug>56661</bug>: Support using AJP request attribute + <code>AJP_LOCAL_ADDR</code> to fix <code>getLocalAddr()</code>. (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