Class ScopedHandler

  • All Implemented Interfaces:
    Handler, HandlerContainer, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
    Direct Known Subclasses:
    ContextHandler, ServletHandler, SessionHandler

    @Deprecated(since="2021-05-27")
    public abstract class ScopedHandler
    extends HandlerWrapper
    Deprecated.
    The Eclipse Jetty and Apache Felix Http Jetty packages are no longer supported.
    ScopedHandler. A ScopedHandler is a HandlerWrapper where the wrapped handlers each define a scope.

    When handle(String, Request, HttpServletRequest, HttpServletResponse) is called on the first ScopedHandler in a chain of HandlerWrappers, the doScope(String, Request, HttpServletRequest, HttpServletResponse) method is called on all contained ScopedHandlers, before the doHandle(String, Request, HttpServletRequest, HttpServletResponse) method is called on all contained handlers.

    For example if Scoped handlers A, B & C were chained together, then the calling order would be:

      A.handle(...)
        A.doScope(...)
          B.doScope(...)
            C.doScope(...)
              A.doHandle(...)
                B.doHandle(...)
                   C.doHandle(...)
      

    If non scoped handler X was in the chained A, B, X & C, then the calling order would be:

      A.handle(...)
        A.doScope(...)
          B.doScope(...)
            C.doScope(...)
              A.doHandle(...)
                B.doHandle(...)
                  X.handle(...)
                    C.handle(...)
                      C.doHandle(...)
      

    A typical usage pattern is:

          private static class MyHandler extends ScopedHandler
          {
              public void doScope(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
              {
                  try
                  {
                      setUpMyScope();
                      super.doScope(target,request,response);
                  }
                  finally
                  {
                      tearDownMyScope();
                  }
              }
    
              public void doHandle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
              {
                  try
                  {
                      doMyHandling();
                      super.doHandle(target,request,response);
                  }
                  finally
                  {
                      cleanupMyHandling();
                  }
              }
          }