Class ServletContextHandler

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.server.handler.AbstractHandler
org.eclipse.jetty.server.handler.AbstractHandlerContainer
org.eclipse.jetty.server.handler.HandlerWrapper
org.eclipse.jetty.server.handler.ScopedHandler
org.eclipse.jetty.server.handler.ContextHandler
org.eclipse.jetty.servlet.ServletContextHandler
All Implemented Interfaces:
org.eclipse.jetty.server.Handler, org.eclipse.jetty.server.HandlerContainer, org.eclipse.jetty.util.Attributes, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.Graceful, org.eclipse.jetty.util.component.LifeCycle

@ManagedObject("Servlet Context Handler") public class ServletContextHandler extends org.eclipse.jetty.server.handler.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.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
     
    static interface 
    Deprecated.
    use new Decorator
    static class 
    A utility class to hold a ServletContainerInitializer and implement the ServletContextHandler.ServletContainerInitializerCaller interface so that the SCI is correctly started if an instance of this class is added as a bean to a ServletContextHandler.
    static class 
     
    static class 
     
    static interface 
     
    static class 
     

    Nested classes/interfaces inherited from class org.eclipse.jetty.server.handler.ContextHandler

    org.eclipse.jetty.server.handler.ContextHandler.AliasCheck, org.eclipse.jetty.server.handler.ContextHandler.ApproveAliases, org.eclipse.jetty.server.handler.ContextHandler.ApproveNonExistentDirectoryAliases, org.eclipse.jetty.server.handler.ContextHandler.Availability, org.eclipse.jetty.server.handler.ContextHandler.ContextScopeListener, org.eclipse.jetty.server.handler.ContextHandler.ContextStatus, org.eclipse.jetty.server.handler.ContextHandler.StaticContext

    Nested classes/interfaces inherited from class org.eclipse.jetty.server.handler.AbstractHandler

    org.eclipse.jetty.server.handler.AbstractHandler.ErrorDispatchHandler

    Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Attributes

    org.eclipse.jetty.util.Attributes.Wrapper

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container

    org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable

    org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Graceful

    org.eclipse.jetty.util.component.Graceful.Shutdown

    Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

    org.eclipse.jetty.util.component.LifeCycle.Listener
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Class<? extends SecurityHandler>
     
    protected org.eclipse.jetty.server.handler.gzip.GzipHandler
     
    protected javax.servlet.descriptor.JspConfigDescriptor
     
    protected final org.eclipse.jetty.util.DecoratedObjectFactory
     
    protected int
     
    protected SecurityHandler
     
    protected ServletHandler
     
    protected org.eclipse.jetty.server.session.SessionHandler
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     

    Fields inherited from class org.eclipse.jetty.server.handler.ContextHandler

    _contextStatus, _scontext, DEFAULT_LISTENER_TYPE_INDEX, DEFAULT_MAX_FORM_CONTENT_SIZE, DEFAULT_MAX_FORM_KEYS, EXTENDED_LISTENER_TYPE_INDEX, MANAGED_ATTRIBUTES, MAX_FORM_CONTENT_SIZE_KEY, MAX_FORM_KEYS_KEY, SERVLET_LISTENER_TYPES, SERVLET_MAJOR_VERSION, SERVLET_MINOR_VERSION

    Fields inherited from class org.eclipse.jetty.server.handler.ScopedHandler

    _nextScope, _outerScope

    Fields inherited from class org.eclipse.jetty.server.handler.HandlerWrapper

    _handler

    Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING

    Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

    KEY
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    ServletContextHandler(int options)
     
    ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, String contextPath)
     
    ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, String contextPath, boolean sessions, boolean security)
     
    ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, String contextPath, int options)
     
    ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, String contextPath, org.eclipse.jetty.server.session.SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, org.eclipse.jetty.server.handler.ErrorHandler errorHandler)
     
    ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, String contextPath, org.eclipse.jetty.server.session.SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, org.eclipse.jetty.server.handler.ErrorHandler errorHandler, int options)
     
    ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, org.eclipse.jetty.server.session.SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, org.eclipse.jetty.server.handler.ErrorHandler errorHandler)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deprecated.
    use the DecoratedObjectFactory from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") or getObjectFactory() instead
    void
    Add EventListener Adds an EventListener to the list.
    addFilter(Class<? extends javax.servlet.Filter> filterClass, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches)
    Convenience method to add a filter
    addFilter(String filterClass, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches)
    Convenience method to add a filter
    void
    addFilter(FilterHolder holder, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches)
    Convenience method to add a filter
    protected void
    addRoles(String... roleNames)
    delegate for ServletContext.declareRole method
    addServlet(Class<? extends javax.servlet.Servlet> servlet, String pathSpec)
    Convenience method to add a servlet.
    addServlet(String className, String pathSpec)
    Convenience method to add a servlet.
    void
    addServlet(ServletHolder servlet, String pathSpec)
    Convenience method to add a servlet.
    void
    callContextDestroyed(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)
     
    void
    callContextInitialized(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e)
     
    protected void
     
    protected void
     
    protected javax.servlet.ServletRegistration.Dynamic
    notification that a ServletRegistration has been created so we can track the annotations
    Deprecated.
    use the DecoratedObjectFactory from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") or getObjectFactory() instead
    Get the defaultSecurityHandlerClass.
    org.eclipse.jetty.server.handler.gzip.GzipHandler
     
    org.eclipse.jetty.util.DecoratedObjectFactory
    The DecoratedObjectFactory for use by IoC containers (weld / spring / etc)
     
    getServletContextHandler(javax.servlet.ServletContext context)
     
     
    org.eclipse.jetty.server.session.SessionHandler
     
    void
    insertHandler(org.eclipse.jetty.server.handler.HandlerWrapper handler)
    Insert a HandlerWrapper before the first Session,Security or ServletHandler but after any other HandlerWrappers.
    protected SecurityHandler
     
    protected ServletHandler
     
    protected org.eclipse.jetty.server.session.SessionHandler
     
    void
    Deprecated.
    use the DecoratedObjectFactory from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") or getObjectFactory() instead
    void
    setDefaultSecurityHandlerClass(Class<? extends SecurityHandler> defaultSecurityHandlerClass)
    Set the defaultSecurityHandlerClass.
    void
    setGzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler gzipHandler)
     
    void
    setHandler(org.eclipse.jetty.server.Handler handler)
     
    void
     
    void
     
    setServletSecurity(javax.servlet.ServletRegistration.Dynamic registration, javax.servlet.ServletSecurityElement servletSecurityElement)
    Delegate for ServletRegistration.Dynamic.setServletSecurity method
    void
    setSessionHandler(org.eclipse.jetty.server.session.SessionHandler sessionHandler)
     
    protected void
    Finish constructing handlers and link them together.
    protected void
     

    Methods inherited from class org.eclipse.jetty.server.handler.ContextHandler

    addAliasCheck, addLocaleEncoding, addProgrammaticListener, addVirtualHosts, checkAlias, checkContext, checkContextPath, checkVirtualHost, clearAliasChecks, clearAttributes, contextDestroyed, contextInitialized, doHandle, doScope, dump, enterScope, exitScope, getAliasChecks, getAllowNullPathInfo, getAttribute, getAttributeNames, getAttributeNameSet, getAttributes, getBaseResource, getClassLoader, getClassPath, getContextHandler, getContextPath, getContextPathEncoded, getCurrentContext, getDisplayName, getErrorHandler, getEventListeners, getInitParameter, getInitParameterNames, getInitParams, getLocaleEncoding, getLocaleEncoding, getLocaleEncodings, getLogger, getMaxFormContentSize, getMaxFormKeys, getMimeTypes, getProtectedTargets, getRequestContextPath, getResource, getResourceBase, getResourcePaths, getServerInfo, getServletContext, getVirtualHosts, getWelcomeFiles, handle, handle, isAvailable, isCompactPath, isDurableListener, isProgrammaticListener, isProtectedTarget, isShutdown, isUsingSecurityManager, loadClass, newResource, newResource, newResource, removeAttribute, removeEventListener, removeVirtualHosts, requestDestroyed, requestInitialized, setAliasChecks, setAllowNullPathInfo, setAttribute, setAttributes, setAvailable, setBaseResource, setClassLoader, setCompactPath, setContextPath, setDisplayName, setErrorHandler, setEventListeners, setInitParameter, setLogger, setManagedAttribute, setMaxFormContentSize, setMaxFormKeys, setMimeTypes, setProtectedTargets, setResourceBase, setServer, setServerInfo, setUsingSecurityManager, setVirtualHosts, setWelcomeFiles, shutdown, toString

    Methods inherited from class org.eclipse.jetty.server.handler.ScopedHandler

    handle, nextHandle, nextScope

    Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper

    destroy, expandChildren, getHandler, getHandlers

    Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer

    doShutdown, expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass

    Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler

    doError, getServer

    Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle

    addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans

    Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

    addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable

    dumpSelf

    Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer

    isDumpable

    Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle

    addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
  • Field Details

    • SESSIONS

      public static final int SESSIONS
      See Also:
    • SECURITY

      public static final int SECURITY
      See Also:
    • GZIP

      public static final int GZIP
      See Also:
    • NO_SESSIONS

      public static final int NO_SESSIONS
      See Also:
    • NO_SECURITY

      public static final int NO_SECURITY
      See Also:
    • _objFactory

      protected final org.eclipse.jetty.util.DecoratedObjectFactory _objFactory
    • _defaultSecurityHandlerClass

      protected Class<? extends SecurityHandler> _defaultSecurityHandlerClass
    • _sessionHandler

      protected org.eclipse.jetty.server.session.SessionHandler _sessionHandler
    • _securityHandler

      protected SecurityHandler _securityHandler
    • _servletHandler

      protected ServletHandler _servletHandler
    • _gzipHandler

      protected org.eclipse.jetty.server.handler.gzip.GzipHandler _gzipHandler
    • _options

      protected int _options
    • _jspConfig

      protected javax.servlet.descriptor.JspConfigDescriptor _jspConfig
  • Constructor Details

    • ServletContextHandler

      public ServletContextHandler()
    • ServletContextHandler

      public ServletContextHandler(int options)
    • ServletContextHandler

      public ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, String contextPath)
    • ServletContextHandler

      public ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, String contextPath, int options)
    • ServletContextHandler

      public ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, String contextPath, boolean sessions, boolean security)
    • ServletContextHandler

      public ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, org.eclipse.jetty.server.session.SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, org.eclipse.jetty.server.handler.ErrorHandler errorHandler)
    • ServletContextHandler

      public ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, String contextPath, org.eclipse.jetty.server.session.SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, org.eclipse.jetty.server.handler.ErrorHandler errorHandler)
    • ServletContextHandler

      public ServletContextHandler(org.eclipse.jetty.server.HandlerContainer parent, String contextPath, org.eclipse.jetty.server.session.SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, org.eclipse.jetty.server.handler.ErrorHandler errorHandler, int options)
  • Method Details

    • addEventListener

      public void addEventListener(EventListener listener)
      Add EventListener Adds an EventListener to the list. @see org.eclipse.jetty.server.handler.ContextHandler#addEventListener(). Also adds any listeners that are session related to the SessionHandler.
      Overrides:
      addEventListener in class org.eclipse.jetty.server.handler.ContextHandler
      Parameters:
      listener - the listener to add
    • setHandler

      public void setHandler(org.eclipse.jetty.server.Handler handler)
      Overrides:
      setHandler in class org.eclipse.jetty.server.handler.HandlerWrapper
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class org.eclipse.jetty.server.handler.ContextHandler
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.eclipse.jetty.server.handler.ContextHandler
      Throws:
      Exception
      See Also:
      • ContextHandler.doStop()
    • 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 org.eclipse.jetty.server.session.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 org.eclipse.jetty.server.handler.ContextHandler
      Throws:
      Exception
      See Also:
      • ContextHandler.startContext()
    • stopContext

      protected void stopContext() throws Exception
      Overrides:
      stopContext in class org.eclipse.jetty.server.handler.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 org.eclipse.jetty.server.session.SessionHandler getSessionHandler()
      Returns:
      Returns the sessionHandler.
    • getGzipHandler

      @ManagedAttribute(value="context gzip handler", readonly=true) public org.eclipse.jetty.server.handler.gzip.GzipHandler getGzipHandler()
      Returns:
      Returns the gzipHandler.
    • 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
    • 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 org.eclipse.jetty.server.handler.ContextHandler
    • callContextDestroyed

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

      public void setSessionHandler(org.eclipse.jetty.server.session.SessionHandler sessionHandler)
      Parameters:
      sessionHandler - The sessionHandler to set.
    • setSecurityHandler

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

      public void setGzipHandler(org.eclipse.jetty.server.handler.gzip.GzipHandler gzipHandler)
      Parameters:
      gzipHandler - The GzipHandler to set on this context.
    • setServletHandler

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

      public void insertHandler(org.eclipse.jetty.server.handler.HandlerWrapper handler)
      Insert a HandlerWrapper before the first Session,Security or ServletHandler but after any other HandlerWrappers.
      Overrides:
      insertHandler in class org.eclipse.jetty.server.handler.HandlerWrapper
    • getObjectFactory

      public org.eclipse.jetty.util.DecoratedObjectFactory getObjectFactory()
      The DecoratedObjectFactory for use by IoC containers (weld / spring / etc)
      Returns:
      The DecoratedObjectFactory
    • getDecorators

      Deprecated.
      use the DecoratedObjectFactory from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") or getObjectFactory() instead
      Returns:
      The decorator list used to resource inject new Filters, Servlets and EventListeners
    • setDecorators

      @Deprecated public void setDecorators(List<ServletContextHandler.Decorator> decorators)
      Deprecated.
      use the DecoratedObjectFactory from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") or getObjectFactory() instead
      Parameters:
      decorators - The list of ServletContextHandler.Decorators
    • addDecorator

      @Deprecated public void addDecorator(ServletContextHandler.Decorator decorator)
      Deprecated.
      use the DecoratedObjectFactory from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") or getObjectFactory() instead
      Parameters:
      decorator - The decorator to add
    • getServletContextHandler

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