From: rjung Date: Tue, 24 Mar 2009 10:41:06 +0000 (+0000) Subject: Allow bigger AJP packets for request bodies and X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=935c4fe8bc58ef90865a1dd8a9cf52d9d3c2d67d;p=tomcat7.0 Allow bigger AJP packets for request bodies and 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 --- diff --git a/java/org/apache/coyote/ajp/AjpAprProcessor.java b/java/org/apache/coyote/ajp/AjpAprProcessor.java index 98f8799fc..c0ea67b78 100644 --- a/java/org/apache/coyote/ajp/AjpAprProcessor.java +++ b/java/org/apache/coyote/ajp/AjpAprProcessor.java @@ -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; diff --git a/java/org/apache/coyote/ajp/AjpAprProtocol.java b/java/org/apache/coyote/ajp/AjpAprProtocol.java index 3160a773d..187fad81b 100644 --- a/java/org/apache/coyote/ajp/AjpAprProtocol.java +++ b/java/org/apache/coyote/ajp/AjpAprProtocol.java @@ -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 diff --git a/java/org/apache/coyote/ajp/AjpProcessor.java b/java/org/apache/coyote/ajp/AjpProcessor.java index 38f92d520..3e6119ac8 100644 --- a/java/org/apache/coyote/ajp/AjpProcessor.java +++ b/java/org/apache/coyote/ajp/AjpProcessor.java @@ -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; diff --git a/java/org/apache/coyote/ajp/AjpProtocol.java b/java/org/apache/coyote/ajp/AjpProtocol.java index 0d1663251..6576ead2c 100644 --- a/java/org/apache/coyote/ajp/AjpProtocol.java +++ b/java/org/apache/coyote/ajp/AjpProtocol.java @@ -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; + } + } /** diff --git a/java/org/apache/jk/common/ChannelNioSocket.java b/java/org/apache/jk/common/ChannelNioSocket.java index 93c3f2638..3f2205efd 100644 --- a/java/org/apache/jk/common/ChannelNioSocket.java +++ b/java/org/apache/jk/common/ChannelNioSocket.java @@ -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);