You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2009/04/06 23:10:06 UTC

svn commit: r762507 - in /tomcat/tc6.0.x/trunk: ./ java/org/apache/coyote/ajp/ java/org/apache/jk/common/ webapps/docs/

Author: rjung
Date: Mon Apr  6 21:10:05 2009
New Revision: 762507

URL: http://svn.apache.org/viewvc?rev=762507&view=rev
Log:
Allow huge request body packets for AJP13.
Backport of r697192 and r757708.

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/AjpAprProtocol.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProtocol.java
    tomcat/tc6.0.x/trunk/java/org/apache/jk/common/ChannelNioSocket.java
    tomcat/tc6.0.x/trunk/java/org/apache/jk/common/JkInputStream.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=762507&r1=762506&r2=762507&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Mon Apr  6 21:10:05 2009
@@ -38,14 +38,6 @@
    0: remm (looks risky, very minor problem), fhanik - minor problem
   -1: 
 
-* Allow huge request body packets for AJP13.
-  This was already applied to connectors, but never
-  carried forward to trunk and tc6.0.x.
-  http://svn.apache.org/viewvc?rev=697192&view=rev
-  Original change: http://svn.apache.org/viewvc?rev=486217&view=rev
-  +1: rjung, mturk, markt, pero, jim
-   0: remm (also affects to the two other AJP connectors)
-
 * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45403
   See commit message for details of negligable performance impact
   http://svn.apache.org/viewvc?rev=701358&view=rev
@@ -80,13 +72,6 @@
   +1: markt, rjung
   -1: 
 
-* Allow huge request body packets for AJP13.
-  Part 2 of the backport proposed and approved above
-  (r697192), now also for the other AJP connectors.
-  http://svn.apache.org/viewvc?rev=757708&view=rev
-  +1: rjung, markt, remm
-  -1:
-
 * Backport cleanup of semantics of thisAccessedTime and
   lastAccessedTime for sessions:
   - preparational whitespace changes

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=762507&r1=762506&r2=762507&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 Mon Apr  6 21:10:05 2009
@@ -86,10 +86,23 @@
         response.setOutputBuffer(new SocketOutputBuffer());
         request.setResponse(response);
 
+        this.packetSize = packetSize;
         requestHeaderMessage = new AjpMessage(packetSize);
         responseHeaderMessage = new AjpMessage(packetSize);
         bodyMessage = new AjpMessage(packetSize);
-        
+
+        // Set the get body message buffer
+        AjpMessage getBodyMessage = new AjpMessage(16);
+        getBodyMessage.reset();
+        getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK);
+        // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE)
+        getBodyMessage.appendInt(Constants.MAX_READ_SIZE + packetSize - Constants.MAX_PACKET_SIZE);
+        getBodyMessage.end();
+        getBodyMessageBuffer =
+            ByteBuffer.allocateDirect(getBodyMessage.getLen());
+        getBodyMessageBuffer.put(getBodyMessage.getBuffer(), 0,
+                                 getBodyMessage.getLen());
+
         // Allocate input and output buffers
         inputBuffer = ByteBuffer.allocateDirect(packetSize * 2);
         inputBuffer.limit(0);
@@ -126,6 +139,12 @@
 
 
     /**
+     * The socket timeout used when reading the first block of the request
+     * header.
+     */
+    protected int packetSize;
+
+    /**
      * Header message. Note that this header is merely the one used during the
      * processing of the first message of a "request", so it might not be a request
      * header. It will stay unchanged during the processing of the whole request.
@@ -238,7 +257,7 @@
     /**
      * Direct buffer used for sending right away a get body message.
      */
-    protected static final ByteBuffer getBodyMessageBuffer;
+    protected final ByteBuffer getBodyMessageBuffer;
 
 
     /**
@@ -263,17 +282,6 @@
 
     static {
 
-        // Set the get body message buffer
-        AjpMessage getBodyMessage = new AjpMessage(16);
-        getBodyMessage.reset();
-        getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK);
-        getBodyMessage.appendInt(Constants.MAX_READ_SIZE);
-        getBodyMessage.end();
-        getBodyMessageBuffer =
-            ByteBuffer.allocateDirect(getBodyMessage.getLen());
-        getBodyMessageBuffer.put(getBodyMessage.getBuffer(), 0,
-                getBodyMessage.getLen());
-
         // Set the read body message buffer
         AjpMessage pongMessage = new AjpMessage(16);
         pongMessage.reset();
@@ -1280,7 +1288,8 @@
 
             int len = chunk.getLength();
             // 4 - hardcoded, byte[] marshalling overhead
-            int chunkSize = Constants.MAX_SEND_SIZE;
+            // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE)
+            int chunkSize = Constants.MAX_SEND_SIZE + packetSize - Constants.MAX_PACKET_SIZE;
             int off = 0;
             while (len > 0) {
                 int thisTime = len;

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java?rev=762507&r1=762506&r2=762507&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProtocol.java Mon Apr  6 21:10:05 2009
@@ -291,7 +291,13 @@
      */
     protected int packetSize = Constants.MAX_PACKET_SIZE;
     public int getPacketSize() { return packetSize; }
-    public void setPacketSize(int packetSize) { this.packetSize = packetSize; }
+    public void setPacketSize(int packetSize) {
+        if(packetSize < Constants.MAX_PACKET_SIZE) {
+            this.packetSize = Constants.MAX_PACKET_SIZE;
+        } else {
+            this.packetSize = packetSize;
+        }
+    }
 
     /**
      * The number of seconds Tomcat will wait for a subsequent request

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=762507&r1=762506&r2=762507&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 Mon Apr  6 21:10:05 2009
@@ -86,10 +86,22 @@
         response.setOutputBuffer(new SocketOutputBuffer());
         request.setResponse(response);
 
+        this.packetSize = packetSize;
         requestHeaderMessage = new AjpMessage(packetSize);
         responseHeaderMessage = new AjpMessage(packetSize);
         bodyMessage = new AjpMessage(packetSize);
-        
+
+        // Set the get body message buffer
+        AjpMessage getBodyMessage = new AjpMessage(16);
+        getBodyMessage.reset();
+        getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK);
+        // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE)
+        getBodyMessage.appendInt(Constants.MAX_READ_SIZE + packetSize - Constants.MAX_PACKET_SIZE);
+        getBodyMessage.end();
+        getBodyMessageArray = new byte[getBodyMessage.getLen()];
+        System.arraycopy(getBodyMessage.getBuffer(), 0, getBodyMessageArray, 
+                         0, getBodyMessage.getLen());
+
         // Cause loading of HexUtils
         int foo = HexUtils.DEC[0];
 
@@ -121,6 +133,12 @@
 
 
     /**
+     * The socket timeout used when reading the first block of the request
+     * header.
+     */
+    protected int packetSize;
+
+    /**
      * Header message. Note that this header is merely the one used during the
      * processing of the first message of a "request", so it might not be a request
      * header. It will stay unchanged during the processing of the whole request.
@@ -240,7 +258,7 @@
     /**
      * Direct buffer used for sending right away a get body message.
      */
-    protected static final byte[] getBodyMessageArray;
+    protected final byte[] getBodyMessageArray;
 
 
     /**
@@ -265,17 +283,6 @@
 
     static {
 
-        // Set the get body message buffer
-
-        AjpMessage getBodyMessage = new AjpMessage(16);
-        getBodyMessage.reset();
-        getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK);
-        getBodyMessage.appendInt(Constants.MAX_READ_SIZE);
-        getBodyMessage.end();
-        getBodyMessageArray = new byte[getBodyMessage.getLen()];
-        System.arraycopy(getBodyMessage.getBuffer(), 0, getBodyMessageArray, 
-                0, getBodyMessage.getLen());
-
         // Set the read body message buffer
         AjpMessage pongMessage = new AjpMessage(16);
         pongMessage.reset();
@@ -1218,7 +1225,8 @@
 
             int len = chunk.getLength();
             // 4 - hardcoded, byte[] marshalling overhead
-            int chunkSize = Constants.MAX_SEND_SIZE;
+            // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE)
+            int chunkSize = Constants.MAX_SEND_SIZE + packetSize - Constants.MAX_PACKET_SIZE;
             int off = 0;
             while (len > 0) {
                 int thisTime = len;

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProtocol.java?rev=762507&r1=762506&r2=762507&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProtocol.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProtocol.java Mon Apr  6 21:10:05 2009
@@ -290,7 +290,13 @@
      */
     protected int packetSize = Constants.MAX_PACKET_SIZE;
     public int getPacketSize() { return packetSize; }
-    public void setPacketSize(int packetSize) { this.packetSize = packetSize; }
+    public void setPacketSize(int packetSize) {
+        if(packetSize < Constants.MAX_PACKET_SIZE) {
+            this.packetSize = Constants.MAX_PACKET_SIZE;
+        } else {
+            this.packetSize = packetSize;
+        }
+    }
 
     
     /**

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jk/common/ChannelNioSocket.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jk/common/ChannelNioSocket.java?rev=762507&r1=762506&r2=762507&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jk/common/ChannelNioSocket.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jk/common/ChannelNioSocket.java Mon Apr  6 21:10:05 2009
@@ -664,7 +664,7 @@
     void acceptConnections() {
         if( running ) {
             try{
-                MsgContext ep=createMsgContext();
+                MsgContext ep=createMsgContext(packetSize);
                 ep.setSource(this);
                 ep.setWorkerEnv( wEnv );
                 this.accept(ep);

Modified: tomcat/tc6.0.x/trunk/java/org/apache/jk/common/JkInputStream.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/jk/common/JkInputStream.java?rev=762507&r1=762506&r2=762507&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/jk/common/JkInputStream.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/jk/common/JkInputStream.java Mon Apr  6 21:10:05 2009
@@ -52,6 +52,7 @@
     private boolean isFirst = true;
     private boolean isReplay = false;
     private boolean isReadRequired = false;
+    private int packetSize = AjpConstants.MAX_PACKET_SIZE;
 
     static {
         // Make certain HttpMessages is loaded for SecurityManager
@@ -64,14 +65,19 @@
 
     public JkInputStream(MsgContext context, int bsize) {
         mc = context;
-        bodyMsg = new MsgAjp(bsize);
-        outputMsg = new MsgAjp(bsize);
+        // Never use less than the default maximum packet size.
+        if (bsize < AjpConstants.MAX_PACKET_SIZE)
+            this.packetSize = AjpConstants.MAX_PACKET_SIZE;
+        else
+            this.packetSize = bsize;
+        bodyMsg = new MsgAjp(this.packetSize);
+        outputMsg = new MsgAjp(this.packetSize);
     }
     /**
      * @deprecated
      */
     public JkInputStream(MsgContext context) {
-        this(context, 8*1024);
+        this(context, AjpConstants.MAX_PACKET_SIZE);
     }
 
     // -------------------- Jk specific methods --------------------
@@ -244,7 +250,8 @@
         // Why not use outBuf??
         bodyMsg.reset();
         bodyMsg.appendByte(AjpConstants.JK_AJP13_GET_BODY_CHUNK);
-        bodyMsg.appendInt(AjpConstants.MAX_READ_SIZE);
+        // Adjust allowed size if packetSize != default (AjpConstants.MAX_PACKET_SIZE)
+        bodyMsg.appendInt(AjpConstants.MAX_READ_SIZE + packetSize - AjpConstants.MAX_PACKET_SIZE);
         
         if( log.isDebugEnabled() )
             log.debug("refillReadBuffer " + Thread.currentThread());

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=762507&r1=762506&r2=762507&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Mon Apr  6 21:10:05 2009
@@ -43,6 +43,9 @@
   </subsection>
   <subsection name="Coyote">
     <changelog>
+      <update>
+        Allow huge request body packets for AJP13. (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)



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