Allow bigger AJP packets for request bodies and
authorrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 24 Mar 2009 10:41:06 +0000 (10:41 +0000)
committerrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 24 Mar 2009 10:41:06 +0000 (10:41 +0000)
responses (by setting packetSize on the connector).

Addition to r697192 for the other AJP connectors.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@757708 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/ajp/AjpAprProcessor.java
java/org/apache/coyote/ajp/AjpAprProtocol.java
java/org/apache/coyote/ajp/AjpProcessor.java
java/org/apache/coyote/ajp/AjpProtocol.java
java/org/apache/jk/common/ChannelNioSocket.java

index 98f8799..c0ea67b 100644 (file)
@@ -86,10 +86,23 @@ public class AjpAprProcessor implements ActionHook {
         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 @@ public class AjpAprProcessor implements ActionHook {
 
 
     /**
+     * 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 @@ public class AjpAprProcessor implements ActionHook {
     /**
      * Direct buffer used for sending right away a get body message.
      */
-    protected static final ByteBuffer getBodyMessageBuffer;
+    protected final ByteBuffer getBodyMessageBuffer;
 
 
     /**
@@ -263,17 +282,6 @@ public class AjpAprProcessor implements ActionHook {
 
     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();
@@ -1284,7 +1292,8 @@ public class AjpAprProcessor implements ActionHook {
 
             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;
index 3160a77..187fad8 100644 (file)
@@ -292,7 +292,13 @@ public class AjpAprProtocol
      */
     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
index 38f92d5..3e6119a 100644 (file)
@@ -86,10 +86,22 @@ public class AjpProcessor implements ActionHook {
         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
         HexUtils.load();
 
@@ -121,6 +133,12 @@ public class AjpProcessor implements ActionHook {
 
 
     /**
+     * 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 @@ public class AjpProcessor implements ActionHook {
     /**
      * Direct buffer used for sending right away a get body message.
      */
-    protected static final byte[] getBodyMessageArray;
+    protected final byte[] getBodyMessageArray;
 
 
     /**
@@ -265,17 +283,6 @@ public class AjpProcessor implements ActionHook {
 
     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();
@@ -1223,7 +1230,8 @@ public class AjpProcessor implements ActionHook {
 
             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;
index 0d16632..6576ead 100644 (file)
@@ -291,7 +291,13 @@ public class AjpProtocol
      */
     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;
+        }
+    }
 
     
     /**
index 93c3f26..3f2205e 100644 (file)
@@ -664,7 +664,7 @@ public class ChannelNioSocket extends JkHandler
     void acceptConnections() {
         if( running ) {
             try{
-                MsgContext ep=createMsgContext();
+                MsgContext ep=createMsgContext(packetSize);
                 ep.setSource(this);
                 ep.setWorkerEnv( wEnv );
                 this.accept(ep);