Package org.eclipse.jetty.servlet
Class ServletContextHandler
- java.lang.Object
-
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classServletContextHandler.Contextstatic interfaceServletContextHandler.DecoratorDeprecated.use newDecoratorstatic classServletContextHandler.InitializerA utility class to hold aServletContainerInitializerand implement theServletContextHandler.ServletContainerInitializerCallerinterface so that the SCI is correctly started if an instance of this class is added as a bean to aServletContextHandler.static classServletContextHandler.JspConfigstatic classServletContextHandler.JspPropertyGroupstatic interfaceServletContextHandler.ServletContainerInitializerCallerstatic classServletContextHandler.TagLib-
Nested classes/interfaces inherited from class org.eclipse.jetty.server.handler.ContextHandler
ContextHandler.AliasCheck, ContextHandler.ApproveAliases, ContextHandler.ApproveNonExistentDirectoryAliases, ContextHandler.Availability, ContextHandler.ContextScopeListener, ContextHandler.ContextStatus, ContextHandler.StaticContext
-
Nested classes/interfaces inherited from class org.eclipse.jetty.server.handler.AbstractHandler
AbstractHandler.ErrorDispatchHandler
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Attributes
Attributes.Wrapper
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Graceful
Graceful.Shutdown
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class<? extends SecurityHandler>_defaultSecurityHandlerClassprotected GzipHandler_gzipHandlerprotected javax.servlet.descriptor.JspConfigDescriptor_jspConfigprotected DecoratedObjectFactory_objFactoryprotected int_optionsprotected SecurityHandler_securityHandlerprotected ServletHandler_servletHandlerprotected SessionHandler_sessionHandlerstatic intGZIPstatic intNO_SECURITYstatic intNO_SESSIONSstatic intSECURITYstatic intSESSIONS-
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
-
-
Constructor Summary
Constructors Constructor Description ServletContextHandler()ServletContextHandler(int options)ServletContextHandler(HandlerContainer parent, java.lang.String contextPath)ServletContextHandler(HandlerContainer parent, java.lang.String contextPath, boolean sessions, boolean security)ServletContextHandler(HandlerContainer parent, java.lang.String contextPath, int options)ServletContextHandler(HandlerContainer parent, java.lang.String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)ServletContextHandler(HandlerContainer parent, java.lang.String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler, int options)ServletContextHandler(HandlerContainer parent, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddDecorator(ServletContextHandler.Decorator decorator)Deprecated.use theDecoratedObjectFactoryfrom getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()insteadvoidaddEventListener(java.util.EventListener listener)Add EventListener Adds an EventListener to the list.FilterHolderaddFilter(java.lang.Class<? extends javax.servlet.Filter> filterClass, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)Convenience method to add a filterFilterHolderaddFilter(java.lang.String filterClass, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)Convenience method to add a filtervoidaddFilter(FilterHolder holder, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)Convenience method to add a filterprotected voidaddRoles(java.lang.String... roleNames)delegate for ServletContext.declareRole methodServletHolderaddServlet(java.lang.Class<? extends javax.servlet.Servlet> servlet, java.lang.String pathSpec)Convenience method to add a servlet.ServletHolderaddServlet(java.lang.String className, java.lang.String pathSpec)Convenience method to add a servlet.voidaddServlet(ServletHolder servlet, java.lang.String pathSpec)Convenience method to add a servlet.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 annotationsjava.util.List<ServletContextHandler.Decorator>getDecorators()Deprecated.use theDecoratedObjectFactoryfrom getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()insteadjava.lang.Class<? extends SecurityHandler>getDefaultSecurityHandlerClass()Get the defaultSecurityHandlerClass.GzipHandlergetGzipHandler()DecoratedObjectFactorygetObjectFactory()The DecoratedObjectFactory for use by IoC containers (weld / spring / etc)SecurityHandlergetSecurityHandler()static ServletContextHandlergetServletContextHandler(javax.servlet.ServletContext context)ServletHandlergetServletHandler()SessionHandlergetSessionHandler()voidinsertHandler(HandlerWrapper handler)Insert a HandlerWrapper before the first Session,Security or ServletHandler but after any other HandlerWrappers.protected SecurityHandlernewSecurityHandler()protected ServletHandlernewServletHandler()protected SessionHandlernewSessionHandler()voidsetDecorators(java.util.List<ServletContextHandler.Decorator> decorators)Deprecated.use theDecoratedObjectFactoryfrom getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()insteadvoidsetDefaultSecurityHandlerClass(java.lang.Class<? extends SecurityHandler> defaultSecurityHandlerClass)Set the defaultSecurityHandlerClass.voidsetGzipHandler(GzipHandler gzipHandler)voidsetHandler(Handler handler)voidsetSecurityHandler(SecurityHandler securityHandler)voidsetServletHandler(ServletHandler servletHandler)java.util.Set<java.lang.String>setServletSecurity(javax.servlet.ServletRegistration.Dynamic registration, javax.servlet.ServletSecurityElement servletSecurityElement)Delegate for ServletRegistration.Dynamic.setServletSecurity methodvoidsetSessionHandler(SessionHandler sessionHandler)protected voidstartContext()Finish constructing handlers and link them together.protected voidstopContext()-
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.DumpableContainer
isDumpable
-
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
-
-
-
Field Detail
-
SESSIONS
public static final int SESSIONS
- See Also:
- Constant Field Values
-
SECURITY
public static final int SECURITY
- See Also:
- Constant Field Values
-
GZIP
public static final int GZIP
- See Also:
- Constant Field Values
-
NO_SESSIONS
public static final int NO_SESSIONS
- See Also:
- Constant Field Values
-
NO_SECURITY
public static final int NO_SECURITY
- See Also:
- Constant Field Values
-
_objFactory
protected final DecoratedObjectFactory _objFactory
-
_defaultSecurityHandlerClass
protected java.lang.Class<? extends SecurityHandler> _defaultSecurityHandlerClass
-
_sessionHandler
protected SessionHandler _sessionHandler
-
_securityHandler
protected SecurityHandler _securityHandler
-
_servletHandler
protected ServletHandler _servletHandler
-
_gzipHandler
protected GzipHandler _gzipHandler
-
_options
protected int _options
-
_jspConfig
protected javax.servlet.descriptor.JspConfigDescriptor _jspConfig
-
-
Constructor Detail
-
ServletContextHandler
public ServletContextHandler()
-
ServletContextHandler
public ServletContextHandler(int options)
-
ServletContextHandler
public ServletContextHandler(HandlerContainer parent, java.lang.String contextPath)
-
ServletContextHandler
public ServletContextHandler(HandlerContainer parent, java.lang.String contextPath, int options)
-
ServletContextHandler
public ServletContextHandler(HandlerContainer parent, java.lang.String contextPath, boolean sessions, boolean security)
-
ServletContextHandler
public ServletContextHandler(HandlerContainer parent, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
-
ServletContextHandler
public ServletContextHandler(HandlerContainer parent, java.lang.String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
-
ServletContextHandler
public ServletContextHandler(HandlerContainer parent, java.lang.String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler, int options)
-
-
Method Detail
-
addEventListener
public void addEventListener(java.util.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:
addEventListenerin classContextHandler- Parameters:
listener- the listener to add- See Also:
ServletContextListener,ServletContextAttributeListener,ServletRequestListener,ServletRequestAttributeListener
-
setHandler
public void setHandler(Handler handler)
- Overrides:
setHandlerin classHandlerWrapper- Parameters:
handler- Set theHandlerwhich should be wrapped.
-
doStart
protected void doStart() throws java.lang.ExceptionDescription copied from class:ContainerLifeCycleStarts the managed lifecycle beans in the order they were added.- Overrides:
doStartin classContextHandler- Throws:
java.lang.Exception- See Also:
AbstractHandler.doStart()
-
doStop
protected void doStop() throws java.lang.ExceptionDescription copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStopin classContextHandler- Throws:
java.lang.Exception- See Also:
ContextHandler.doStop()
-
getDefaultSecurityHandlerClass
public java.lang.Class<? extends SecurityHandler> getDefaultSecurityHandlerClass()
Get the defaultSecurityHandlerClass.- Returns:
- the defaultSecurityHandlerClass
-
setDefaultSecurityHandlerClass
public void setDefaultSecurityHandlerClass(java.lang.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 java.lang.ExceptionFinish constructing handlers and link them together.- Overrides:
startContextin classContextHandler- Throws:
java.lang.Exception- if unable to start the context- See Also:
ContextHandler.startContext()
-
stopContext
protected void stopContext() throws java.lang.Exception- Overrides:
stopContextin classContextHandler- Throws:
java.lang.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.
-
getGzipHandler
@ManagedAttribute(value="context gzip handler", readonly=true) public GzipHandler getGzipHandler()
- Returns:
- Returns the gzipHandler.
-
addServlet
public ServletHolder addServlet(java.lang.String className, java.lang.String pathSpec)
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
public ServletHolder addServlet(java.lang.Class<? extends javax.servlet.Servlet> servlet, java.lang.String pathSpec)
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
public void addServlet(ServletHolder servlet, java.lang.String pathSpec)
Convenience method to add a servlet.- Parameters:
servlet- the servlet holderpathSpec- the path spec
-
addFilter
public void addFilter(FilterHolder holder, java.lang.String pathSpec, java.util.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(java.lang.Class<? extends javax.servlet.Filter> filterClass, java.lang.String pathSpec, java.util.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(java.lang.String filterClass, java.lang.String pathSpec, java.util.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
-
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(java.lang.String... roleNames)
delegate for ServletContext.declareRole method- Parameters:
roleNames- role names to add
-
setServletSecurity
public java.util.Set<java.lang.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
public void setSessionHandler(SessionHandler sessionHandler)
- Parameters:
sessionHandler- The sessionHandler to set.
-
setSecurityHandler
public void setSecurityHandler(SecurityHandler securityHandler)
- Parameters:
securityHandler- TheSecurityHandlerto set on this context.
-
setGzipHandler
public void setGzipHandler(GzipHandler gzipHandler)
- Parameters:
gzipHandler- TheGzipHandlerto set on this context.
-
setServletHandler
public void setServletHandler(ServletHandler servletHandler)
- Parameters:
servletHandler- The servletHandler to set.
-
insertHandler
public void insertHandler(HandlerWrapper handler)
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
public DecoratedObjectFactory getObjectFactory()
The DecoratedObjectFactory for use by IoC containers (weld / spring / etc)- Returns:
- The DecoratedObjectFactory
-
getDecorators
@Deprecated public java.util.List<ServletContextHandler.Decorator> getDecorators()
Deprecated.use theDecoratedObjectFactoryfrom getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()instead- Returns:
- The decorator list used to resource inject new Filters, Servlets and EventListeners
-
setDecorators
@Deprecated public void setDecorators(java.util.List<ServletContextHandler.Decorator> decorators)
Deprecated.use theDecoratedObjectFactoryfrom getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()instead- Parameters:
decorators- The list ofServletContextHandler.Decorators
-
addDecorator
@Deprecated public void addDecorator(ServletContextHandler.Decorator decorator)
Deprecated.use theDecoratedObjectFactoryfrom getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()instead- Parameters:
decorator- The decorator to add
-
getServletContextHandler
public static ServletContextHandler getServletContextHandler(javax.servlet.ServletContext context)
-
-