416477 Improved consumeAll error handling

This commit is contained in:
Greg Wilkins 2013-09-05 12:09:22 +10:00
parent 9b9c7ba8d1
commit ce098c67de
3 changed files with 92 additions and 13 deletions

View File

@ -265,7 +265,7 @@ public abstract class HttpInput<T> extends ServletInputStream
synchronized (lock())
{
T item = _inputQ.peekUnsafe();
while (!isShutdown() && !isEarlyEOF())
loop: while (!isShutdown() && !isEarlyEOF())
{
while (item != null)
{
@ -286,7 +286,8 @@ public abstract class HttpInput<T> extends ServletInputStream
}
catch (IOException e)
{
throw new RuntimeIOException(e);
LOG.warn(e);
break loop;
}
}
}

View File

@ -71,11 +71,14 @@ public class DumpHandler extends AbstractHandler
if (!isStarted())
return;
StringBuilder read = null;
if (request.getParameter("read")!=null)
{
read=new StringBuilder();
int len=Integer.parseInt(request.getParameter("read"));
Reader in = request.getReader();
for (int i=Integer.parseInt(request.getParameter("read"));i-->0;)
in.read();
for (int i=len;i-->0;)
read.append((char)in.read());
}
if (request.getParameter("ISE")!=null)
@ -190,16 +193,23 @@ public class DumpHandler extends AbstractHandler
writer.write("</pre>\n<h3>Content:</h3>\n<pre>");
char[] content= new char[4096];
int len;
try{
Reader in=request.getReader();
while((len=in.read(content))>=0)
writer.write(new String(content,0,len));
}
catch(IOException e)
if (read!=null)
{
writer.write(e.toString());
writer.write(read.toString());
}
else
{
char[] content= new char[4096];
int len;
try{
Reader in=request.getReader();
while((len=in.read(content))>=0)
writer.write(new String(content,0,len));
}
catch(IOException e)
{
writer.write(e.toString());
}
}
writer.write("</pre>\n");

View File

@ -68,6 +68,7 @@ public class HttpConnectionTest
http.getHttpConfiguration().setResponseHeaderSize(1024);
connector = new LocalConnector(server,http,null);
connector.setIdleTimeout(500);
server.addConnector(connector);
server.setHandler(new DumpHandler());
server.start();
@ -371,6 +372,73 @@ public class HttpConnectionTest
}
}
@Test
public void testUnconsumed() throws Exception
{
String response=null;
String requests=null;
int offset=0;
offset=0;
requests=
"GET /R1?read=4 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: chunked\n"+
"Content-Type: text/plain; charset=utf-8\n"+
"\015\012"+
"5;\015\012"+
"12345\015\012"+
"5;\015\012"+
"67890\015\012"+
"0;\015\012\015\012"+
"GET /R2 HTTP/1.1\n"+
"Host: localhost\n"+
"Content-Type: text/plain; charset=utf-8\n"+
"Content-Length: 10\n"+
"Connection: close\n"+
"\n"+
"abcdefghij\n";
response=connector.getResponses(requests);
offset = checkContains(response,offset,"HTTP/1.1 200");
offset = checkContains(response,offset,"pathInfo=/R1");
offset = checkContains(response,offset,"1234");
checkNotContained(response,offset,"56789");
offset = checkContains(response,offset,"HTTP/1.1 200");
offset = checkContains(response,offset,"pathInfo=/R2");
offset = checkContains(response,offset,"encoding=UTF-8");
offset = checkContains(response,offset,"abcdefghij");
}
@Test
public void testUnconsumedTimeout() throws Exception
{
String response=null;
String requests=null;
int offset=0;
offset=0;
requests=
"GET /R1?read=4 HTTP/1.1\n"+
"Host: localhost\n"+
"Transfer-Encoding: chunked\n"+
"Content-Type: text/plain; charset=utf-8\n"+
"\015\012"+
"5;\015\012"+
"12345\015\012";
long start=System.currentTimeMillis();
response=connector.getResponses(requests,2000,TimeUnit.MILLISECONDS);
if ((System.currentTimeMillis()-start)>=2000)
Assert.fail();
offset = checkContains(response,offset,"HTTP/1.1 200");
offset = checkContains(response,offset,"pathInfo=/R1");
offset = checkContains(response,offset,"1234");
checkNotContained(response,offset,"56789");
}
@Test
public void testUnconsumedError() throws Exception
{