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
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 TypeClassDescriptionclass
static interface
Deprecated.static class
A utility class to hold aServletContainerInitializer
and implement theServletContextHandler.ServletContainerInitializerCaller
interface so that the SCI is correctly started if an instance of this class is added as a bean to aServletContextHandler
.static class
static class
private static class
Implementation of the legacy interface to decorate loaded classes.static interface
static class
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
FieldsModifier and TypeFieldDescriptionprotected Class<? extends SecurityHandler>
protected GzipHandler
protected javax.servlet.descriptor.JspConfigDescriptor
protected final DecoratedObjectFactory
protected int
protected SecurityHandler
protected ServletHandler
protected SessionHandler
private boolean
static final int
private static final Logger
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
-
Constructor Summary
ConstructorsConstructorDescriptionServletContextHandler
(int options) ServletContextHandler
(HandlerContainer parent, String contextPath) ServletContextHandler
(HandlerContainer parent, String contextPath, boolean sessions, boolean security) ServletContextHandler
(HandlerContainer parent, String contextPath, int options) ServletContextHandler
(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler) ServletContextHandler
(HandlerContainer parent, 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
Modifier and TypeMethodDescriptionvoid
addDecorator
(ServletContextHandler.Decorator decorator) Deprecated.use theDecoratedObjectFactory
from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()
insteadvoid
addEventListener
(EventListener listener) 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 filterConvenience method to add a filtervoid
addFilter
(FilterHolder holder, String pathSpec, EnumSet<javax.servlet.DispatcherType> dispatches) Convenience method to add a filterprotected void
delegate 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.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) (package private) void
destroyFilter
(javax.servlet.Filter filter) (package private) void
destroyListener
(EventListener listener) (package private) void
destroyServlet
(javax.servlet.Servlet servlet) private void
doSetHandler
(HandlerWrapper wrapper, Handler handler) protected void
doStart()
Starts the managed lifecycle beans in the order they were added.protected void
doStop()
Stops the managed lifecycle beans in the reverse order they were added.protected javax.servlet.ServletRegistration.Dynamic
dynamicHolderAdded
(ServletHolder holder) notification that a ServletRegistration has been created so we can track the annotationsDeprecated.use theDecoratedObjectFactory
from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()
insteadClass<? extends SecurityHandler>
Get the defaultSecurityHandlerClass.The DecoratedObjectFactory for use by IoC containers (weld / spring / etc)static ServletContextHandler
getServletContextHandler
(javax.servlet.ServletContext context) void
insertHandler
(HandlerWrapper handler) Insert a HandlerWrapper before the first Session,Security or ServletHandler but after any other HandlerWrappers.protected SecurityHandler
protected ServletHandler
protected SessionHandler
private void
private void
replaceHandler
(HandlerWrapper handler, HandlerWrapper replacement) void
setDecorators
(List<ServletContextHandler.Decorator> decorators) Deprecated.use theDecoratedObjectFactory
from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()
insteadvoid
setDefaultSecurityHandlerClass
(Class<? extends SecurityHandler> defaultSecurityHandlerClass) Set the defaultSecurityHandlerClass.void
setGzipHandler
(GzipHandler gzipHandler) void
setHandler
(Handler handler) void
setSecurityHandler
(SecurityHandler securityHandler) void
setServletHandler
(ServletHandler servletHandler) setServletSecurity
(javax.servlet.ServletRegistration.Dynamic registration, javax.servlet.ServletSecurityElement servletSecurityElement) Delegate for ServletRegistration.Dynamic.setServletSecurity methodvoid
setSessionHandler
(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.DumpableContainer
isDumpable
Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Field Details
-
LOG
-
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
-
_defaultSecurityHandlerClass
-
_sessionHandler
-
_securityHandler
-
_servletHandler
-
_gzipHandler
-
_options
protected int _options -
_jspConfig
protected javax.servlet.descriptor.JspConfigDescriptor _jspConfig -
_startListeners
private boolean _startListeners
-
-
Constructor Details
-
ServletContextHandler
public ServletContextHandler() -
ServletContextHandler
public ServletContextHandler(int options) -
ServletContextHandler
-
ServletContextHandler
-
ServletContextHandler
public ServletContextHandler(HandlerContainer parent, String contextPath, boolean sessions, boolean security) -
ServletContextHandler
public ServletContextHandler(HandlerContainer parent, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler) -
ServletContextHandler
public ServletContextHandler(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler) -
ServletContextHandler
public ServletContextHandler(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler, int options)
-
-
Method Details
-
addEventListener
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 classContextHandler
- Parameters:
listener
- the listener to add- See Also:
-
ServletContextListener
ServletContextAttributeListener
ServletRequestListener
ServletRequestAttributeListener
-
setHandler
- Overrides:
setHandler
in classHandlerWrapper
- Parameters:
handler
- Set theHandler
which should be wrapped.
-
doSetHandler
-
relinkHandlers
private void relinkHandlers() -
doStart
Description copied from class:ContainerLifeCycle
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classContextHandler
- Throws:
Exception
- See Also:
-
doStop
Description copied from class:ContainerLifeCycle
Stops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStop
in classContextHandler
- Throws:
Exception
- See Also:
-
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:
startContext
in classContextHandler
- Throws:
Exception
- if unable to start the context- See Also:
-
stopContext
- Overrides:
stopContext
in 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.
-
getGzipHandler
- Returns:
- Returns the gzipHandler.
-
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
-
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:
callContextInitialized
in classContextHandler
-
callContextDestroyed
public void callContextDestroyed(javax.servlet.ServletContextListener l, javax.servlet.ServletContextEvent e) - Overrides:
callContextDestroyed
in classContextHandler
-
replaceHandler
-
setSessionHandler
- Parameters:
sessionHandler
- The sessionHandler to set.
-
setSecurityHandler
- Parameters:
securityHandler
- TheSecurityHandler
to set on this context.
-
setGzipHandler
- Parameters:
gzipHandler
- TheGzipHandler
to set on this context.
-
setServletHandler
- Parameters:
servletHandler
- The servletHandler to set.
-
insertHandler
Insert a HandlerWrapper before the first Session,Security or ServletHandler but after any other HandlerWrappers.- Overrides:
insertHandler
in classHandlerWrapper
- Parameters:
handler
- the wrapper to insert
-
getObjectFactory
The DecoratedObjectFactory for use by IoC containers (weld / spring / etc)- Returns:
- The DecoratedObjectFactory
-
getDecorators
Deprecated.use theDecoratedObjectFactory
from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()
instead- Returns:
- The decorator list used to resource inject new Filters, Servlets and EventListeners
-
setDecorators
Deprecated.use theDecoratedObjectFactory
from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()
instead- Parameters:
decorators
- The list ofServletContextHandler.Decorator
s
-
addDecorator
Deprecated.use theDecoratedObjectFactory
from getAttribute("org.eclipse.jetty.util.DecoratedObjectFactory") orgetObjectFactory()
instead- Parameters:
decorator
- The decorator to add
-
destroyServlet
void destroyServlet(javax.servlet.Servlet servlet) -
destroyFilter
void destroyFilter(javax.servlet.Filter filter) -
destroyListener
-
getServletContextHandler
-
Decorator