Author: markt
Date: Mon Sep 2 14:35:31 2013
New Revision: 1519453
URL: http://svn.apache.org/r1519453
Log:
Refactoring. Pull up readMessage()
Modified:
tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
Modified: tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java?rev=1519453&r1=1519452&r2=1519453&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AbstractAjpProcessor.java Mon Sep
2 14:35:31 2013
@@ -800,13 +800,31 @@ public abstract class AbstractAjpProcess
protected abstract void setupSocket(SocketWrapper<S> socketWrapper)
throws IOException;
+ protected abstract void setTimeout(SocketWrapper<S> socketWrapper,
+ int timeout) throws IOException;
+
// Methods called by prepareResponse()
protected abstract void output(byte[] src, int offset, int length)
throws IOException;
- // Methods used by process
- protected abstract void setTimeout(SocketWrapper<S> socketWrapper,
- int timeout) throws IOException;
+ // Methods used by readMessage
+ /**
+ * Read at least the specified amount of bytes, and place them
+ * in the input buffer. Note that if any data is available to read then
this
+ * method will always block until at least the specified number of bytes
+ * have been read.
+ *
+ * @param buf Buffer to read data into
+ * @param pos Start position
+ * @param n The minimum number of bytes to read
+ * @param block If there is no data available to read when this method is
+ * called, should this call block until data becomes
available?
+ * @return <code>true</code> if the requested number of bytes were read
+ * else <code>false</code>
+ * @throws IOException
+ */
+ protected abstract boolean read(byte[] buf, int pos, int n, boolean block)
+ throws IOException;
// Methods used by SocketInputBuffer
/** Receive a chunk of data. Called to implement the
@@ -848,8 +866,40 @@ public abstract class AbstractAjpProcess
*
* @throws IOException any other failure, including incomplete reads
*/
- protected abstract boolean readMessage(AjpMessage message,
- boolean blockOnFirstRead) throws IOException;
+ protected boolean readMessage(AjpMessage message, boolean block)
+ throws IOException {
+
+ byte[] buf = message.getBuffer();
+ int headerLength = message.getHeaderLength();
+
+ if (!read(buf, 0, headerLength, block)) {
+ return false;
+ }
+
+ int messageLength = message.processHeader(true);
+ if (messageLength < 0) {
+ // Invalid AJP header signature
+ throw new IOException(sm.getString("ajpmessage.invalidLength",
+ Integer.valueOf(messageLength)));
+ }
+ else if (messageLength == 0) {
+ // Zero length message.
+ return true;
+ }
+ else {
+ if (messageLength > message.getBuffer().length) {
+ // Message too long for the buffer
+ // Need to trigger a 400 response
+ throw new IllegalArgumentException(sm.getString(
+ "ajpprocessor.header.tooLong",
+ Integer.valueOf(messageLength),
+ Integer.valueOf(buf.length)));
+ }
+ read(buf, headerLength, messageLength, true);
+ return true;
+ }
+ }
+
@Override
public final boolean isComet() {
Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java?rev=1519453&r1=1519452&r2=1519453&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java Mon Sep 2
14:35:31 2013
@@ -182,18 +182,7 @@ public class AjpAprProcessor extends Abs
}
- /**
- * Read at least the specified amount of bytes, and place them
- * in the input buffer. Note that if any data is available to read then
this
- * method will always block until at least the specified number of bytes
- * have been read.
- *
- * @param n The minimum number of bytes to read
- * @param block If there is no data available to read when this method is
- * called, should this call block until data becomes
available?
- * @return
- * @throws IOException
- */
+ @Override
protected boolean read(byte[] buf, int pos, int n, boolean block)
throws IOException {
@@ -275,42 +264,6 @@ public class AjpAprProcessor extends Abs
}
- @Override
- protected boolean readMessage(AjpMessage message, boolean block)
- throws IOException {
-
- byte[] buf = message.getBuffer();
- int headerLength = message.getHeaderLength();
-
- if (!read(buf, 0, headerLength, block)) {
- return false;
- }
-
- int messageLength = message.processHeader(true);
- if (messageLength < 0) {
- // Invalid AJP header signature
- throw new IOException(sm.getString("ajpmessage.invalidLength",
- Integer.valueOf(messageLength)));
- }
- else if (messageLength == 0) {
- // Zero length message.
- return true;
- }
- else {
- if (messageLength > message.getBuffer().length) {
- // Message too long for the buffer
- // Need to trigger a 400 response
- throw new IllegalArgumentException(sm.getString(
- "ajpprocessor.header.tooLong",
- Integer.valueOf(messageLength),
- Integer.valueOf(buf.length)));
- }
- read(buf, headerLength, messageLength, true);
- return true;
- }
- }
-
-
/**
* Recycle the processor.
*/
Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java?rev=1519453&r1=1519452&r2=1519453&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpNioProcessor.java Mon Sep 2
14:35:31 2013
@@ -138,9 +138,7 @@ public class AjpNioProcessor extends Abs
}
- /**
- * Read the specified amount of bytes, and place them in the input buffer.
- */
+ @Override
protected boolean read(byte[] buf, int pos, int n, boolean blockFirstRead)
throws IOException {
@@ -203,40 +201,4 @@ public class AjpNioProcessor extends Abs
return 0;
}
}
-
-
- @Override
- protected boolean readMessage(AjpMessage message, boolean blockFirstRead)
- throws IOException {
-
- byte[] buf = message.getBuffer();
- int headerLength = message.getHeaderLength();
-
- if (!read(buf, 0, headerLength, blockFirstRead)) {
- return false;
- }
-
- int messageLength = message.processHeader(true);
- if (messageLength < 0) {
- // Invalid AJP header signature
- throw new IOException(sm.getString("ajpmessage.invalidLength",
- Integer.valueOf(messageLength)));
- }
- else if (messageLength == 0) {
- // Zero length message.
- return true;
- }
- else {
- if (messageLength > buf.length) {
- // Message too long for the buffer
- // Need to trigger a 400 response
- throw new IllegalArgumentException(sm.getString(
- "ajpprocessor.header.tooLong",
- Integer.valueOf(messageLength),
- Integer.valueOf(buf.length)));
- }
- read(buf, headerLength, messageLength, true);
- return true;
- }
- }
}
Modified: tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java?rev=1519453&r1=1519452&r2=1519453&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ajp/AjpProcessor.java Mon Sep 2
14:35:31 2013
@@ -121,22 +121,7 @@ public class AjpProcessor extends Abstra
}
- /**
- * Read at least the specified amount of bytes, and place them
- * in the input buffer.
- *
- * @param buf Buffer to read data into
- * @param pos Start position
- * @param n Number of bytes to read
- * @param blockFirstRead Should the first read block?
- *
- * @return If blockFirstRead is false, the connector supports non-blocking
- * IO and the first read does not return any data, this method
- * reads no data into the buffer returns false. Otherwise, blocking
- * reads are used read the specified number of bytes into the
- * buffer.
- * @throws IOException
- */
+ @Override
protected boolean read(byte[] buf, int pos, int n, boolean blockFirstRead)
throws IOException {
@@ -153,40 +138,4 @@ public class AjpProcessor extends Abstra
return true;
}
-
-
- @Override
- protected boolean readMessage(AjpMessage message, boolean block)
- throws IOException {
-
- byte[] buf = message.getBuffer();
- int headerLength = message.getHeaderLength();
-
- if (!read(buf, 0, headerLength, block)) {
- return false;
- }
-
- int messageLength = message.processHeader(true);
- if (messageLength < 0) {
- // Invalid AJP header signature
- throw new IOException(sm.getString("ajpmessage.invalidLength",
- Integer.valueOf(messageLength)));
- }
- else if (messageLength == 0) {
- // Zero length message.
- return true;
- }
- else {
- if (messageLength > buf.length) {
- // Message too long for the buffer
- // Need to trigger a 400 response
- throw new IllegalArgumentException(sm.getString(
- "ajpprocessor.header.tooLong",
- Integer.valueOf(messageLength),
- Integer.valueOf(buf.length)));
- }
- read(buf, headerLength, messageLength, true);
- return true;
- }
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]