diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/AbstractHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/AbstractHandler.java index 86adae4e050..fc8da059a7a 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/AbstractHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/AbstractHandler.java @@ -28,16 +28,27 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.HttpChannel; +import org.eclipse.jetty.server.HttpConnection; import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Response; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -/* ------------------------------------------------------------ */ /** AbstractHandler. + *
A convenience implementation of {@link Handler} that uses the + * {@link ContainerLifeCycle} to provide:
This method can be called from {@link #handle(String, Request, HttpServletRequest, HttpServletResponse)} when an {@link DispatcherType#ERROR} dispatch
+ * is detected and an error page needs to be generated by calling {@link HttpServletResponse#sendError(int, String)} with the appropriate code and reason,
+ * which are taken from {@link HttpServletRequest#getAttribute(String)} for {@link RequestDispatcher#ERROR_STATUS_CODE} and {@link RequestDispatcher#ERROR_MESSAGE}
+ * @see ErrorDispatchHandler for a conveniance class that calls this method.
+ * @param target
+ * The target of the request - either a URI or a name.
+ * @param baseRequest
+ * The original unwrapped request object.
+ * @param request
+ * The request either as the {@link Request} object or a wrapper of that request. The
+ * {@link HttpConnection#getCurrentConnection()}.{@link HttpConnection#getHttpChannel() getHttpChannel()}.{@link HttpChannel#getRequest() getRequest()}
+ * method can be used access the Request object if required.
+ * @param response
+ * The response as the {@link Response} object or a wrapper of that request. The
+ * {@link HttpConnection#getCurrentConnection()}.{@link HttpConnection#getHttpChannel() getHttpChannel()}.{@link HttpChannel#getResponse() getResponse()}
+ * method can be used access the Response object if required.
+ * @throws IOException
+ * if unable to handle the request or response processing
+ * @throws ServletException
+ * if unable to handle the request or response due to underlying servlet issue
+ */
protected void doError(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
Object o = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
@@ -79,7 +100,6 @@ public abstract class AbstractHandler extends ContainerLifeCycle implements Hand
response.sendError(code,reason);
}
- /* ------------------------------------------------------------ */
/*
* @see org.eclipse.thread.LifeCycle#start()
*/
@@ -93,7 +113,6 @@ public abstract class AbstractHandler extends ContainerLifeCycle implements Hand
super.doStart();
}
- /* ------------------------------------------------------------ */
/*
* @see org.eclipse.thread.LifeCycle#stop()
*/
@@ -105,7 +124,6 @@ public abstract class AbstractHandler extends ContainerLifeCycle implements Hand
super.doStop();
}
- /* ------------------------------------------------------------ */
@Override
public void setServer(Server server)
{
@@ -116,14 +134,12 @@ public abstract class AbstractHandler extends ContainerLifeCycle implements Hand
_server=server;
}
- /* ------------------------------------------------------------ */
@Override
public Server getServer()
{
return _server;
}
- /* ------------------------------------------------------------ */
@Override
public void destroy()
{
@@ -132,11 +148,52 @@ public abstract class AbstractHandler extends ContainerLifeCycle implements Hand
super.destroy();
}
- /* ------------------------------------------------------------ */
@Override
public void dumpThis(Appendable out) throws IOException
{
out.append(toString()).append(" - ").append(getState()).append('\n');
}
-
+
+ /**
+ * An extension of AbstractHandler that handles {@link DispatcherType#ERROR} dispatches.
+ *
+ * {@link DispatcherType#ERROR} dispatches are handled by calling the {@link #doError(String, Request, HttpServletRequest, HttpServletResponse)}
+ * method. All other dispatches are passed to the abstract {@link #doNonErrorHandle(String, Request, HttpServletRequest, HttpServletResponse)}
+ * method, which should be implemented with specific handler behavior
+ *
+ */
+ public static abstract class ErrorDispatchHandler extends AbstractHandler
+ {
+ @Override
+ public final void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ if (baseRequest.getDispatcherType()==DispatcherType.ERROR)
+ doError(target,baseRequest,request,response);
+ else
+ doNonErrorHandle(target,baseRequest,request,response);
+ }
+
+ /**
+ * Called by {@link #handle(String, Request, HttpServletRequest, HttpServletResponse)}
+ * for all non-{@link DispatcherType#ERROR} dispatches.
+ * @param target
+ * The target of the request - either a URI or a name.
+ * @param baseRequest
+ * The original unwrapped request object.
+ * @param request
+ * The request either as the {@link Request} object or a wrapper of that request. The
+ * {@link HttpConnection#getCurrentConnection()}.{@link HttpConnection#getHttpChannel() getHttpChannel()}.{@link HttpChannel#getRequest() getRequest()}
+ * method can be used access the Request object if required.
+ * @param response
+ * The response as the {@link Response} object or a wrapper of that request. The
+ * {@link HttpConnection#getCurrentConnection()}.{@link HttpConnection#getHttpChannel() getHttpChannel()}.{@link HttpChannel#getResponse() getResponse()}
+ * method can be used access the Response object if required.
+ * @throws IOException
+ * if unable to handle the request or response processing
+ * @throws ServletException
+ * if unable to handle the request or response due to underlying servlet issue
+ */
+ protected abstract void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException;
+ }
+
}
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
index 4af41cde9ac..f0a4f68661f 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java
@@ -1127,16 +1127,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
if (LOG.isDebugEnabled())
LOG.debug("context={}|{}|{} @ {}",baseRequest.getContextPath(),baseRequest.getServletPath(), baseRequest.getPathInfo(),this);
- // start manual inline of nextScope(target,baseRequest,request,response);
- if (never())
- nextScope(target,baseRequest,request,response);
- else if (_nextScope != null)
- _nextScope.doScope(target,baseRequest,request,response);
- else if (_outerScope != null)
- _outerScope.doHandle(target,baseRequest,request,response);
- else
- doHandle(target,baseRequest,request,response);
- // end manual inline (pathentic attempt to reduce stack depth)
+ nextScope(target,baseRequest,request,response);
}
finally
{
@@ -1159,7 +1150,41 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
}
}
}
+
+ /* ------------------------------------------------------------ */
+ protected void requestInitialized(Request baseRequest, HttpServletRequest request)
+ {
+ // Handle the REALLY SILLY request events!
+ if (!_servletRequestAttributeListeners.isEmpty())
+ for (ServletRequestAttributeListener l :_servletRequestAttributeListeners)
+ baseRequest.addEventListener(l);
+ if (!_servletRequestListeners.isEmpty())
+ {
+ final ServletRequestEvent sre = new ServletRequestEvent(_scontext,request);
+ for (ServletRequestListener l : _servletRequestListeners)
+ l.requestInitialized(sre);
+ }
+ }
+
+ /* ------------------------------------------------------------ */
+ protected void requestDestroyed(Request baseRequest, HttpServletRequest request)
+ {
+ // Handle more REALLY SILLY request events!
+ if (!_servletRequestListeners.isEmpty())
+ {
+ final ServletRequestEvent sre = new ServletRequestEvent(_scontext,request);
+ for (int i=_servletRequestListeners.size();i-->0;)
+ _servletRequestListeners.get(i).requestDestroyed(sre);
+ }
+
+ if (!_servletRequestAttributeListeners.isEmpty())
+ {
+ for (int i=_servletRequestAttributeListeners.size();i-->0;)
+ baseRequest.removeEventListener(_servletRequestAttributeListeners.get(i));
+ }
+ }
+
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.server.handler.ScopedHandler#doHandle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest,
@@ -1173,19 +1198,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
try
{
if (new_context)
- {
- // Handle the REALLY SILLY request events!
- if (!_servletRequestAttributeListeners.isEmpty())
- for (ServletRequestAttributeListener l :_servletRequestAttributeListeners)
- baseRequest.addEventListener(l);
-
- if (!_servletRequestListeners.isEmpty())
- {
- final ServletRequestEvent sre = new ServletRequestEvent(_scontext,request);
- for (ServletRequestListener l : _servletRequestListeners)
- l.requestInitialized(sre);
- }
- }
+ requestInitialized(baseRequest,request);
switch(dispatch)
{
@@ -1203,50 +1216,24 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
if (Boolean.TRUE.equals(baseRequest.getAttribute(Dispatcher.__ERROR_DISPATCH)))
break;
- Object error = request.getAttribute(Dispatcher.ERROR_STATUS_CODE);
- // We can just call sendError here. If there is no error page, then one will
+ // We can just call doError here. If there is no error page, then one will
// be generated. If there is an error page, then a RequestDispatcher will be
// used to route the request through appropriate filters etc.
- response.sendError((error instanceof Integer)?((Integer)error).intValue():500);
+ doError(target,baseRequest,request,response);
return;
default:
break;
}
- // start manual inline of nextHandle(target,baseRequest,request,response);
- // noinspection ConstantIfStatement
- if (never())
- nextHandle(target,baseRequest,request,response);
- else if (_nextScope != null && _nextScope == _handler)
- _nextScope.doHandle(target,baseRequest,request,response);
- else if (_handler != null)
- _handler.handle(target,baseRequest,request,response);
- // end manual inline
+ nextHandle(target,baseRequest,request,response);
}
finally
{
- // Handle more REALLY SILLY request events!
if (new_context)
- {
- if (!_servletRequestListeners.isEmpty())
- {
- final ServletRequestEvent sre = new ServletRequestEvent(_scontext,request);
- for (int i=_servletRequestListeners.size();i-->0;)
- _servletRequestListeners.get(i).requestDestroyed(sre);
- }
-
- if (!_servletRequestAttributeListeners.isEmpty())
- {
- for (int i=_servletRequestAttributeListeners.size();i-->0;)
- baseRequest.removeEventListener(_servletRequestAttributeListeners.get(i));
- }
- }
+ requestDestroyed(baseRequest,request);
}
}
-
-
-
/**
* @param request A request that is applicable to the scope, or null
* @param reason An object that indicates the reason the scope is being entered.
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
index 254886b776e..d3cee263b57 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
@@ -74,6 +74,12 @@ public class ErrorHandler extends AbstractHandler
*/
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
+ {
+ doError(target,baseRequest,request,response);
+ }
+
+ @Override
+ public void doError(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
{
String method = request.getMethod();
if (!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method))
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ScopedHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ScopedHandler.java
index 6a7f8af1f0e..1d3eadcd4ec 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ScopedHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ScopedHandler.java
@@ -129,7 +129,7 @@ public abstract class ScopedHandler extends HandlerWrapper
}
}
- /* ------------------------------------------------------------ */
+ /** ------------------------------------------------------------ */
/*
*/
@Override
@@ -145,22 +145,23 @@ public abstract class ScopedHandler extends HandlerWrapper
}
/* ------------------------------------------------------------ */
- /*
+ /**
* Scope the handler
+ *
Derived implementations should call {@link #nextScope(String, Request, HttpServletRequest, HttpServletResponse)} */ - public abstract void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException; + public void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException + { + nextScope(target,baseRequest,request,response); + } /* ------------------------------------------------------------ */ - /* + /** * Scope the handler */ public final void nextScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - // this method has been manually inlined in several locations, but - // is called protected by an if(never()), so your IDE can find those - // locations if this code is changed. if (_nextScope!=null) _nextScope.doScope(target,baseRequest,request, response); else if (_outerScope!=null) @@ -170,8 +171,9 @@ public abstract class ScopedHandler extends HandlerWrapper } /* ------------------------------------------------------------ */ - /* + /** * Do the handler work within the scope. + *
Derived implementations should call {@link #nextHandle(String, Request, HttpServletRequest, HttpServletResponse)} */ public abstract void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException; @@ -182,19 +184,9 @@ public abstract class ScopedHandler extends HandlerWrapper */ public final void nextHandle(String target, final Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - // this method has been manually inlined in several locations, but - // is called protected by an if(never()), so your IDE can find those - // locations if this code is changed. if (_nextScope!=null && _nextScope==_handler) _nextScope.doHandle(target,baseRequest,request, response); else if (_handler!=null) - _handler.handle(target,baseRequest, request, response); + super.handle(target,baseRequest,request,response); } - - /* ------------------------------------------------------------ */ - protected boolean never() - { - return false; - } - } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java index af7712bc7d9..3bfd7e58faa 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java @@ -1581,14 +1581,7 @@ public class SessionHandler extends ScopedHandler @Override public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - // start manual inline of nextHandle(target,baseRequest,request,response); - if (never()) - nextHandle(target,baseRequest,request,response); - else if (_nextScope != null && _nextScope == _handler) - _nextScope.doHandle(target,baseRequest,request,response); - else if (_handler != null) - _handler.handle(target,baseRequest,request,response); - // end manual inline + nextHandle(target,baseRequest,request,response); } /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java index 3ddabdbb687..66970e26e23 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java @@ -128,7 +128,7 @@ public abstract class AbstractHttpTest } } - protected class ThrowExceptionOnDemandHandler extends AbstractHandler + protected class ThrowExceptionOnDemandHandler extends AbstractHandler.ErrorDispatchHandler { private final boolean throwException; private volatile Throwable failure; @@ -138,14 +138,8 @@ public abstract class AbstractHttpTest this.throwException = throwException; } - @Override final - public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException - { - super.handle(target,baseRequest,request,response); - } - @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (throwException) throw new TestCommitException(); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java b/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java index 6e55843bdb0..ed61d574518 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/DumpHandler.java @@ -38,15 +38,11 @@ import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -/* ------------------------------------------------------------ */ /** Dump request handler. * Dumps GET and POST requests. * Useful for testing and debugging. - * - * @version $Id: DumpHandler.java,v 1.14 2005/08/13 00:01:26 gregwilkins Exp $ - * */ -public class DumpHandler extends AbstractHandler +public class DumpHandler extends AbstractHandler.ErrorDispatchHandler { private static final Logger LOG = Log.getLogger(DumpHandler.class); @@ -61,12 +57,8 @@ public class DumpHandler extends AbstractHandler this.label=label; } - /* ------------------------------------------------------------ */ - /* - * @see org.eclipse.jetty.server.server.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int) - */ @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (!isStarted()) return; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java index 89af28b26ea..b434a210414 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java @@ -857,10 +857,10 @@ public class HttpConnectionTest final CountDownLatch checkError = new CountDownLatch(1); String response = null; server.stop(); - server.setHandler(new DumpHandler() + server.setHandler(new AbstractHandler.ErrorDispatchHandler() { @Override - public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.setHeader(HttpHeader.CONTENT_TYPE.toString(),MimeTypes.Type.TEXT_HTML.toString()); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java index 329e771a81b..2dce71ca6a5 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java @@ -84,7 +84,7 @@ public class HttpManyWaysToAsyncCommitBadBehaviourTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { final CyclicBarrier resumeBarrier = new CyclicBarrier(1); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java index 102380cd06a..02cd7651b7c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java @@ -100,7 +100,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -118,7 +118,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } }).run(); } - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -158,7 +158,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -177,7 +177,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest }).run(); } baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -216,7 +216,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -243,7 +243,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest }).run(); } baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -286,7 +286,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -315,7 +315,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest }).run(); } baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -357,7 +357,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -384,7 +384,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest }).run(); } baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -426,7 +426,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -456,7 +456,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest }).run(); } baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -501,7 +501,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -530,7 +530,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest }).run(); } baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -573,7 +573,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -602,7 +602,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest }).run(); } baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -646,7 +646,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -675,7 +675,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest }).run(); } baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -714,7 +714,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -743,7 +743,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest }).run(); } baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -783,7 +783,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) { @@ -812,7 +812,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest }).run(); } baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java index bcd8b18aaea..3f4e788d321 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java @@ -86,10 +86,10 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(false); // not needed, but lets be explicit about what the test does - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -126,10 +126,10 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -166,11 +166,11 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.getWriter().write("foobar"); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -211,12 +211,12 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.getWriter().write("foobar"); response.flushBuffer(); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -254,11 +254,11 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.flushBuffer(); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -299,13 +299,13 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.getWriter().write("foo"); response.flushBuffer(); response.getWriter().write("bar"); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -374,12 +374,12 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.setBufferSize(4); response.getWriter().write("foobar"); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -391,13 +391,13 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.setBufferSize(8); response.getWriter().write("fo"); response.getWriter().write("obarfoobar"); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -409,7 +409,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.setBufferSize(8); @@ -419,7 +419,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest response.getWriter().write("fo"); response.getWriter().write("ob"); response.getWriter().write("ar"); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -520,12 +520,12 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.setContentLength(3); response.getWriter().write("foo"); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -563,13 +563,13 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.setContentLength(3); // Only "foo" will get written and "bar" will be discarded response.getWriter().write("foobar"); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -607,12 +607,12 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.getWriter().write("foo"); response.setContentLength(3); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } @@ -650,12 +650,12 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest } @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); response.getWriter().write("foobar"); response.setContentLength(3); - super.doHandle(target, baseRequest, request, response); + super.doNonErrorHandle(target, baseRequest, request, response); } } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java index af2e4947298..d36e9469af6 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java @@ -269,10 +269,10 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture @Test public void testExceptionThrownInHandler() throws Exception { - configureServer(new AbstractHandler() + configureServer(new AbstractHandler.ErrorDispatchHandler() { @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { throw new QuietServletException("TEST handler exception"); } @@ -300,10 +300,10 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture { final AtomicBoolean fourBytesRead = new AtomicBoolean(false); final AtomicBoolean earlyEOFException = new AtomicBoolean(false); - configureServer(new AbstractHandler() + configureServer(new AbstractHandler.ErrorDispatchHandler() { @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { baseRequest.setHandled(true); int contentLength = request.getContentLength(); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index c147baed452..f1401e66341 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -1494,14 +1494,14 @@ public class RequestTest boolean check(HttpServletRequest request,HttpServletResponse response) throws IOException; } - private class RequestHandler extends AbstractHandler + private class RequestHandler extends AbstractHandler.ErrorDispatchHandler { private RequestTester _checker; @SuppressWarnings("unused") private String _content; @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { ((Request)request).setHandled(true); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SniSslConnectionFactoryTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SniSslConnectionFactoryTest.java index 5534a7b2d6f..8b93f741035 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SniSslConnectionFactoryTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SniSslConnectionFactoryTest.java @@ -99,10 +99,10 @@ public class SniSslConnectionFactoryTest new HttpConnectionFactory(_https_config)); _server.addConnector(https); - _server.setHandler(new AbstractHandler() + _server.setHandler(new AbstractHandler.ErrorDispatchHandler() { @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) { baseRequest.setHandled(true); response.setStatus(200); diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java index bfd5f438c2b..14a5796fec8 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java @@ -478,16 +478,7 @@ public class ServletHandler extends ScopedHandler old_scope=baseRequest.getUserIdentityScope(); baseRequest.setUserIdentityScope(servlet_holder); - // start manual inline of nextScope(target,baseRequest,request,response); - if (never()) - nextScope(target,baseRequest,request,response); - else if (_nextScope!=null) - _nextScope.doScope(target,baseRequest,request, response); - else if (_outerScope!=null) - _outerScope.doHandle(target,baseRequest,request, response); - else - doHandle(target,baseRequest,request, response); - // end manual inline (pathentic attempt to reduce stack depth) + nextScope(target,baseRequest,request,response); } finally { diff --git a/jetty-unixsocket/src/test/java/org/eclipse/jetty/unixsocket/UnixSocketServer.java b/jetty-unixsocket/src/test/java/org/eclipse/jetty/unixsocket/UnixSocketServer.java index 32482cef377..8f62a69fe89 100644 --- a/jetty-unixsocket/src/test/java/org/eclipse/jetty/unixsocket/UnixSocketServer.java +++ b/jetty-unixsocket/src/test/java/org/eclipse/jetty/unixsocket/UnixSocketServer.java @@ -41,12 +41,11 @@ public class UnixSocketServer UnixSocketConnector connector = new UnixSocketConnector(server,proxy,http); server.addConnector(connector); - server.setHandler(new AbstractHandler() + server.setHandler(new AbstractHandler.ErrorDispatchHandler() { - @Override - protected void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) - throws IOException, ServletException + protected void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { baseRequest.setHandled(true); response.setStatus(200); diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ServerTimeoutsTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ServerTimeoutsTest.java index 855ab7c0908..92fbc2aed88 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ServerTimeoutsTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/ServerTimeoutsTest.java @@ -495,12 +495,11 @@ public class ServerTimeoutsTest extends AbstractTest int bytesPerSecond = 20; httpConfig.setMinRequestDataRate(bytesPerSecond); CountDownLatch handlerLatch = new CountDownLatch(1); - start(new AbstractHandler() + start(new AbstractHandler.ErrorDispatchHandler() { @Override - public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void doNonErrorHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - try { baseRequest.setHandled(true); @@ -518,6 +517,7 @@ public class ServerTimeoutsTest extends AbstractTest throw x; } } + }); DeferredContentProvider contentProvider = new DeferredContentProvider();