Author: rjung
Date: Mon Apr  6 21:55:11 2009
New Revision: 762524

URL: http://svn.apache.org/viewvc?rev=762524&view=rev
Log:
Allow AJP connectors to provide correct getRemotePort().
The remote port is not part of the AJP13 protocol.
Since the protocol is not extensible enough for standard
attributes, we use generic attributes mechanism to forward
the remote port as AJP_REMOTE_PORT.
Backport of r756926 and r757223.

Modified:
    tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java
    tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/Constants.java
    tomcat/connectors/trunk/jk/java/org/apache/jk/common/AjpConstants.java
    tomcat/connectors/trunk/jk/java/org/apache/jk/common/HandlerRequest.java
    tomcat/container/tc5.5.x/webapps/docs/changelog.xml
    tomcat/current/tc5.5.x/STATUS.txt

Modified: 
tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java?rev=762524&r1=762523&r2=762524&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java 
(original)
+++ tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java 
Mon Apr  6 21:55:11 2009
@@ -731,7 +731,21 @@
                 String n = tmpMB.toString();
                 requestHeaderMessage.getBytes(tmpMB);
                 String v = tmpMB.toString();
-                request.setAttribute(n, v);
+                /*
+                 * 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.
+                 */
+                if(n.equals(Constants.SC_A_REQ_REMOTE_PORT)) {
+                    try {
+                        request.setRemotePort(Integer.parseInt(v));
+                    } catch (NumberFormatException nfe) {
+                    }
+                } else {
+                    request.setAttribute(n, v);
+                }
                 break;
 
             case Constants.SC_A_CONTEXT :

Modified: tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/Constants.java
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/Constants.java?rev=762524&r1=762523&r2=762524&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/Constants.java 
(original)
+++ tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/Constants.java Mon 
Apr  6 21:55:11 2009
@@ -85,6 +85,11 @@
     // Used for attributes which are not in the list above
     public static final byte SC_A_REQ_ATTRIBUTE = 10;
 
+    /**
+     * AJP private request attributes
+     */
+    public static final String SC_A_REQ_REMOTE_PORT = "AJP_REMOTE_PORT";
+
     // Terminates list of attributes
     public static final byte SC_A_ARE_DONE      = (byte)0xFF;
 

Modified: tomcat/connectors/trunk/jk/java/org/apache/jk/common/AjpConstants.java
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/java/org/apache/jk/common/AjpConstants.java?rev=762524&r1=762523&r2=762524&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/java/org/apache/jk/common/AjpConstants.java 
(original)
+++ tomcat/connectors/trunk/jk/java/org/apache/jk/common/AjpConstants.java Mon 
Apr  6 21:55:11 2009
@@ -97,6 +97,11 @@
     public static final byte SC_A_REQ_ATTRIBUTE = 10; 
 
     /**
+     * AJP private request attributes
+     */
+    public static final String SC_A_REQ_REMOTE_PORT = "AJP_REMOTE_PORT";
+
+    /**
      * Terminates list of attributes
      */
     public static final byte SC_A_ARE_DONE      = (byte)0xFF;

Modified: 
tomcat/connectors/trunk/jk/java/org/apache/jk/common/HandlerRequest.java
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/java/org/apache/jk/common/HandlerRequest.java?rev=762524&r1=762523&r2=762524&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/java/org/apache/jk/common/HandlerRequest.java 
(original)
+++ tomcat/connectors/trunk/jk/java/org/apache/jk/common/HandlerRequest.java 
Mon Apr  6 21:55:11 2009
@@ -447,9 +447,23 @@
                 String n=tmpMB.toString();
                 msg.getBytes( tmpMB );
                 String v=tmpMB.toString();
-                req.setAttribute(n, v );
-                if(log.isTraceEnabled())
-                    log.trace("jk Attribute set " + n + "=" + v);
+                /*
+                 * 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.
+                 */
+                if(n.equals(AjpConstants.SC_A_REQ_REMOTE_PORT)) {
+                    try {
+                        req.setRemotePort(Integer.parseInt(v));
+                    } catch (NumberFormatException nfe) {
+                    }
+                } else {
+                    req.setAttribute(n, v );
+                    if(log.isTraceEnabled())
+                        log.trace("jk Attribute set " + n + "=" + v);
+                }
             }
 
 

Modified: tomcat/container/tc5.5.x/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/webapps/docs/changelog.xml?rev=762524&r1=762523&r2=762524&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/webapps/docs/changelog.xml (original)
+++ tomcat/container/tc5.5.x/webapps/docs/changelog.xml Mon Apr  6 21:55:11 2009
@@ -86,6 +86,10 @@
   </subsection>
   <subsection name="Coyote" >
     <changelog>
+      <update>
+        Set remote port for AJP connectors from the optional request
+        attribute AJP_REMOTE_PORT. (rjung)
+      </update>
       <fix>
         <bug>45026</bug>: Never return an empty HTTP status reason phrase.
         mod_jk and httpd 2.x do not like that. (rjung)

Modified: tomcat/current/tc5.5.x/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/current/tc5.5.x/STATUS.txt?rev=762524&r1=762523&r2=762524&view=diff
==============================================================================
--- tomcat/current/tc5.5.x/STATUS.txt (original)
+++ tomcat/current/tc5.5.x/STATUS.txt Mon Apr  6 21:55:11 2009
@@ -157,16 +157,6 @@
   +1: rjung, markt
   -1:
 
-* Allow AJP connectors to provide correct getRemotePort().
-  The remote port is not part of the AJP13 protocol.
-  Since the protocol is not extensible enough for standard
-  attributes, we use generic attributes mechanism to forward
-  the remote port.
-  Backport of http://svn.apache.org/viewvc?rev=756926&view=rev
-  and http://svn.apache.org/viewvc?rev=757223&view=rev
-  +1: rjung, markt, pero
-  -1:
-
 * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=41606
   Prevent double init() of JSP
   Patch provided by Chris Halstead



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

Reply via email to