Author: pero
Date: Tue Dec 12 08:34:12 2006
New Revision: 486216
URL: http://svn.apache.org/viewvc?view=rev&rev=486216
Log:
Backport AJP packetSize handling from Tomcat 6.0.x
Add support to send and receive more the 8K BODY packets.
Modified:
tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java
tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProtocol.java
tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpMessage.java
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?view=diff&rev=486216&r1=486215&r2=486216
==============================================================================
--- tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java
(original)
+++ tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProcessor.java
Tue Dec 12 08:34:12 2006
@@ -75,7 +75,7 @@
// ----------------------------------------------------------- Constructors
- public AjpAprProcessor(AprEndpoint endpoint) {
+ public AjpAprProcessor(int packetSize, AprEndpoint endpoint) {
this.endpoint = endpoint;
@@ -84,9 +84,13 @@
response = new Response();
response.setHook(this);
- response.setOutputBuffer(new SocketOutputBuffer());
+ response.setOutputBuffer(new SocketOutputBuffer(packetSize));
request.setResponse(response);
+ requestHeaderMessage = new AjpMessage(packetSize);
+ responseHeaderMessage = new AjpMessage(packetSize);
+ bodyMessage = new AjpMessage(packetSize);
+
if (endpoint.getFirstReadTimeout() > 0) {
readTimeout = endpoint.getFirstReadTimeout() * 1000;
} else {
@@ -94,15 +98,27 @@
}
// Allocate input and output buffers
- inputBuffer = ByteBuffer.allocateDirect(Constants.MAX_PACKET_SIZE * 2);
+ inputBuffer = ByteBuffer.allocateDirect(packetSize * 2);
inputBuffer.limit(0);
- outputBuffer = ByteBuffer.allocateDirect(Constants.MAX_PACKET_SIZE *
2);
+ outputBuffer = ByteBuffer.allocateDirect(packetSize * 2);
// Cause loading of HexUtils
int foo = HexUtils.DEC[0];
// Cause loading of HttpMessages
HttpMessages.getMessage(200);
+
+ // Set the get body message buffer
+ AjpMessage getBodyMessage = new AjpMessage(128);
+ getBodyMessage.reset();
+ getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK);
+ getBodyMessage.appendInt(packetSize -Constants.H_SIZE - 2);
+ getBodyMessage.end();
+ getBodyMessageBuffer =
+ ByteBuffer.allocateDirect(getBodyMessage.getLen());
+ getBodyMessageBuffer.put(getBodyMessage.getBuffer(), 0,
+ getBodyMessage.getLen());
+
}
@@ -133,19 +149,19 @@
* 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.
*/
- protected AjpMessage requestHeaderMessage = new AjpMessage();
+ protected AjpMessage requestHeaderMessage ;
/**
* Message used for response header composition.
*/
- protected AjpMessage responseHeaderMessage = new AjpMessage();
+ protected AjpMessage responseHeaderMessage ;
/**
* Body message.
*/
- protected AjpMessage bodyMessage = new AjpMessage();
+ protected AjpMessage bodyMessage ;
/**
@@ -248,7 +264,7 @@
/**
* Direct buffer used for sending right away a get body message.
*/
- protected static final ByteBuffer getBodyMessageBuffer;
+ protected ByteBuffer getBodyMessageBuffer;
/**
@@ -272,19 +288,9 @@
static {
- // Set the get body message buffer
- AjpMessage getBodyMessage = new AjpMessage();
- 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();
+ AjpMessage pongMessage = new AjpMessage(128);
pongMessage.reset();
pongMessage.appendByte(Constants.JK_AJP13_CPONG_REPLY);
pongMessage.end();
@@ -293,7 +299,7 @@
pongMessage.getLen());
// Allocate the end message array
- AjpMessage endMessage = new AjpMessage();
+ AjpMessage endMessage = new AjpMessage(128);
endMessage.reset();
endMessage.appendByte(Constants.JK_AJP13_END_RESPONSE);
endMessage.appendByte(1);
@@ -303,7 +309,7 @@
endMessage.getLen());
// Set the flush message buffer
- AjpMessage flushMessage = new AjpMessage();
+ AjpMessage flushMessage = new AjpMessage(128);
flushMessage.reset();
flushMessage.appendByte(Constants.JK_AJP13_SEND_BODY_CHUNK);
flushMessage.appendInt(0);
@@ -369,8 +375,6 @@
// Error flag
error = false;
- long soTimeout = endpoint.getSoTimeout();
-
int limit = 0;
if (endpoint.getFirstReadTimeout() > 0) {
limit = endpoint.getMaxThreads() / 2;
@@ -1249,7 +1253,12 @@
protected class SocketOutputBuffer
implements OutputBuffer {
-
+ int maxSendPacketSize ;
+
+ SocketOutputBuffer(int maxSendSize) {
+ this.maxSendPacketSize = maxSendSize - Constants.H_SIZE - 4 ;
+ }
+
/**
* Write chunk.
*/
@@ -1268,7 +1277,7 @@
int len = chunk.getLength();
// 4 - hardcoded, byte[] marshalling overhead
- int chunkSize = Constants.MAX_SEND_SIZE;
+ int chunkSize = maxSendPacketSize ;
int off = 0;
while (len > 0) {
int thisTime = len;
Modified:
tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProtocol.java
URL:
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProtocol.java?view=diff&rev=486216&r1=486215&r2=486216
==============================================================================
--- tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProtocol.java
(original)
+++ tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpAprProtocol.java
Tue Dec 12 08:34:12 2006
@@ -107,6 +107,12 @@
/**
+ * AJP packet size.
+ */
+ protected int packetSize = Constants.MAX_PACKET_SIZE;
+
+
+ /**
* Adapter which will process the requests recieved by this endpoint.
*/
private Adapter adapter;
@@ -405,6 +411,19 @@
this.requiredSecret = requiredSecret;
}
+
+ public int getPacketSize() {
+ return packetSize;
+ }
+
+
+ public void setPacketSize(int packetSize) {
+ if(packetSize <Constants.MAX_PACKET_SIZE) {
+ packetSize = Constants.MAX_PACKET_SIZE;
+ }
+ this.packetSize = packetSize;
+ }
+
// -------------------------------------- AjpConnectionHandler Inner Class
@@ -424,7 +443,7 @@
try {
processor = (AjpAprProcessor) localProcessor.get();
if (processor == null) {
- processor = new AjpAprProcessor(proto.ep);
+ processor = new AjpAprProcessor(proto.packetSize,proto.ep);
processor.setAdapter(proto.adapter);
processor.setTomcatAuthentication(proto.tomcatAuthentication);
processor.setRequiredSecret(proto.requiredSecret);
Modified: tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpMessage.java
URL:
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpMessage.java?view=diff&rev=486216&r1=486215&r2=486216
==============================================================================
--- tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpMessage.java
(original)
+++ tomcat/connectors/trunk/jk/java/org/apache/coyote/ajp/AjpMessage.java Tue
Dec 12 08:34:12 2006
@@ -47,14 +47,19 @@
protected static StringManager sm =
StringManager.getManager(Constants.Package);
+ // ------------------------------------------------------------ Constructor
+ public AjpMessage(int packetSize) {
+ buf = new byte[packetSize];
+ }
+
// ----------------------------------------------------- Instance Variables
/**
* Fixed size buffer.
*/
- protected byte buf[] = new byte[8 * 1024];
+ protected byte buf[] = null ;
/**
@@ -71,7 +76,7 @@
*/
protected int len;
-
+
// --------------------------------------------------------- Public Methods
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]