Author: markt
Date: Thu Aug 30 18:37:18 2012
New Revision: 1379050
URL: http://svn.apache.org/viewvc?rev=1379050&view=rev
Log:
Implement fall-back for checking for failure when socket is closed before
client can read response. Fixes intermittent issue on Windows.
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1379047
Modified:
tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java?rev=1379050&r1=1379049&r2=1379050&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
(original)
+++
tomcat/tc7.0.x/trunk/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
Thu Aug 30 18:37:18 2012
@@ -27,6 +27,8 @@ import javax.servlet.http.HttpServletReq
import javax.servlet.http.HttpServletResponse;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@@ -102,7 +104,8 @@ public class TestChunkedInputFilter exte
Context ctx =
tomcat.addContext("", System.getProperty("java.io.tmpdir"));
- Tomcat.addServlet(ctx, "servlet", new EchoHeaderServlet());
+ EchoHeaderServlet servlet = new EchoHeaderServlet();
+ Tomcat.addServlet(ctx, "servlet", servlet);
ctx.addServletMapping("/", "servlet");
tomcat.start();
@@ -131,14 +134,28 @@ public class TestChunkedInputFilter exte
client.setRequest(request);
client.connect();
- client.processRequest();
+ Exception processException = null;
+ try {
+ client.processRequest();
+ } catch (Exception e) {
+ // Socket was probably closed before client had a chance to read
+ // response
+ processException = e;
+ }
if (expectPass) {
assertTrue(client.isResponse200());
assertEquals("nullnull7TestValue1TestValue2",
client.getResponseBody());
+ assertNull(processException);
+ assertFalse(servlet.getExceptionDuringRead());
} else {
- assertTrue(client.getResponseLine(), client.isResponse500());
+ if (processException == null) {
+ assertTrue(client.getResponseLine(), client.isResponse500());
+ } else {
+ // Use fall-back for checking the error occurred
+ assertTrue(servlet.getExceptionDuringRead());
+ }
}
}
@@ -226,6 +243,8 @@ public class TestChunkedInputFilter exte
private static class EchoHeaderServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
+ private boolean exceptionDuringRead = false;
+
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
@@ -238,8 +257,13 @@ public class TestChunkedInputFilter exte
// Read the body - quick and dirty
InputStream is = req.getInputStream();
int count = 0;
- while (is.read() > -1) {
- count++;
+ try {
+ while (is.read() > -1) {
+ count++;
+ }
+ } catch (IOException ioe) {
+ exceptionDuringRead = true;
+ throw ioe;
}
pw.write(Integer.valueOf(count).toString());
@@ -249,6 +273,10 @@ public class TestChunkedInputFilter exte
dumpHeader("x-trailer2", req, pw);
}
+ public boolean getExceptionDuringRead() {
+ return exceptionDuringRead;
+ }
+
private void dumpHeader(String headerName, HttpServletRequest req,
PrintWriter pw) {
String value = req.getHeader(headerName);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]