Class ServletContextHandler

All Implemented Interfaces:
Handler, HandlerContainer, Attributes, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, Graceful, LifeCycle
Direct Known Subclasses:
WebAppContext

@ManagedObject("Servlet Context Handler") public class ServletContextHandler extends ContextHandler
Servlet Context.

This extension to the ContextHandler allows for simple construction of a context with ServletHandler and optionally session and security handlers, et.

   new ServletContext("/context",Context.SESSIONS|Context.NO_SECURITY);
 

This class should have been called ServletContext, but this would have cause confusion with ServletContext.

  • Field Details

  • Constructor Details

  • Method Details

    • getServletContextHandler

      public static ServletContextHandler getServletContextHandler(javax.servlet.ServletContext servletContext, String purpose)
    • getServletContextHandler

      public static ServletContextHandler getServletContextHandler(javax.servlet.ServletContext context)
    • setParent

      protected void setParent(HandlerContainer parent)
    • addEventListener

      public boolean addEventListener(EventListener listener)
      Add EventListener
      Specified by:
      addEventListener in interface Container
      Specified by:
      addEventListener in interface LifeCycle
      Overrides:
      addEventListener in class ContextHandler
      Parameters:
      listener - the listener to add
      Returns:
      true if the listener was added
      See Also:
    • setHandler

      public void setHandler(Handler handler)
      Overrides:
      setHandler in class HandlerWrapper
      Parameters:
      handler - Set the Handler which should be wrapped.
    • doStart

      protected void doStart() throws Exception
      Description copied from class: ContainerLifeCycle
      Starts the managed lifecycle beans in the order they were added.
      Overrides:
      doStart in class ContextHandler
      Throws:
      AbstractLifeCycle.StopException - If thrown, the lifecycle will immediately be stopped.
      Exception - If there was a problem starting. Will cause a transition to FAILED state
    • doStop

      protected void doStop() throws Exception
      Description copied from class: ContainerLifeCycle
      Stops the managed lifecycle beans in the reverse order they were added.
      Overrides:
      doStop in class ContextHandler
      Throws:
      Exception - If there was a problem stopping. Will cause a transition to FAILED state
    • getDefaultSecurityHandlerClass

      public Class<? extends SecurityHandler> getDefaultSecurityHandlerClass()
      Get the defaultSecurityHandlerClass.
      Returns:
      the defaultSecurityHandlerClass
    • setDefaultSecurityHandlerClass

      public void setDefaultSecurityHandlerClass(Class<? extends SecurityHandler> defaultSecurityHandlerClass)
      Set the defaultSecurityHandlerClass.
      Parameters:
      defaultSecurityHandlerClass - the defaultSecurityHandlerClass to set
    • newSessionHandler

      protected SessionHandler newSessionHandler()
    • newSecurityHandler

      protected SecurityHandler newSecurityHandler()
    • newServletHandler

      protected ServletHandler newServletHandler()
    • startContext

      protected void startContext() throws Exception
      Finish constructing handlers and link them together.
      Overrides:
      startContext in class ContextHandler
      Throws:
      Exception - if unable to start the context
      See Also:
    • stopContext

      protected void stopContext() throws Exception
      Overrides:
      stopContext in class ContextHandler
      Throws:
      Exception
    • getSecurityHandler

      @ManagedAttribute(value="context security handler", readonly=true) public SecurityHandler getSecurityHandler()
      Returns:
      Returns the securityHandler.
    • getServletHandler

      @ManagedAttribute(value="context servlet handler", readonly=true) public ServletHandler getServletHandler()
      Returns:
      Returns the servletHandler.
    • getSessionHandler

      @ManagedAttribute(value="context session handler", readonly=true) public SessionHandler getSessionHandler()
      Returns:
      Returns the sessionHandler.
    • addServlet

      public ServletHolder addServlet(String className, String pathSpec)
      Convenience method to add a servlet.
      Parameters:
      className - the servlet class name
      pathSpec - the path spec to map servlet to
      Returns:
      the ServletHolder for the added servlet
    • addServlet

      public ServletHolder addServlet(Class<? extends javax.servlet.Servlet> servlet, String pathSpec)
      Convenience method to add a servlet.
      Parameters:
      servlet - the servlet class
      pathSpec - the path spec to map servlet to
      Returns:
      the ServletHolder for the added servlet
    • addServlet

      public void addServlet(ServletHolder servlet, String pathSpec)
      Convenience method to add a servlet.
      Parameters:
      servlet - the servlet holder
      pathSpec - the path spec
    • addFilter

      public void addFilter(FilterHolder holder, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches)
      Convenience method to add a filter
      Parameters:
      holder - the filter holder
      pathSpec - the path spec
      dispatches - the dispatcher types for this filter
    • addFilter

      public FilterHolder addFilter(Class<? extends javax.servlet.Filter> filterClass, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches)
      Convenience method to add a filter
      Parameters:
      filterClass - the filter class
      pathSpec - the path spec
      dispatches - the dispatcher types for this filter
      Returns:
      the FilterHolder that was created
    • addFilter

      public FilterHolder addFilter(String filterClass, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches)
      Convenience method to add a filter
      Parameters:
      filterClass - the filter class name
      pathSpec - the path spec
      dispatches - the dispatcher types for this filter
      Returns:
      the FilterHolder that was created
    • addServletContainerInitializer

      public ServletContainerInitializerHolder addServletContainerInitializer(javax.servlet.ServletContainerInitializer sci)
      Convenience method to programmatically add a ServletContainerInitializer.
      Parameters:
      sci - the ServletContainerInitializer to register.
      Returns:
      the ServletContainerInitializerHolder that was created
    • addServletContainerInitializer

      public ServletContainerInitializerHolder addServletContainerInitializer(javax.servlet.ServletContainerInitializer sci, Class<?>... classes)
      Convenience method to programmatically add a ServletContainerInitializer.
      Parameters:
      sci - the ServletContainerInitializer to register.
      classes - the Set of application classes.
      Returns:
      the ServletContainerInitializerHolder that was created
    • addServletContainerInitializer

      public void addServletContainerInitializer(ServletContainerInitializerHolder... sciHolders)
      Convenience method to programmatically add a list of ServletContainerInitializer. The initializers are guaranteed to be called in the order they are passed into this method.
      Parameters:
      sciHolders - the ServletContainerInitializerHolders
    • dynamicHolderAdded

      protected javax.servlet.ServletRegistration.Dynamic dynamicHolderAdded(ServletHolder holder)
      notification that a ServletRegistration has been created so we can track the annotations
      Parameters:
      holder - new holder created through the api.
      Returns:
      the ServletRegistration.Dynamic
    • addRoles

      protected void addRoles(String... roleNames)
      delegate for ServletContext.declareRole method
      Parameters:
      roleNames - role names to add
    • setServletSecurity

      public Set<String> setServletSecurity(javax.servlet.ServletRegistration.Dynamic registration, javax.servlet.ServletSecurityElement servletSecurityElement)
      Delegate for ServletRegistration.Dynamic.setServletSecurity method
      Parameters:
      registration - ServletRegistration.Dynamic instance that setServletSecurity was called on
      servletSecurityElement - new security info
      Returns:
      the set of exact URL mappings currently associated with the registration that are also present in the web.xml security constraints and thus will be unaffected by this call.
    • callContextInitialized

      public void callContextInitialized(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)
      Overrides:
      callContextInitialized in class ContextHandler
    • callContextDestroyed

      public void callContextDestroyed(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)
      Overrides:
      callContextDestroyed in class ContextHandler
    • setSessionHandler

      public void setSessionHandler(SessionHandler sessionHandler)
      Parameters:
      sessionHandler - The sessionHandler to set.
    • setSecurityHandler

      public void setSecurityHandler(SecurityHandler securityHandler)
      Parameters:
      securityHandler - The SecurityHandler to set on this context.
    • setServletHandler

      public void setServletHandler(ServletHandler servletHandler)
      Parameters:
      servletHandler - The servletHandler to set.
    • setGzipHandler

      @Deprecated public void setGzipHandler(GzipHandler gzipHandler)
      Deprecated.
      Parameters:
      gzipHandler - the GzipHandler for this ServletContextHandler
    • insertHandler

      public void insertHandler(HandlerWrapper handler)
      Insert a HandlerWrapper before the first Session, Security or ServletHandler but after any other HandlerWrappers.
      Overrides:
      insertHandler in class HandlerWrapper
      Parameters:
      handler - the wrapper to insert
    • getObjectFactory

      public DecoratedObjectFactory getObjectFactory()
      The DecoratedObjectFactory for use by IoC containers (weld / spring / etc)
      Returns:
      The DecoratedObjectFactory