Class ServletContextHandler
java.lang.Object
- All Implemented Interfaces:
Supplier<Handler>, Handler, HandlerContainer, Attributes, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
- Direct Known Subclasses:
WebAppContext
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 ClassesModifier and TypeClassDescriptionstatic classDeprecated.static classstatic classclassstatic interfacestatic classBean that is added to the ServletContextHandler to start all of the ServletContainerInitializers by starting their corresponding ServletContainerInitializerHolders when this bean is itself started.static classNested classes/interfaces inherited from class ContextHandler
ContextHandler.APIContext, ContextHandler.ContextScopeListener, ContextHandler.ContextStatus, ContextHandler.CoreContextHandler, ContextHandler.CoreContextRequestNested classes/interfaces inherited from class AbstractHandler
AbstractHandler.ErrorDispatchHandlerNested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Attributes
Attributes.Layer, Attributes.Lazy, Attributes.Mapped, Attributes.Synthetic, Attributes.WrapperNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainerNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Class<? extends SecurityHandler> protected javax.servlet.descriptor.JspConfigDescriptorprotected final DecoratedObjectFactoryprotected intprotected SecurityHandlerprotected ServletHandlerprotected SessionHandlerstatic final intstatic final intstatic final intstatic final intFields inherited from class ContextHandler
_apiContext, _contextStatus, DEFAULT_LISTENER_TYPE_INDEX, DEFAULT_MAX_FORM_CONTENT_SIZE, DEFAULT_MAX_FORM_KEYS, ENVIRONMENT, EXTENDED_LISTENER_TYPE_INDEX, MAX_FORM_CONTENT_SIZE_KEY, MAX_FORM_KEYS_KEY, SERVLET_LISTENER_TYPES, SERVLET_MAJOR_VERSION, SERVLET_MINOR_VERSIONFields inherited from class ScopedHandler
_nextScope, _outerScopeFields inherited from class HandlerWrapper
_handlerFields inherited from interface Attributes
NULL -
Constructor Summary
ConstructorsConstructorDescriptionServletContextHandler(int options) ServletContextHandler(Handler.Container parent, String contextPath) ServletContextHandler(Handler.Container parent, String contextPath, boolean sessions, boolean security) ServletContextHandler(Handler.Container parent, String contextPath, int options) ServletContextHandler(Handler.Container parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler) ServletContextHandler(Handler.Container parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler, int options) ServletContextHandler(Handler.Container parent, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler) -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddEventListener(EventListener listener) Add EventListeneraddFilter(Class<? extends javax.servlet.Filter> filterClass, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches) Convenience method to add a filterConvenience method to add a filtervoidaddFilter(FilterHolder holder, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches) Convenience method to add a filterprotected voiddelegate for ServletContext.declareRole methodaddServlet(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.voidaddServlet(ServletHolder servlet, String pathSpec) Convenience method to add a servlet.addServletContainerInitializer(javax.servlet.ServletContainerInitializer sci) Convenience method to programmatically add aServletContainerInitializer.addServletContainerInitializer(javax.servlet.ServletContainerInitializer sci, Class<?>... classes) Convenience method to programmatically add aServletContainerInitializer.voidaddServletContainerInitializer(ServletContainerInitializerHolder... sciHolders) Convenience method to programmatically add a list ofServletContainerInitializer.voidcallContextDestroyed(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e) voidcallContextInitialized(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e) protected voiddoStart()Starts the managed lifecycle beans in the order they were added.protected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.protected javax.servlet.ServletRegistration.DynamicdynamicHolderAdded(ServletHolder holder) notification that a ServletRegistration has been created so we can track the annotationsClass<? extends SecurityHandler> Get the defaultSecurityHandlerClass.The DecoratedObjectFactory for use by IoC containers (weld / spring / etc)static ServletContextHandlergetServletContextHandler(javax.servlet.ServletContext context) static ServletContextHandlergetServletContextHandler(javax.servlet.ServletContext servletContext, String purpose) voidinsertHandler(HandlerWrapper handler) Insert a HandlerWrapper before the first Session, Security or ServletHandler but after any other HandlerWrappers.protected SecurityHandlerprotected ServletHandlerprotected SessionHandlervoidsetDefaultSecurityHandlerClass(Class<? extends SecurityHandler> defaultSecurityHandlerClass) Set the defaultSecurityHandlerClass.voidsetHandler(Handler handler) voidsetSecurityHandler(SecurityHandler securityHandler) voidsetServletHandler(ServletHandler servletHandler) setServletSecurity(javax.servlet.ServletRegistration.Dynamic registration, javax.servlet.ServletSecurityElement servletSecurityElement) Delegate for ServletRegistration.Dynamic.setServletSecurity methodvoidsetSessionHandler(SessionHandler sessionHandler) protected voidFinish constructing handlers and link them together.protected voidMethods inherited from class ContextHandler
addAliasCheck, addLocaleEncoding, addProgrammaticListener, addVirtualHosts, checkAlias, clearAliasChecks, clearAttributes, contextDestroyed, contextInitialized, doHandle, doScope, doStartInContext, doStopInContext, dump, enterScope, exitScope, get, getAliasChecks, getAllowNullPathInfo, getAttribute, getAttributeNames, getAttributeNameSet, getAttributes, getBaseResource, getClassLoader, getClassPath, getContextHandler, getContextPath, getContextPathEncoded, getCoreContextHandler, getCurrentContext, getCurrentContextHandler, getDefaultRequestCharacterEncoding, getDefaultResponseCharacterEncoding, getDisplayName, getErrorHandler, getInitParameter, getInitParameterNames, getInitParams, getLocaleEncoding, getLocaleEncoding, getLocaleEncodings, getLogger, getMaxFormContentSize, getMaxFormKeys, getMimeTypes, getNestedResourceForTempDirName, getProtectedTargets, getRequestContextPath, getResource, getResourceBase, getResourcePaths, getServletContext, getServletContext, getVirtualHosts, getWelcomeFiles, handle, handle, handle, handleAsync, handleCrossContextAsync, handleOptions, insertHandler, isAvailable, isCompactPath, isCrossContextDispatchSupported, isDurableListener, isProgrammaticListener, isProtectedTarget, isUsingSecurityManager, loadClass, newResource, newResource, newResource, removeAttribute, removeEventListener, removeVirtualHosts, requestDestroyed, requestInitialized, setAliasChecks, setAllowNullPathInfo, setAttribute, setAttributes, setAvailable, setBaseResource, setBaseResourceAsPath, setBaseResourceAsString, setClassLoader, setCompactPath, setContextPath, setCrossContextDispatchSupported, setDefaultRequestCharacterEncoding, setDefaultResponseCharacterEncoding, setDisplayName, setErrorHandler, setInitParameter, setLogger, setMaxFormContentSize, setMaxFormKeys, setProtectedTargets, setResourceBase, setServer, setUsingSecurityManager, setVirtualHosts, setWelcomeFiles, toStringMethods inherited from class ScopedHandler
handle, nextHandle, nextScopeMethods inherited from class HandlerWrapper
destroy, expandChildren, getHandler, getHandlers, getTail, setAsParentMethods inherited from class AbstractHandlerContainer
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClassMethods inherited from class AbstractHandler
doError, getServerMethods inherited from class ContainerLifeCycle
addBean, addBean, addManaged, contains, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Attributes
asAttributeMap, equals, hashCodeMethods inherited from interface Container
getCachedBeans, getEventListenersMethods inherited from interface Dumpable.DumpableContainer
isDumpableMethods inherited from interface LifeCycle
isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, start, stop
-
Field Details
-
SESSIONS
public static final int SESSIONS- See Also:
-
SECURITY
public static final int SECURITY- See Also:
-
NO_SESSIONS
public static final int NO_SESSIONS- See Also:
-
NO_SECURITY
public static final int NO_SECURITY- See Also:
-
_objFactory
-
_defaultSecurityHandlerClass
-
_sessionHandler
-
_securityHandler
-
_servletHandler
-
_options
protected int _options -
_jspConfig
protected javax.servlet.descriptor.JspConfigDescriptor _jspConfig
-
-
Constructor Details
-
ServletContextHandler
public ServletContextHandler() -
ServletContextHandler
public ServletContextHandler(int options) -
ServletContextHandler
-
ServletContextHandler
-
ServletContextHandler
public ServletContextHandler(Handler.Container parent, String contextPath, boolean sessions, boolean security) -
ServletContextHandler
public ServletContextHandler(Handler.Container parent, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler) -
ServletContextHandler
public ServletContextHandler(Handler.Container parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler) -
ServletContextHandler
public ServletContextHandler(Handler.Container parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler, int options)
-
-
Method Details
-
getServletContextHandler
public static ServletContextHandler getServletContextHandler(javax.servlet.ServletContext servletContext, String purpose) -
getServletContextHandler
-
addEventListener
Add EventListener- Specified by:
addEventListenerin interfaceContainer- Specified by:
addEventListenerin interfaceLifeCycle- Overrides:
addEventListenerin classContextHandler- Parameters:
listener- the listener to add- Returns:
- true if the listener was added
- See Also:
-
doStart
Description copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classContextHandler- Throws:
Exception- If there was a problem starting. Will cause a transition to FAILED state
-
doStop
Description copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStopin classContextHandler- Throws:
Exception- If there was a problem stopping. Will cause a transition to FAILED state
-
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
-
newSecurityHandler
-
newServletHandler
-
startContext
Finish constructing handlers and link them together.- Overrides:
startContextin classContextHandler- Throws:
Exception- if unable to start the context- See Also:
-
stopContext
- Overrides:
stopContextin classContextHandler- 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
Convenience method to add a servlet.- Parameters:
className- the servlet class namepathSpec- the path spec to map servlet to- Returns:
- the ServletHolder for the added servlet
-
addServlet
Convenience method to add a servlet.- Parameters:
servlet- the servlet classpathSpec- the path spec to map servlet to- Returns:
- the ServletHolder for the added servlet
-
addServlet
Convenience method to add a servlet.- Parameters:
servlet- the servlet holderpathSpec- 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 holderpathSpec- the path specdispatches- 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 classpathSpec- the path specdispatches- 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 namepathSpec- the path specdispatches- 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 aServletContainerInitializer.- 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 aServletContainerInitializer.- Parameters:
sci- the ServletContainerInitializer to register.classes- the Set of application classes.- Returns:
- the ServletContainerInitializerHolder that was created
-
addServletContainerInitializer
Convenience method to programmatically add a list ofServletContainerInitializer. The initializers are guaranteed to be called in the order they are passed into this method.- Parameters:
sciHolders- the ServletContainerInitializerHolders
-
dynamicHolderAdded
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
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 onservletSecurityElement- 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:
callContextInitializedin classContextHandler
-
callContextDestroyed
public void callContextDestroyed(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e) - Overrides:
callContextDestroyedin classContextHandler
-
setSessionHandler
- Parameters:
sessionHandler- The sessionHandler to set.
-
setSecurityHandler
- Parameters:
securityHandler- TheSecurityHandlerto set on this context.
-
setServletHandler
- Parameters:
servletHandler- The servletHandler to set.
-
setHandler
- Overrides:
setHandlerin classHandlerWrapper- Parameters:
handler- Set theHandlerwhich should be wrapped.
-
insertHandler
Insert a HandlerWrapper before the first Session, Security or ServletHandler but after any other HandlerWrappers.- Overrides:
insertHandlerin classHandlerWrapper- Parameters:
handler- the wrapper to insert
-
getObjectFactory
The DecoratedObjectFactory for use by IoC containers (weld / spring / etc)- Returns:
- The DecoratedObjectFactory
-