Merge remote-tracking branch 'origin/master' into jetty-9.1

Conflicts:
	jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java
This commit is contained in:
Greg Wilkins 2013-10-31 14:40:54 +11:00
commit c64dad6066
3 changed files with 54 additions and 9 deletions

View File

@ -420,6 +420,7 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable
boolean committed = sendResponse(info, null, true);
if (!committed)
LOG.warn("Could not send response error 500: "+x);
_request.getAsyncContext().complete();
}
else if (isCommitted())
{

View File

@ -569,10 +569,10 @@ public class ServletHandler extends ScopedHandler
LOG.debug(request.toString());
}
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,th.getClass());
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,th);
if (!response.isCommitted())
{
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,th.getClass());
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,th);
if (th instanceof UnavailableException)
{
UnavailableException ue = (UnavailableException)th;
@ -586,6 +586,10 @@ public class ServletHandler extends ScopedHandler
}
else
LOG.debug("Response already committed",th);
// Complete async requests
if (request.isAsyncStarted())
request.getAsyncContext().complete();
}
catch(Error e)
{
@ -596,15 +600,16 @@ public class ServletHandler extends ScopedHandler
LOG.warn("Error for "+request.getRequestURI(),e);
if(LOG.isDebugEnabled())LOG.debug(request.toString());
// TODO httpResponse.getHttpConnection().forceClose();
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,e.getClass());
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,e);
if (!response.isCommitted())
{
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE,e.getClass());
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION,e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
else
LOG.debug("Response already committed for handling ",e);
// Complete async requests
if (request.isAsyncStarted())
request.getAsyncContext().complete();
}
finally
{

View File

@ -41,6 +41,7 @@ import javax.servlet.http.HttpServletResponseWrapper;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.QuietServletException;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
@ -68,7 +69,7 @@ public class AsyncContextTest
_server = new Server();
_contextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
_connector = new LocalConnector(_server);
_connector.setIdleTimeout(30000);
_connector.setIdleTimeout(5000);
_server.setConnectors(new Connector[]
{ _connector });
@ -76,6 +77,7 @@ public class AsyncContextTest
_contextHandler.addServlet(new ServletHolder(new TestServlet()),"/servletPath");
_contextHandler.addServlet(new ServletHolder(new TestServlet()),"/path with spaces/servletPath");
_contextHandler.addServlet(new ServletHolder(new TestServlet2()),"/servletPath2");
_contextHandler.addServlet(new ServletHolder(new TestStartThrowServlet()),"/startthrow/*");
_contextHandler.addServlet(new ServletHolder(new ForwardingServlet()),"/forward");
_contextHandler.addServlet(new ServletHolder(new AsyncDispatchingServlet()),"/dispatchingServlet");
_contextHandler.addServlet(new ServletHolder(new ExpireServlet()),"/expire/*");
@ -84,7 +86,8 @@ public class AsyncContextTest
ErrorPageErrorHandler error_handler = new ErrorPageErrorHandler();
_contextHandler.setErrorHandler(error_handler);
error_handler.addErrorPage(500,"/error");
error_handler.addErrorPage(500,"/error/500");
error_handler.addErrorPage(IOException.class.getName(),"/error/IOE");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]
@ -116,6 +119,25 @@ public class AsyncContextTest
}
@Test
public void testStartThrow() throws Exception
{
String request = "GET /ctx/startthrow HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ "Connection: close\r\n" + "\r\n";
String responseString = _connector.getResponses(request);
BufferedReader br = new BufferedReader(new StringReader(responseString));
assertEquals("HTTP/1.1 500 Server Error",br.readLine());
br.readLine();// connection close
br.readLine();// server
br.readLine();// empty
Assert.assertEquals("error servlet","ERROR: /error",br.readLine());
Assert.assertEquals("error servlet","PathInfo= /IOE",br.readLine());
Assert.assertEquals("error servlet","EXCEPTION: java.io.IOException: Test",br.readLine());
}
@Test
public void testDispatchAsyncContext() throws Exception
{
@ -327,6 +349,7 @@ public class AsyncContextTest
br.readLine();// empty
Assert.assertEquals("error servlet","ERROR: /error",br.readLine());
Assert.assertEquals("error servlet","PathInfo= /500",br.readLine());
Assert.assertEquals("error servlet","EXCEPTION: java.io.IOException: TEST",br.readLine());
}
@ -365,6 +388,7 @@ public class AsyncContextTest
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.getOutputStream().print("ERROR: " + request.getServletPath() + "\n");
response.getOutputStream().print("PathInfo= " + request.getPathInfo() + "\n");
if (request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)!=null)
response.getOutputStream().print("EXCEPTION: " + request.getAttribute(RequestDispatcher.ERROR_EXCEPTION) + "\n");
}
@ -462,6 +486,21 @@ public class AsyncContextTest
asyncContext.start(new AsyncRunnable(asyncContext));
}
}
private class TestStartThrowServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
if (request.getDispatcherType()==DispatcherType.REQUEST)
{
request.startAsync(request, response);
throw new QuietServletException(new IOException("Test"));
}
}
}
private class AsyncRunnable implements Runnable
{