Ensure AjpMessage header is correct for the direction in which the message is being...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 22 Aug 2011 17:55:14 +0000 (17:55 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 22 Aug 2011 17:55:14 +0000 (17:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1160347 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/ajp/AjpAprProcessor.java
java/org/apache/coyote/ajp/AjpMessage.java
java/org/apache/coyote/ajp/AjpNioProcessor.java
java/org/apache/coyote/ajp/AjpProcessor.java
test/org/apache/coyote/ajp/SimpleAjpClient.java
test/org/apache/coyote/ajp/TestAbstractAjpProcessor.java
test/org/apache/coyote/ajp/TesterAjpMessage.java

index 6efd594..11c03c8 100644 (file)
@@ -463,7 +463,7 @@ public class AjpAprProcessor extends AbstractAjpProcessor<Long> {
             read(headerLength);
         }
         inputBuffer.get(message.getBuffer(), 0, headerLength);
-        int messageLength = message.processHeader();
+        int messageLength = message.processHeader(true);
         if (messageLength < 0) {
             // Invalid AJP header signature
             // TODO: Throw some exception and close the connection to frontend.
index 491e280..b71cbc6 100644 (file)
@@ -348,13 +348,18 @@ public class AjpMessage {
         return buf.length;
     }
     
-    
+    @Deprecated
     public int processHeader() {
+        return processHeader(true);
+    }
+    
+    public int processHeader(boolean toContainer) {
         pos = 0;
         int mark = getInt();
         len = getInt();
         // Verify message signature
-        if ((mark != 0x1234) && (mark != 0x4142)) {
+        if ((toContainer && mark != 0x1234) ||
+                (!toContainer && mark != 0x4142)) {
             log.error(sm.getString("ajpmessage.invalid", "" + mark));
             if (log.isDebugEnabled()) {
                 dump("In: ");
index a964a20..152a26c 100644 (file)
@@ -465,7 +465,7 @@ public class AjpNioProcessor extends AbstractAjpProcessor<NioChannel> {
             return 0;
         }
         
-        int messageLength = message.processHeader();
+        int messageLength = message.processHeader(true);
         if (messageLength < 0) {
             // Invalid AJP header signature
             throw new IOException(sm.getString("ajpmessage.invalidLength",
index ceb1c29..785f99c 100644 (file)
@@ -414,7 +414,7 @@ public class AjpProcessor extends AbstractAjpProcessor<Socket> {
 
         read(buf, 0, headerLength);
 
-        int messageLength = message.processHeader();
+        int messageLength = message.processHeader(true);
         if (messageLength < 0) {
             // Invalid AJP header signature
             // TODO: Throw some exception and close the connection to frontend.
index f2cd521..2953ac7 100644 (file)
@@ -149,7 +149,7 @@ public class SimpleAjpClient {
 
         read(is, buf, 0, headerLength);
 
-        int messageLength = message.processHeader();
+        int messageLength = message.processHeader(false);
         if (messageLength < 0) {
             throw new IOException("Invalid AJP message length");
         } else if (messageLength == 0) {
index 0112c8e..c91b528 100644 (file)
@@ -101,7 +101,7 @@ public class TestAbstractAjpProcessor extends TomcatBaseTest {
         assertEquals((byte) 'B', message.buf[1]);
         
         // Set the start position and read the length
-        message.processHeader();
+        message.processHeader(false);
         
         // Check the length
         assertTrue(message.len > 0);
@@ -136,7 +136,7 @@ public class TestAbstractAjpProcessor extends TomcatBaseTest {
         assertEquals((byte) 'B', message.buf[1]);
         
         // Set the start position and read the length
-        message.processHeader();
+        message.processHeader(false);
         
         // Should be a body chunk message
         assertEquals(0x03, message.readByte());
@@ -153,7 +153,7 @@ public class TestAbstractAjpProcessor extends TomcatBaseTest {
         assertEquals((byte) 'A', message.buf[0]);
         assertEquals((byte) 'B', message.buf[1]);
 
-        message.processHeader();
+        message.processHeader(false);
         
         // Should be an end body message
         assertEquals(0x05, message.readByte());
index b9053e8..8835c64 100644 (file)
@@ -67,4 +67,17 @@ public class TesterAjpMessage extends AjpMessage {
             return readString(len);
         }
     }
+
+    @Override
+    public void end() {
+        len = pos;
+        int dLen = len - 4;
+
+        buf[0] = (byte) 0x12;
+        buf[1] = (byte) 0x34;
+        buf[2] = (byte) ((dLen>>>8) & 0xFF);
+        buf[3] = (byte) (dLen & 0xFF);
+    }
+
+    
 }