Author: mmillson
Date: 2010-06-23 23:15:20 -0400 (Wed, 23 Jun 2010)
New Revision: 1492
Modified:
branches/JBOSSWEB_2_0_0_GA_CP12_JBPAPP-4519/src/share/classes/org/apache/catalina/connector/LocalStrings.properties
branches/JBOSSWEB_2_0_0_GA_CP12_JBPAPP-4519/src/share/classes/org/apache/catalina/connector/Request.java
Log:
Fix retrieving request parameters on POST with transfer-encoding: chunked for
[JBPAPP-4519].
Modified:
branches/JBOSSWEB_2_0_0_GA_CP12_JBPAPP-4519/src/share/classes/org/apache/catalina/connector/LocalStrings.properties
===================================================================
---
branches/JBOSSWEB_2_0_0_GA_CP12_JBPAPP-4519/src/share/classes/org/apache/catalina/connector/LocalStrings.properties 2010-06-24
02:51:20 UTC (rev 1491)
+++
branches/JBOSSWEB_2_0_0_GA_CP12_JBPAPP-4519/src/share/classes/org/apache/catalina/connector/LocalStrings.properties 2010-06-24
03:15:20 UTC (rev 1492)
@@ -48,6 +48,7 @@
coyoteRequest.attributeEvent=Exception thrown by attributes event listener
coyoteRequest.parseParameters=Exception thrown whilst processing POSTed parameters
coyoteRequest.postTooLarge=Parameters were not parsed because the size of the posted data
was too big. Use the maxPostSize attribute of the connector to resolve this if the
application should accept large POSTs.
+coyoteRequest.chunkedPostTooLarge=Parameters were not parsed because the size of the
posted data was too big. Because this request was a chunked request, it could not be
processed further. Use the maxPostSize attribute of the connector to resolve this if the
application should accept large POSTs.
requestFacade.nullRequest=Null request object
responseFacade.nullResponse=Null response object
Modified:
branches/JBOSSWEB_2_0_0_GA_CP12_JBPAPP-4519/src/share/classes/org/apache/catalina/connector/Request.java
===================================================================
---
branches/JBOSSWEB_2_0_0_GA_CP12_JBPAPP-4519/src/share/classes/org/apache/catalina/connector/Request.java 2010-06-24
02:51:20 UTC (rev 1491)
+++
branches/JBOSSWEB_2_0_0_GA_CP12_JBPAPP-4519/src/share/classes/org/apache/catalina/connector/Request.java 2010-06-24
03:15:20 UTC (rev 1492)
@@ -46,6 +46,7 @@
import javax.servlet.http.HttpSession;
import org.apache.tomcat.util.buf.B2CConverter;
+import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.MessageBytes;
import org.apache.tomcat.util.buf.StringCache;
import org.apache.tomcat.util.http.Cookies;
@@ -2449,7 +2450,8 @@
int maxPostSize = connector.getMaxPostSize();
if ((maxPostSize > 0) && (len > maxPostSize)) {
if (context.getLogger().isDebugEnabled()) {
- context.getLogger().debug("Post too large");
+ context.getLogger().debug(
+ sm.getString("coyoteRequest.postTooLarge"));
}
return;
}
@@ -2474,6 +2476,20 @@
return;
}
parameters.processParameters(formData, 0, len);
+ } else if ("chunked".equalsIgnoreCase(
+ coyoteRequest.getHeader("transfer-encoding"))) {
+ byte[] formData = null;
+ try {
+ formData = readChunkedPostBody();
+ } catch (IOException e) {
+ // Client disconnect
+ if (context.getLogger().isDebugEnabled()) {
+ context.getLogger().debug(
+ sm.getString("coyoteRequest.parseParameters"), e);
+ }
+ return;
+ }
+ parameters.processParameters(formData, 0, formData.length);
}
}
@@ -2499,6 +2515,38 @@
/**
+ * Read chunked post body.
+ */
+ protected byte[] readChunkedPostBody() throws IOException {
+ ByteChunk body = new ByteChunk();
+
+ byte[] buffer = new byte[CACHED_POST_LEN];
+
+ int len = 0;
+ while (len > -1) {
+ len = getStream().read(buffer, 0, CACHED_POST_LEN);
+ if (connector.getMaxPostSize() > 0 &&
+ (body.getLength() + len) > connector.getMaxPostSize()) {
+ // Too much data
+ throw new IllegalArgumentException(
+ sm.getString("coyoteRequest.chunkedPostTooLarge"));
+ }
+ if (len > 0) {
+ body.append(buffer, 0, len);
+ }
+ }
+ if (body.getLength() < body.getBuffer().length) {
+ int length = body.getLength();
+ byte[] result = new byte[length];
+ System.arraycopy(body.getBuffer(), 0, result, 0, length);
+ return result;
+ } else {
+ return body.getBuffer();
+ }
+ }
+
+
+ /**
* Parse request locales.
*/
protected void parseLocales() {
Show replies by date