- All Implemented Interfaces:
org.eclipse.jetty.server.Handler,org.eclipse.jetty.server.Handler.Container,org.eclipse.jetty.server.Handler.Singleton,org.eclipse.jetty.server.Request.Handler,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,org.eclipse.jetty.util.thread.Invocable
This handler maps requests to servlets that implement the jakarta.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().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classA mapping of a servlet by pathSpec or by nameNested classes/interfaces inherited from class org.eclipse.jetty.server.Handler.Abstract
org.eclipse.jetty.server.Handler.Abstract.NonBlockingNested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainerNested classes/interfaces inherited from interface org.eclipse.jetty.server.Handler
org.eclipse.jetty.server.Handler.Abstract, org.eclipse.jetty.server.Handler.AbstractContainer, org.eclipse.jetty.server.Handler.Collection, org.eclipse.jetty.server.Handler.Container, org.eclipse.jetty.server.Handler.Sequence, org.eclipse.jetty.server.Handler.Singleton, org.eclipse.jetty.server.Handler.WrapperNested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
org.eclipse.jetty.util.thread.Invocable.Callable, org.eclipse.jetty.util.thread.Invocable.InvocationType, org.eclipse.jetty.util.thread.Invocable.ReadyTask, org.eclipse.jetty.util.thread.Invocable.TaskNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.server.Request.Handler
org.eclipse.jetty.server.Request.Handler.AbortException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ConcurrentMap<String,jakarta.servlet.FilterChain>[] Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPINGFields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEYFields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking, NOOP -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFilter(FilterHolder filter) Convenience method to add a preconstructed FilterHoldervoidaddFilter(FilterHolder filter, FilterMapping filterMapping) Convenience method to add a filter and mappingvoidaddFilterMapping(FilterMapping mapping) Convenience method to add a preconstructed FilterMappingaddFilterWithMapping(Class<? extends jakarta.servlet.Filter> filter, String pathSpec, int dispatches) Convenience method to add a filter.addFilterWithMapping(Class<? extends jakarta.servlet.Filter> filter, String pathSpec, EnumSet<jakarta.servlet.DispatcherType> dispatches) Convenience method to add a filter.addFilterWithMapping(String className, String pathSpec, int dispatches) Convenience method to add a filter.addFilterWithMapping(String className, String pathSpec, EnumSet<jakarta.servlet.DispatcherType> dispatches) Convenience method to add a filter.voidaddFilterWithMapping(FilterHolder holder, String pathSpec, int dispatches) Convenience method to add a filter.voidaddFilterWithMapping(FilterHolder holder, String pathSpec, EnumSet<jakarta.servlet.DispatcherType> dispatches) Convenience method to add a filter.voidaddListener(ListenerHolder listener) Add a holder for a listenervoidaddServlet(ServletHolder holder) Convenience method to add a pre-constructed ServletHolder.voidaddServletMapping(ServletMapping mapping) Convenience method to add a pre-constructed ServletMapping.addServletWithMapping(Class<? extends jakarta.servlet.Servlet> servlet, String pathSpec) Convenience method to add a servlet.addServletWithMapping(String className, String pathSpec) Convenience method to add a servlet.voidaddServletWithMapping(ServletHolder servlet, String pathSpec) Convenience method to add a servlet.protected org.eclipse.jetty.http.pathmap.PathSpecasPathSpec(String pathSpec) protected booleancontainsFilterHolder(FilterHolder holder) protected booleancontainsServletHolder(ServletHolder holder) protected voiddoStart()protected voiddoStop()voiddump(Appendable out, String indent) protected jakarta.servlet.FilterChaingetFilterChain(jakarta.servlet.http.HttpServletRequest request, String pathInContext, ServletHolder servletHolder) protected org.eclipse.jetty.security.IdentityServicegetMappedServlet(String target) ServletHolder matching path.org.eclipse.jetty.http.pathmap.MatchedResource<ServletHandler.MappedServlet> getMatchedServlet(String target) ServletHolder matching target path.intgetServlet(String name) jakarta.servlet.ServletContextgetServletMapping(String pathSpec) Get the ServletMapping matching the pathgetServlets(Class<?> clazz) booleanhandle(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback) voidInitialize filters and load-on-startup servlets.protected voidinitializeHolders(Collection<? extends BaseHolder<?>> holders) protected voidbooleanbooleanbooleanbooleanisDumpable(Object o) booleanbooleanbooleanbooleanprotected jakarta.servlet.FilterChainnewFilterChain(FilterHolder filterHolder, jakarta.servlet.FilterChain chain) Create a FilterChain that calls the passed filter with the passed chainnewFilterHolder(Source source) newListenerHolder(Source source) newServletHolder(Source source) Add a new servlet holderprotected voidnotFound(org.eclipse.jetty.server.Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) voidprependFilter(FilterHolder filter) Convenience method to add a preconstructed FilterHoldervoidprependFilterMapping(FilterMapping mapping) Convenience method to add a preconstructed FilterMappingvoidremoveFilterHolder(FilterHolder holder) voidremoveFilterMapping(FilterMapping mapping) voidsetAllowDuplicateMappings(boolean allowDuplicateMappings) Set the allowDuplicateMappings to set.voidsetDecodeAmbiguousURIs(boolean decodeAmbiguousURIs) Allow or disallow ambiguous URIs to be returned byServletApiRequest.getServletPath()andServletApiRequest.getPathInfo().voidsetEnsureDefaultServlet(boolean ensureDefaultServlet) voidsetFilterChainsCached(boolean filterChainsCached) voidsetFilterMappings(FilterMapping[] filterMappings) voidsetFilters(FilterHolder[] holders) voidsetListeners(ListenerHolder[] holders) voidsetMaxFilterChainsCacheSize(int maxFilterChainsCacheSize) Set the maximum filter chain cache size.voidsetServletMappings(ServletMapping[] servletMappings) voidsetServlets(ServletHolder[] holders) Set Servlets.setServletSecurity(jakarta.servlet.ServletRegistration.Dynamic registration, jakarta.servlet.ServletSecurityElement servletSecurityElement) voidsetStartWithUnavailable(boolean start) protected voidstart(org.eclipse.jetty.util.component.LifeCycle l) protected voidstop(org.eclipse.jetty.util.component.LifeCycle l) protected voidprotected voidMethods inherited from class org.eclipse.jetty.server.Handler.Wrapper
getHandler, getInvocationType, setHandlerMethods inherited from class org.eclipse.jetty.server.Handler.AbstractContainer
findContainerOf, getDescendant, getDescendants, isDynamic, setDynamic, setServerMethods inherited from class org.eclipse.jetty.server.Handler.Abstract
destroy, getServerMethods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListenersMethods inherited from interface org.eclipse.jetty.util.component.Destroyable
destroyMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dumpSelfMethods inherited from interface org.eclipse.jetty.server.Handler
getServer, setServerMethods inherited from interface org.eclipse.jetty.server.Handler.Container
getContainer, getDescendant, getDescendants, getDescendantsMethods inherited from interface org.eclipse.jetty.server.Handler.Singleton
getHandlers, getTail, insertHandler, setHandlerMethods inherited from interface org.eclipse.jetty.util.component.LifeCycle
addEventListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, start, stop
-
Field Details
-
_chainCache
-
-
Constructor Details
-
ServletHandler
public ServletHandler()Constructor.
-
-
Method Details
-
isDecodeAmbiguousURIs
@ManagedAttribute("True if URIs with violations are decoded") public boolean isDecodeAmbiguousURIs() -
setDecodeAmbiguousURIs
public void setDecodeAmbiguousURIs(boolean decodeAmbiguousURIs) Allow or disallow ambiguous URIs to be returned by
ServletApiRequest.getServletPath()andServletApiRequest.getPathInfo().Note that the
HttpConfiguration.setUriCompliance(UriCompliance)must also be set to allow ambiguous URIs to be accepted by theConnector.- Parameters:
decodeAmbiguousURIs-Trueif ambiguous URIs are decoded by all servlet API methods.
-
isDumpable
-
dump
- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Overrides:
dumpin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
IOException
-
doStart
-
isEnsureDefaultServlet
public boolean isEnsureDefaultServlet()- Returns:
- true if ServletHandler always has a default servlet, using
ServletHandler.Default404Servletif no other default servlet is configured.
-
setEnsureDefaultServlet
public void setEnsureDefaultServlet(boolean ensureDefaultServlet) - Parameters:
ensureDefaultServlet- true if ServletHandler always has a default servlet, usingServletHandler.Default404Servletif no other default servlet is configured.
-
start
-
stop
-
doStop
-
getFilterMappings
-
getFilters
-
getServletContext
public jakarta.servlet.ServletContext getServletContext() -
getServletContextHandler
-
getServletMappings
@ManagedAttribute(value="mappings of servlets", readonly=true) public ServletMapping[] getServletMappings() -
getServletMapping
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
-
getServlets
-
getServlet
-
getIdentityService
protected org.eclipse.jetty.security.IdentityService getIdentityService() -
handle
public boolean handle(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response, org.eclipse.jetty.util.Callback callback) throws Exception - Specified by:
handlein interfaceorg.eclipse.jetty.server.Request.Handler- Overrides:
handlein classorg.eclipse.jetty.server.Handler.Wrapper- Throws:
Exception
-
getMatchedServlet
public org.eclipse.jetty.http.pathmap.MatchedResource<ServletHandler.MappedServlet> getMatchedServlet(String target) ServletHolder matching target path.- Parameters:
target- Path within _context or servlet name- Returns:
- MatchedResource, pointing to the
MappedResourcefor theServletHolder, and also the pathspec specific name/info sections for the match. Named servlets have a null PathSpec andMatchedResource.
-
getMappedServlet
ServletHolder matching path.- Parameters:
target- Path within _context or servlet name- Returns:
- MappedResource to the ServletHolder. Named servlets have a null PathSpec
-
getFilterChain
protected jakarta.servlet.FilterChain getFilterChain(jakarta.servlet.http.HttpServletRequest request, String pathInContext, ServletHolder servletHolder) -
newFilterChain
protected jakarta.servlet.FilterChain newFilterChain(FilterHolder filterHolder, jakarta.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
-
isAllowDuplicateMappings
public boolean isAllowDuplicateMappings()- Returns:
- the allowDuplicateMappings
-
setAllowDuplicateMappings
public void setAllowDuplicateMappings(boolean allowDuplicateMappings) Set the allowDuplicateMappings to set.- Parameters:
allowDuplicateMappings- the allowDuplicateMappings to set
-
initialize
-
isInitialized
public boolean isInitialized()- Returns:
- true if initialized has been called, false otherwise
-
initializeHolders
-
isFilterChainsCached
public boolean isFilterChainsCached()- Returns:
- whether the filter chains are cached.
-
addListener
Add a holder for a listener- Parameters:
listener- the listener for the holder
-
getListeners
-
setListeners
-
newListenerHolder
-
newServletHolder
Add a new servlet holder- Parameters:
source- the holder source- Returns:
- the servlet holder
-
addServletWithMapping
Convenience method to add a servlet.- Parameters:
className- the class namepathSpec- the path spec- Returns:
- The servlet holder.
-
addServletWithMapping
public ServletHolder addServletWithMapping(Class<? extends jakarta.servlet.Servlet> servlet, String pathSpec) Convenience method to add a servlet.- Parameters:
servlet- the servlet classpathSpec- the path spec- Returns:
- The servlet holder.
-
addServletWithMapping
Convenience method to add a servlet.- Parameters:
servlet- servlet holder to addpathSpec- servlet mappings for the servletHolder
-
addServlet
Convenience method to add a pre-constructed ServletHolder.- Parameters:
holder- the servlet holder
-
addServletMapping
Convenience method to add a pre-constructed ServletMapping.- Parameters:
mapping- the servlet mapping
-
setServletSecurity
-
newFilterHolder
-
getFilter
-
addFilterWithMapping
public FilterHolder addFilterWithMapping(Class<? extends jakarta.servlet.Filter> filter, String pathSpec, EnumSet<jakarta.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(String className, String pathSpec, EnumSet<jakarta.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, String pathSpec, EnumSet<jakarta.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(Class<? extends jakarta.servlet.Filter> filter, 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
Convenience method to add a filter.- Parameters:
className- of filterpathSpec- filter mappings for filterdispatches- seeFilterMapping.setDispatches(int)- Returns:
- The filter holder.
-
addFilterWithMapping
Convenience method to add a filter.- Parameters:
holder- filter holder to addpathSpec- filter mappings for filterdispatches- seeFilterMapping.setDispatches(int)
-
addFilter
Convenience method to add a filter and mapping- Parameters:
filter- the filter holderfilterMapping- the filter mapping
-
addFilter
Convenience method to add a preconstructed FilterHolder- Parameters:
filter- the filter holder
-
prependFilter
Convenience method to add a preconstructed FilterHolder- Parameters:
filter- the filter holder
-
addFilterMapping
Convenience method to add a preconstructed FilterMapping- Parameters:
mapping- the filter mapping
-
prependFilterMapping
Convenience method to add a preconstructed FilterMapping- Parameters:
mapping- the filter mapping
-
removeFilterHolder
-
removeFilterMapping
-
updateNameMappings
protected void updateNameMappings() -
asPathSpec
-
updateMappings
protected void updateMappings() -
notFound
protected void notFound(org.eclipse.jetty.server.Request baseRequest, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException, jakarta.servlet.ServletException - Throws:
IOExceptionjakarta.servlet.ServletException
-
containsFilterHolder
-
containsServletHolder
-
setFilterChainsCached
public void setFilterChainsCached(boolean filterChainsCached) - Parameters:
filterChainsCached- The filterChainsCached to set.
-
setFilterMappings
- Parameters:
filterMappings- The filterMappings to set.
-
setFilters
-
setServletMappings
- Parameters:
servletMappings- The servletMappings to set.
-
setServlets
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.
-