@ManagedObject(value="Servlet Handler") public class ServletHandler extends ScopedHandler
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, the initialize()
method must be called manually after start().
Modifier and Type | Class and Description |
---|---|
protected class |
ServletHandler.CachedChain |
static class |
ServletHandler.Default404Servlet |
AbstractHandler.ErrorDispatchHandler
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
__DEFAULT_SERVLET |
protected java.util.concurrent.ConcurrentMap<java.lang.String,javax.servlet.FilterChain>[] |
_chainCache |
protected java.util.Queue<java.lang.String>[] |
_chainLRU |
_nextScope, _outerScope
_handler
Constructor and Description |
---|
ServletHandler()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addFilter(FilterHolder filter)
Convenience method to add a preconstructed FilterHolder
|
void |
addFilter(FilterHolder filter,
FilterMapping filterMapping)
Convenience method to add a filter and mapping
|
FilterHolder |
addFilter(java.lang.String className,
java.lang.String pathSpec,
java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
Deprecated.
use
addFilterWithMapping(Class, String, EnumSet) instead |
void |
addFilterMapping(FilterMapping mapping)
Convenience method to add a preconstructed FilterMapping
|
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.Class<? extends javax.servlet.Filter> filter,
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 |
addFilterWithMapping(FilterHolder holder,
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.
|
FilterHolder |
addFilterWithMapping(java.lang.String className,
java.lang.String pathSpec,
int dispatches)
Convenience method to add a filter.
|
void |
addListener(ListenerHolder listener)
Add a holder for a listener
|
void |
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.
|
void |
addServletWithMapping(ServletHolder 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.
|
protected boolean |
containsFilterHolder(FilterHolder holder) |
protected boolean |
containsServletHolder(ServletHolder holder) |
void |
doHandle(java.lang.String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Do the handler work within the scope.
|
void |
doScope(java.lang.String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Scope the 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.
|
void |
dump(java.lang.Appendable out,
java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.
|
FilterHolder |
getFilter(java.lang.String name) |
protected javax.servlet.FilterChain |
getFilterChain(Request baseRequest,
java.lang.String pathInContext,
ServletHolder servletHolder) |
FilterMapping[] |
getFilterMappings() |
FilterHolder[] |
getFilters() |
MappedResource<ServletHolder> |
getHolderEntry(java.lang.String target)
Deprecated.
|
protected IdentityService |
getIdentityService() |
ListenerHolder[] |
getListeners() |
MappedResource<ServletHolder> |
getMappedServlet(java.lang.String target)
ServletHolder matching path.
|
int |
getMaxFilterChainsCacheSize() |
ServletHolder |
getServlet(java.lang.String name) |
javax.servlet.ServletContext |
getServletContext() |
ServletMapping |
getServletMapping(java.lang.String pathSpec)
Get the ServletMapping matching the path
|
ServletMapping[] |
getServletMappings() |
ServletHolder[] |
getServlets() |
void |
initialize()
Initialize filters and load-on-startup servlets.
|
protected FilterMapping[] |
insertFilterMapping(FilterMapping mapping,
int pos,
boolean before)
Insert a filtermapping in the list
|
protected void |
invalidateChainsCache() |
boolean |
isAllowDuplicateMappings() |
boolean |
isAvailable() |
boolean |
isEnsureDefaultServlet() |
boolean |
isFilterChainsCached() |
boolean |
isStartWithUnavailable() |
ServletHandler.CachedChain |
newCachedChain(java.util.List<FilterHolder> filters,
ServletHolder servletHolder)
Create a new CachedChain
|
FilterHolder |
newFilterHolder(Source source) |
ListenerHolder |
newListenerHolder(Source source) |
ServletHolder |
newServletHolder(Source source)
Add a new servlet holder
|
protected void |
notFound(Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) |
void |
prependFilterMapping(FilterMapping mapping)
Convenience method to add a preconstructed FilterMapping
|
void |
setAllowDuplicateMappings(boolean allowDuplicateMappings) |
void |
setEnsureDefaultServlet(boolean ensureDefaultServlet) |
void |
setFilterChainsCached(boolean filterChainsCached) |
void |
setFilterMappings(FilterMapping[] filterMappings) |
void |
setFilters(FilterHolder[] holders) |
void |
setListeners(ListenerHolder[] listeners) |
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(LifeCycle l)
Starts the given lifecycle.
|
protected void |
updateMappings() |
protected void |
updateNameMappings() |
handle, nextHandle, nextScope
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandler
doShutdown, expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServer
doError, getServer
addBean, 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, stop, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, start, stop, stop
dumpObjects, dumpSelf
public static final java.lang.String __DEFAULT_SERVLET
protected final java.util.concurrent.ConcurrentMap<java.lang.String,javax.servlet.FilterChain>[] _chainCache
protected final java.util.Queue<java.lang.String>[] _chainLRU
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
Dumpable
dump
in interface Dumpable
dump
in class ContainerLifeCycle
out
- The appendable to dump toindent
- The indent to apply after any new lines.java.io.IOException
- if unable to write to Appendableprotected void doStart() throws java.lang.Exception
ContainerLifeCycle
doStart
in class ScopedHandler
java.lang.Exception
AbstractHandler.doStart()
public boolean isEnsureDefaultServlet()
ServletHandler.Default404Servlet
if no other
default servlet is configured.public void setEnsureDefaultServlet(boolean ensureDefaultServlet)
ensureDefaultServlet
- true if ServletHandler always has a default servlet, using ServletHandler.Default404Servlet
if no other
default servlet is configured.protected void start(LifeCycle l) throws java.lang.Exception
ContainerLifeCycle
start
in class ContainerLifeCycle
l
- the lifecycle to startjava.lang.Exception
- if unable to start lifecycleprotected void doStop() throws java.lang.Exception
ContainerLifeCycle
doStop
in class AbstractHandler
java.lang.Exception
protected IdentityService getIdentityService()
@ManagedAttribute(value="filters", readonly=true) public FilterMapping[] getFilterMappings()
@ManagedAttribute(value="filters", readonly=true) public FilterHolder[] getFilters()
@Deprecated public MappedResource<ServletHolder> getHolderEntry(java.lang.String target)
getMappedServlet(String)
target
- Path within _context or servlet namepublic javax.servlet.ServletContext getServletContext()
@ManagedAttribute(value="mappings of servlets", readonly=true) public ServletMapping[] getServletMappings()
public ServletMapping getServletMapping(java.lang.String pathSpec)
pathSpec
- the path spec@ManagedAttribute(value="servlets", readonly=true) public ServletHolder[] getServlets()
public ServletHolder getServlet(java.lang.String name)
public void doScope(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
ScopedHandler
Derived implementations should call ScopedHandler.nextScope(String, Request, HttpServletRequest, HttpServletResponse)
doScope
in class ScopedHandler
target
- The target of the request - either a URI or a name.baseRequest
- The original unwrapped request object.request
- The request either as the Request
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getRequest()
method can be used access the Request object if required.response
- The response as the Response
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getResponse()
method can be used access the Response object if required.java.io.IOException
- if unable to handle the request or response processingjavax.servlet.ServletException
- if unable to handle the request or response due to underlying servlet issuepublic void doHandle(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
ScopedHandler
Derived implementations should call ScopedHandler.nextHandle(String, Request, HttpServletRequest, HttpServletResponse)
doHandle
in class ScopedHandler
target
- The target of the request - either a URI or a name.baseRequest
- The original unwrapped request object.request
- The request either as the Request
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getRequest()
method can be used access the Request object if required.response
- The response as the Response
object or a wrapper of that request. The
HttpConnection.getCurrentConnection()
.getHttpChannel()
.getResponse()
method can be used access the Response object if required.java.io.IOException
- if unable to handle the request or response processingjavax.servlet.ServletException
- if unable to handle the request or response due to underlying servlet issuepublic MappedResource<ServletHolder> getMappedServlet(java.lang.String target)
target
- Path within _context or servlet nameprotected javax.servlet.FilterChain getFilterChain(Request baseRequest, java.lang.String pathInContext, ServletHolder servletHolder)
protected void invalidateChainsCache()
public boolean isAvailable()
public void setStartWithUnavailable(boolean start)
start
- True if this handler will start with unavailable servletspublic boolean isAllowDuplicateMappings()
public void setAllowDuplicateMappings(boolean allowDuplicateMappings)
allowDuplicateMappings
- the allowDuplicateMappings to setpublic boolean isStartWithUnavailable()
public void initialize() throws java.lang.Exception
java.lang.Exception
- if unable to initializepublic boolean isFilterChainsCached()
public void addListener(ListenerHolder listener)
listener
- the listener for the holderpublic ListenerHolder[] getListeners()
public void setListeners(ListenerHolder[] listeners)
public ListenerHolder newListenerHolder(Source source)
public ServletHandler.CachedChain newCachedChain(java.util.List<FilterHolder> filters, ServletHolder servletHolder)
filters
- the filter chain to be cached as a collection of FilterHolder
servletHolder
- the servletHolderServletHandler.CachedChain
instancepublic ServletHolder newServletHolder(Source source)
source
- the holder sourcepublic ServletHolder addServletWithMapping(java.lang.String className, java.lang.String pathSpec)
className
- the class namepathSpec
- the path specpublic ServletHolder addServletWithMapping(java.lang.Class<? extends javax.servlet.Servlet> servlet, java.lang.String pathSpec)
servlet
- the servlet classpathSpec
- the path specpublic void addServletWithMapping(ServletHolder servlet, java.lang.String pathSpec)
servlet
- servlet holder to addpathSpec
- servlet mappings for the servletHolderpublic void addServlet(ServletHolder holder)
holder
- the servlet holderpublic void addServletMapping(ServletMapping mapping)
mapping
- the servlet mappingpublic java.util.Set<java.lang.String> setServletSecurity(javax.servlet.ServletRegistration.Dynamic registration, javax.servlet.ServletSecurityElement servletSecurityElement)
public FilterHolder newFilterHolder(Source source)
public FilterHolder getFilter(java.lang.String name)
public FilterHolder addFilterWithMapping(java.lang.Class<? extends javax.servlet.Filter> filter, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
filter
- class of filter to createpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
public FilterHolder addFilterWithMapping(java.lang.String className, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
className
- of filterpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
public void addFilterWithMapping(FilterHolder holder, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
holder
- filter holder to addpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
public FilterHolder addFilterWithMapping(java.lang.Class<? extends javax.servlet.Filter> filter, java.lang.String pathSpec, int dispatches)
filter
- class of filter to createpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
public FilterHolder addFilterWithMapping(java.lang.String className, java.lang.String pathSpec, int dispatches)
className
- of filterpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
public void addFilterWithMapping(FilterHolder holder, java.lang.String pathSpec, int dispatches)
holder
- filter holder to addpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
@Deprecated public FilterHolder addFilter(java.lang.String className, java.lang.String pathSpec, java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
addFilterWithMapping(Class, String, EnumSet)
insteadclassName
- the filter class namepathSpec
- the path specdispatches
- the dispatcher types for this filterpublic void addFilter(FilterHolder filter, FilterMapping filterMapping)
filter
- the filter holderfilterMapping
- the filter mappingpublic void addFilter(FilterHolder filter)
filter
- the filter holderpublic void addFilterMapping(FilterMapping mapping)
mapping
- the filter mappingpublic void prependFilterMapping(FilterMapping mapping)
mapping
- the filter mappingprotected FilterMapping[] insertFilterMapping(FilterMapping mapping, int pos, boolean before)
mapping
- the FilterMapping to addpos
- the position in the existing arry at which to add itbefore
- if true, insert before pos, if false insert after itprotected void updateNameMappings()
protected void updateMappings()
protected void notFound(Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException
java.io.IOException
javax.servlet.ServletException
protected boolean containsFilterHolder(FilterHolder holder)
protected boolean containsServletHolder(ServletHolder holder)
public void setFilterChainsCached(boolean filterChainsCached)
filterChainsCached
- The filterChainsCached to set.public void setFilterMappings(FilterMapping[] filterMappings)
filterMappings
- The filterMappings to set.public void setFilters(FilterHolder[] holders)
public void setServletMappings(ServletMapping[] servletMappings)
servletMappings
- The servletMappings to set.public void setServlets(ServletHolder[] holders)
holders
- Array of servlets to definepublic int getMaxFilterChainsCacheSize()
public void setMaxFilterChainsCacheSize(int maxFilterChainsCacheSize)
isFilterChainsCached()
is true. If the max cache size
is greater than zero, then the cache is flushed whenever it grows to be this size.maxFilterChainsCacheSize
- the maximum number of entries in a filter chain cache.Copyright © 1995–2023 Webtide. All rights reserved.