- 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.servlet.ServletHandler
-
- All Implemented Interfaces:
org.eclipse.jetty.server.Handler
,org.eclipse.jetty.server.HandlerContainer
,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.LifeCycle
@ManagedObject("Servlet Handler") public class ServletHandler extends org.eclipse.jetty.server.handler.ScopedHandler
Servlet HttpHandler.This handler maps requests to servlets that implement the javax.servlet.http.HttpServlet API.
This handler does not implement the full J2EE features and is intended to be used directly when a full web application is not required. If a Web application is required, then this handler should be used as part of a
org.eclipse.jetty.webapp.WebAppContext
.Unless run as part of a
ServletContextHandler
or derivative, theinitialize()
method must be called manually after start().
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ServletHandler.Default404Servlet
static class
ServletHandler.MappedServlet
A mapping of a servlet by pathSpec or by name-
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, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException
-
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
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.ConcurrentMap<java.lang.String,javax.servlet.FilterChain>[]
_chainCache
-
Constructor Summary
Constructors Constructor Description ServletHandler()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFilter(FilterHolder filter)
Convenience method to add a preconstructed FilterHoldervoid
addFilter(FilterHolder filter, FilterMapping filterMapping)
Convenience method to add a filter and mappingvoid
addFilterMapping(FilterMapping mapping)
Convenience method to add a preconstructed FilterMappingFilterHolder
addFilterWithMapping(java.lang.Class<? extends javax.servlet.Filter> filter, java.lang.String pathSpec, int dispatches)
Convenience method to add a filter.FilterHolder
addFilterWithMapping(java.lang.Class<? extends javax.servlet.Filter> filter, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
Convenience method to add a filter.FilterHolder
addFilterWithMapping(java.lang.String className, java.lang.String pathSpec, int dispatches)
Convenience method to add a filter.FilterHolder
addFilterWithMapping(java.lang.String className, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
Convenience method to add a filter.void
addFilterWithMapping(FilterHolder holder, java.lang.String pathSpec, int dispatches)
Convenience method to add a filter.void
addFilterWithMapping(FilterHolder holder, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
Convenience method to add a filter.void
addListener(ListenerHolder listener)
Add a holder for a listenervoid
addServlet(ServletHolder holder)
Convenience method to add a pre-constructed ServletHolder.void
addServletMapping(ServletMapping mapping)
Convenience method to add a pre-constructed ServletMapping.ServletHolder
addServletWithMapping(java.lang.Class<? extends javax.servlet.Servlet> servlet, java.lang.String pathSpec)
Convenience method to add a servlet.ServletHolder
addServletWithMapping(java.lang.String className, java.lang.String pathSpec)
Convenience method to add a servlet.void
addServletWithMapping(ServletHolder servlet, java.lang.String pathSpec)
Convenience method to add a servlet.protected boolean
containsFilterHolder(FilterHolder holder)
protected boolean
containsServletHolder(ServletHolder holder)
void
doHandle(java.lang.String target, org.eclipse.jetty.server.Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
void
doScope(java.lang.String target, org.eclipse.jetty.server.Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected void
doStart()
protected void
doStop()
void
dump(java.lang.Appendable out, java.lang.String indent)
FilterHolder
getFilter(java.lang.String name)
FilterMapping[]
getFilterMappings()
FilterHolder[]
getFilters()
protected org.eclipse.jetty.security.IdentityService
getIdentityService()
ListenerHolder[]
getListeners()
ServletHandler.MappedServlet
getMappedServlet(java.lang.String target)
Get MappedServlet for target.int
getMaxFilterChainsCacheSize()
ServletHolder
getServlet(java.lang.String name)
javax.servlet.ServletContext
getServletContext()
ServletContextHandler
getServletContextHandler()
ServletMapping
getServletMapping(java.lang.String pathSpec)
Get the ServletMapping matching the pathServletMapping[]
getServletMappings()
ServletHolder[]
getServlets()
java.util.List<ServletHolder>
getServlets(java.lang.Class<?> clazz)
void
initialize()
Initialize filters and load-on-startup servlets.protected void
initializeHolders(java.util.Collection<? extends BaseHolder<?>> holders)
protected void
invalidateChainsCache()
boolean
isAllowDuplicateMappings()
boolean
isAvailable()
boolean
isDumpable(java.lang.Object o)
boolean
isEnsureDefaultServlet()
boolean
isFilterChainsCached()
boolean
isInitialized()
boolean
isStartWithUnavailable()
protected javax.servlet.FilterChain
newFilterChain(FilterHolder filterHolder, javax.servlet.FilterChain chain)
Create a FilterChain that calls the passed filter with the passed chainFilterHolder
newFilterHolder(Source source)
ListenerHolder
newListenerHolder(Source source)
ServletHolder
newServletHolder(Source source)
Add a new servlet holderprotected void
notFound(org.eclipse.jetty.server.Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
void
prependFilter(FilterHolder filter)
Convenience method to add a preconstructed FilterHoldervoid
prependFilterMapping(FilterMapping mapping)
Convenience method to add a preconstructed FilterMappingvoid
removeFilterHolder(FilterHolder holder)
void
removeFilterMapping(FilterMapping mapping)
void
setAllowDuplicateMappings(boolean allowDuplicateMappings)
void
setEnsureDefaultServlet(boolean ensureDefaultServlet)
void
setFilterChainsCached(boolean filterChainsCached)
void
setFilterMappings(FilterMapping[] filterMappings)
void
setFilters(FilterHolder[] holders)
void
setListeners(ListenerHolder[] holders)
void
setMaxFilterChainsCacheSize(int maxFilterChainsCacheSize)
Set the maximum filter chain cache size.void
setServletMappings(ServletMapping[] servletMappings)
void
setServlets(ServletHolder[] holders)
Set Servlets.java.util.Set<java.lang.String>
setServletSecurity(javax.servlet.ServletRegistration.Dynamic registration, javax.servlet.ServletSecurityElement servletSecurityElement)
void
setStartWithUnavailable(boolean start)
protected void
start(org.eclipse.jetty.util.component.LifeCycle l)
protected void
stop(org.eclipse.jetty.util.component.LifeCycle l)
protected void
updateMappings()
protected void
updateNameMappings()
-
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, insertHandler, setHandler
-
Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServer
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, unmanage, updateBean, updateBean, updateBeans, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
isDumpable
public boolean isDumpable(java.lang.Object o)
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
- Overrides:
dump
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.io.IOException
-
doStart
protected void doStart() throws java.lang.Exception
- Overrides:
doStart
in classorg.eclipse.jetty.server.handler.ScopedHandler
- Throws:
java.lang.Exception
-
isEnsureDefaultServlet
public boolean isEnsureDefaultServlet()
- Returns:
- true if ServletHandler always has a default servlet, using
ServletHandler.Default404Servlet
if no other default servlet is configured.
-
setEnsureDefaultServlet
public void setEnsureDefaultServlet(boolean ensureDefaultServlet)
- Parameters:
ensureDefaultServlet
- true if ServletHandler always has a default servlet, usingServletHandler.Default404Servlet
if no other default servlet is configured.
-
start
protected void start(org.eclipse.jetty.util.component.LifeCycle l) throws java.lang.Exception
- Overrides:
start
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.lang.Exception
-
stop
protected void stop(org.eclipse.jetty.util.component.LifeCycle l) throws java.lang.Exception
- Overrides:
stop
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.Exception
- Overrides:
doStop
in classorg.eclipse.jetty.server.handler.AbstractHandler
- Throws:
java.lang.Exception
-
getIdentityService
protected org.eclipse.jetty.security.IdentityService getIdentityService()
-
getFilterMappings
@ManagedAttribute(value="filters", readonly=true) public FilterMapping[] getFilterMappings()
-
getFilters
@ManagedAttribute(value="filters", readonly=true) public FilterHolder[] getFilters()
-
getServletContext
public javax.servlet.ServletContext getServletContext()
-
getServletContextHandler
public ServletContextHandler getServletContextHandler()
-
getServletMappings
@ManagedAttribute(value="mappings of servlets", readonly=true) public ServletMapping[] getServletMappings()
-
getServletMapping
public ServletMapping getServletMapping(java.lang.String pathSpec)
Get the ServletMapping matching the path- Parameters:
pathSpec
- the path spec- Returns:
- the servlet mapping for the path spec (or null if not found)
-
getServlets
@ManagedAttribute(value="servlets", readonly=true) public ServletHolder[] getServlets()
-
getServlets
public java.util.List<ServletHolder> getServlets(java.lang.Class<?> clazz)
-
getServlet
public ServletHolder getServlet(java.lang.String name)
-
doScope
public void doScope(java.lang.String target, org.eclipse.jetty.server.Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
- Overrides:
doScope
in classorg.eclipse.jetty.server.handler.ScopedHandler
- Throws:
java.io.IOException
javax.servlet.ServletException
-
doHandle
public void doHandle(java.lang.String target, org.eclipse.jetty.server.Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
- Specified by:
doHandle
in classorg.eclipse.jetty.server.handler.ScopedHandler
- Throws:
java.io.IOException
javax.servlet.ServletException
-
getMappedServlet
public ServletHandler.MappedServlet getMappedServlet(java.lang.String target)
Get MappedServlet for target.- Parameters:
target
- Path within _context or servlet name- Returns:
- MappedServlet matched by path or name. Named servlets have a null PathSpec
-
newFilterChain
protected javax.servlet.FilterChain newFilterChain(FilterHolder filterHolder, javax.servlet.FilterChain chain)
Create a FilterChain that calls the passed filter with the passed chain- Parameters:
filterHolder
- The filter to invokechain
- The chain to pass to the filter- Returns:
- A FilterChain that invokes the filter with the chain
-
invalidateChainsCache
protected void invalidateChainsCache()
-
isAvailable
public boolean isAvailable()
- Returns:
- true if the handler is started and there are no unavailable servlets
-
setStartWithUnavailable
public void setStartWithUnavailable(boolean start)
- Parameters:
start
- True if this handler will start with unavailable servlets
-
isAllowDuplicateMappings
public boolean isAllowDuplicateMappings()
- Returns:
- the allowDuplicateMappings
-
setAllowDuplicateMappings
public void setAllowDuplicateMappings(boolean allowDuplicateMappings)
- Parameters:
allowDuplicateMappings
- the allowDuplicateMappings to set
-
isStartWithUnavailable
public boolean isStartWithUnavailable()
- Returns:
- True if this handler will start with unavailable servlets
-
initialize
public void initialize() throws java.lang.Exception
Initialize filters and load-on-startup servlets.- Throws:
java.lang.Exception
- if unable to initialize
-
isInitialized
public boolean isInitialized()
- Returns:
- true if initialized has been called, false otherwise
-
initializeHolders
protected void initializeHolders(java.util.Collection<? extends BaseHolder<?>> holders)
-
isFilterChainsCached
public boolean isFilterChainsCached()
- Returns:
- whether the filter chains are cached.
-
addListener
public void addListener(ListenerHolder listener)
Add a holder for a listener- Parameters:
listener
- the listener for the holder
-
getListeners
public ListenerHolder[] getListeners()
-
setListeners
public void setListeners(ListenerHolder[] holders)
-
newListenerHolder
public ListenerHolder newListenerHolder(Source source)
-
newServletHolder
public ServletHolder newServletHolder(Source source)
Add a new servlet holder- Parameters:
source
- the holder source- Returns:
- the servlet holder
-
addServletWithMapping
public ServletHolder addServletWithMapping(java.lang.String className, java.lang.String pathSpec)
Convenience method to add a servlet.- Parameters:
className
- the class namepathSpec
- the path spec- Returns:
- The servlet holder.
-
addServletWithMapping
public ServletHolder addServletWithMapping(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- Returns:
- The servlet holder.
-
addServletWithMapping
public void addServletWithMapping(ServletHolder servlet, java.lang.String pathSpec)
Convenience method to add a servlet.- Parameters:
servlet
- servlet holder to addpathSpec
- servlet mappings for the servletHolder
-
addServlet
public void addServlet(ServletHolder holder)
Convenience method to add a pre-constructed ServletHolder.- Parameters:
holder
- the servlet holder
-
addServletMapping
public void addServletMapping(ServletMapping mapping)
Convenience method to add a pre-constructed ServletMapping.- Parameters:
mapping
- the servlet mapping
-
setServletSecurity
public java.util.Set<java.lang.String> setServletSecurity(javax.servlet.ServletRegistration.Dynamic registration, javax.servlet.ServletSecurityElement servletSecurityElement)
-
newFilterHolder
public FilterHolder newFilterHolder(Source source)
-
getFilter
public FilterHolder getFilter(java.lang.String name)
-
addFilterWithMapping
public FilterHolder addFilterWithMapping(java.lang.Class<? extends javax.servlet.Filter> filter, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
Convenience method to add a filter.- Parameters:
filter
- class of filter to createpathSpec
- filter mappings for filterdispatches
- seeFilterMapping.setDispatches(int)
- Returns:
- The filter holder.
-
addFilterWithMapping
public FilterHolder addFilterWithMapping(java.lang.String className, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
Convenience method to add a filter.- Parameters:
className
- of filterpathSpec
- filter mappings for filterdispatches
- seeFilterMapping.setDispatches(int)
- Returns:
- The filter holder.
-
addFilterWithMapping
public void addFilterWithMapping(FilterHolder holder, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
Convenience method to add a filter.- Parameters:
holder
- filter holder to addpathSpec
- filter mappings for filterdispatches
- seeFilterMapping.setDispatches(int)
-
addFilterWithMapping
public FilterHolder addFilterWithMapping(java.lang.Class<? extends javax.servlet.Filter> filter, java.lang.String pathSpec, int dispatches)
Convenience method to add a filter.- Parameters:
filter
- class of filter to createpathSpec
- filter mappings for filterdispatches
- seeFilterMapping.setDispatches(int)
- Returns:
- The filter holder.
-
addFilterWithMapping
public FilterHolder addFilterWithMapping(java.lang.String className, java.lang.String pathSpec, int dispatches)
Convenience method to add a filter.- Parameters:
className
- of filterpathSpec
- filter mappings for filterdispatches
- seeFilterMapping.setDispatches(int)
- Returns:
- The filter holder.
-
addFilterWithMapping
public void addFilterWithMapping(FilterHolder holder, java.lang.String pathSpec, int dispatches)
Convenience method to add a filter.- Parameters:
holder
- filter holder to addpathSpec
- filter mappings for filterdispatches
- seeFilterMapping.setDispatches(int)
-
addFilter
public void addFilter(FilterHolder filter, FilterMapping filterMapping)
Convenience method to add a filter and mapping- Parameters:
filter
- the filter holderfilterMapping
- the filter mapping
-
addFilter
public void addFilter(FilterHolder filter)
Convenience method to add a preconstructed FilterHolder- Parameters:
filter
- the filter holder
-
prependFilter
public void prependFilter(FilterHolder filter)
Convenience method to add a preconstructed FilterHolder- Parameters:
filter
- the filter holder
-
addFilterMapping
public void addFilterMapping(FilterMapping mapping)
Convenience method to add a preconstructed FilterMapping- Parameters:
mapping
- the filter mapping
-
prependFilterMapping
public void prependFilterMapping(FilterMapping mapping)
Convenience method to add a preconstructed FilterMapping- Parameters:
mapping
- the filter mapping
-
removeFilterHolder
public void removeFilterHolder(FilterHolder holder)
-
removeFilterMapping
public void removeFilterMapping(FilterMapping mapping)
-
updateNameMappings
protected void updateNameMappings()
-
updateMappings
protected void updateMappings()
-
notFound
protected void notFound(org.eclipse.jetty.server.Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
- Throws:
java.io.IOException
javax.servlet.ServletException
-
containsFilterHolder
protected boolean containsFilterHolder(FilterHolder holder)
-
containsServletHolder
protected boolean containsServletHolder(ServletHolder holder)
-
setFilterChainsCached
public void setFilterChainsCached(boolean filterChainsCached)
- Parameters:
filterChainsCached
- The filterChainsCached to set.
-
setFilterMappings
public void setFilterMappings(FilterMapping[] filterMappings)
- Parameters:
filterMappings
- The filterMappings to set.
-
setFilters
public void setFilters(FilterHolder[] holders)
-
setServletMappings
public void setServletMappings(ServletMapping[] servletMappings)
- Parameters:
servletMappings
- The servletMappings to set.
-
setServlets
public void setServlets(ServletHolder[] holders)
Set Servlets.- Parameters:
holders
- Array of servlets to define
-
getMaxFilterChainsCacheSize
public int getMaxFilterChainsCacheSize()
- Returns:
- The maximum entries in a filter chain cache.
-
setMaxFilterChainsCacheSize
public void setMaxFilterChainsCacheSize(int maxFilterChainsCacheSize)
Set the maximum filter chain cache size. Filter chains are cached ifisFilterChainsCached()
is true. If the max cache size is greater than zero, then the cache is flushed whenever it grows to be this size.- Parameters:
maxFilterChainsCacheSize
- the maximum number of entries in a filter chain cache.
-
-