JETTY-1086 Use UncheckedPrintWriter & cleaned up HttpStatus.Code usage
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@931 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
0b70620b82
commit
ac6c1b98e1
|
@ -12,7 +12,7 @@ jetty-7.0.0.RC6-SNAPSHOT
|
|||
+ JETTY-936 274251 Improved servlet matching and optimized'
|
||||
+ JETTY-1080 modify previous fix to work on windows
|
||||
+ JETTY-1084 HEAD command not setting content-type in response under certain circumstances
|
||||
+ JETTY-1086 Use UncheckedPrintWriter
|
||||
+ JETTY-1086 Use UncheckedPrintWriter & cleaned up HttpStatus.Code usage
|
||||
+ JETTY-1090 resolve potential infinite loop with webdav listener
|
||||
+ JETTY-1092 MultiPartFilter can be pushed into infinite loop
|
||||
+ JETTY-1093 Request.toString throws exception when size exceeds 4k
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.eclipse.jetty.http.HttpStatus;
|
|||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.http.HttpVersions;
|
||||
import org.eclipse.jetty.http.MimeTypes;
|
||||
import org.eclipse.jetty.http.HttpStatus.Code;
|
||||
import org.eclipse.jetty.io.BufferCache.CachedBuffer;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ErrorHandler;
|
||||
|
@ -276,7 +277,7 @@ public class Response implements HttpServletResponse
|
|||
setStatus(code,message);
|
||||
|
||||
if (message==null)
|
||||
message=HttpStatus.getCode(code).getMessage();
|
||||
message=HttpStatus.getMessage(code);
|
||||
|
||||
// If we are allowed to have a body
|
||||
if (code!=SC_NO_CONTENT &&
|
||||
|
@ -324,7 +325,7 @@ public class Response implements HttpServletResponse
|
|||
writer.write(Integer.toString(code));
|
||||
writer.write(' ');
|
||||
if (message==null)
|
||||
message=HttpStatus.getCode(code).getMessage();
|
||||
message=HttpStatus.getMessage(code);
|
||||
writer.write(message);
|
||||
writer.write("</title>\n</head>\n<body>\n<h2>HTTP ERROR: ");
|
||||
writer.write(Integer.toString(code));
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.jetty.http.HttpHeaders;
|
|||
import org.eclipse.jetty.http.HttpMethods;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.MimeTypes;
|
||||
import org.eclipse.jetty.http.HttpStatus.Code;
|
||||
import org.eclipse.jetty.server.HttpConnection;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.util.ByteArrayISO8859Writer;
|
||||
|
@ -74,7 +75,7 @@ public class ErrorHandler extends AbstractHandler
|
|||
throws IOException
|
||||
{
|
||||
if (message == null)
|
||||
message=HttpStatus.getCode(code).getMessage();
|
||||
message=HttpStatus.getMessage(code);
|
||||
|
||||
writer.write("<html>\n<head>\n");
|
||||
writeErrorPageHead(request,writer,code,message);
|
||||
|
|
|
@ -493,7 +493,6 @@ public class ServletHandler extends ScopedHandler
|
|||
Log.warn(request.getRequestURI(),th);
|
||||
}
|
||||
|
||||
// TODO httpResponse.getHttpConnection().forceClose();
|
||||
if (!response.isCommitted())
|
||||
{
|
||||
request.setAttribute(Dispatcher.ERROR_EXCEPTION_TYPE,th.getClass());
|
||||
|
@ -510,10 +509,7 @@ public class ServletHandler extends ScopedHandler
|
|||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,th.getMessage());
|
||||
}
|
||||
else
|
||||
if(Log.isDebugEnabled())Log.debug("Response already committed for handling "+th);
|
||||
|
||||
if (th instanceof IOException)
|
||||
throw (IOException)th;
|
||||
Log.debug("Response already committed for handling "+th);
|
||||
}
|
||||
catch(Error e)
|
||||
{
|
||||
|
@ -530,7 +526,7 @@ public class ServletHandler extends ScopedHandler
|
|||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,e.getMessage());
|
||||
}
|
||||
else
|
||||
if(Log.isDebugEnabled())Log.debug("Response already committed for handling ",e);
|
||||
Log.debug("Response already committed for handling ",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.jetty.http.HttpException;
|
||||
import org.eclipse.jetty.io.ByteArrayBuffer;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
|
||||
|
@ -39,7 +40,9 @@ public class ServletTest extends TestCase
|
|||
tester.setContextPath("/context");
|
||||
tester.addServlet(TestServlet.class, "/servlet/*");
|
||||
tester.addServlet(HelloServlet.class, "/hello/*");
|
||||
tester.addServlet(ExceptServlet.class, "/except/*");
|
||||
tester.addServlet("org.eclipse.jetty.servlet.DefaultServlet", "/");
|
||||
|
||||
tester.start();
|
||||
}
|
||||
|
||||
|
@ -233,6 +236,36 @@ public class ServletTest extends TestCase
|
|||
assertEquals(expected,responses.toString());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void testExcept() throws Exception
|
||||
{
|
||||
String request0=
|
||||
"GET /context/except/io HTTP/1.1\r\n"+
|
||||
"Host: whatever\r\n"+
|
||||
"\r\n"+
|
||||
"GET /context/except/http HTTP/1.1\r\n"+
|
||||
"Host: whatever\r\n"+
|
||||
"\r\n";
|
||||
|
||||
ByteArrayBuffer out = new ByteArrayBuffer(4096);
|
||||
out.put(request0.getBytes("iso8859-1"));
|
||||
String responses = tester.getResponses(out).toString();
|
||||
|
||||
int offset = responses.indexOf("HTTP/1.1 500");
|
||||
assertTrue(offset>=0);
|
||||
offset = responses.indexOf("Content-Length: ",offset);
|
||||
assertTrue(offset>0);
|
||||
offset = responses.indexOf("<h2>HTTP ERROR 500</h2>",offset);
|
||||
assertTrue(offset>0);
|
||||
offset = responses.indexOf("IOException: testing",offset);
|
||||
assertTrue(offset>0);
|
||||
offset = responses.indexOf("</html>",offset);
|
||||
assertTrue(offset>0);
|
||||
offset = responses.indexOf("HTTP/1.1 499",offset);
|
||||
assertTrue(offset>0);
|
||||
offset = responses.indexOf("Content-Length: ",offset);
|
||||
assertTrue(offset>0);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static class HelloServlet extends HttpServlet
|
||||
|
@ -285,4 +318,19 @@ public class ServletTest extends TestCase
|
|||
response.getWriter().print("<h1>Test Servlet</h1>");
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExceptServlet extends HttpServlet
|
||||
{
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
if ("/http".equals(request.getPathInfo()))
|
||||
throw new HttpException(499);
|
||||
if ("/runtime".equals(request.getPathInfo()))
|
||||
throw new RuntimeException("testing");
|
||||
if ("/error".equals(request.getPathInfo()))
|
||||
throw new Error("testing");
|
||||
throw new IOException("testing");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue