Top Description Inners Fields Constructors Methods
org.eclipse.jetty.ee10.servlet

public Class ServletHandler

extends Wrapper
Class Inheritance
Annotations
@ManagedObject:Servlet Handler
Imports
java.io.IOException, java.util.ArrayList, .Arrays, .Collections, .EnumSet, .EventListener, .HashMap, .List, .Map, .Objects, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.function.Consumer, java.util.stream.Collectors, .Stream, jakarta.servlet.DispatcherType, .Filter, .FilterChain, .Servlet, .ServletContext, .ServletException, .ServletRegistration, .ServletRequest, .ServletResponse, .ServletSecurityElement, jakarta.servlet.http.HttpServlet, .HttpServletRequest, .HttpServletResponse, org.eclipse.jetty.http.pathmap.MappedResource, .MatchedPath, .MatchedResource, .PathMappings, .PathSpec, .ServletPathSpec, org.eclipse.jetty.security.IdentityService, .SecurityHandler, org.eclipse.jetty.server.Context, .Handler, .Request, .Response, org.eclipse.jetty.server.handler.ContextHandler, org.eclipse.jetty.util.ArrayUtil, .Callback, .ExceptionUtil, .MultiMap, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, org.eclipse.jetty.util.component.DumpableCollection, .LifeCycle, org.eclipse.jetty.util.thread.AutoLock, org.slf4j.Logger, .LoggerFactory

Servlet HttpHandler.

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 and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
public static class
public static class
ServletHandler.MappedServlet

A mapping of a servlet by pathSpec or by name

Field Summary

Modifier and TypeField and Description
private boolean
protected final ConcurrentMap<String, FilterChain>[]
private boolean
private final List<BaseHolder<?>>
private boolean
private boolean
private final List<FilterMapping>
private final Map<String, FilterHolder>
private MultiMap<FilterMapping>
private List<FilterMapping>
private final List<FilterHolder>
private IdentityService
private boolean
private final List<ListenerHolder>
private final AutoLock
private int
private int
private int
private ServletContext
private ServletContextHandler
private final List<ServletMapping>
private final Map<String, ServletHandler.MappedServlet>
private PathMappings<ServletHandler.MappedServlet>
private final List<ServletHolder>
private boolean
private List<FilterMapping>
private static final Logger

Constructor Summary

AccessConstructor and Description
public
ServletHandler()

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
addFilter(FilterHolder
the filter holder
filter
,
FilterMapping
the filter mapping
filterMapping
)

Convenience method to add a filter and mapping

public void
addFilter(FilterHolder
the filter holder
filter
)

Convenience method to add a preconstructed FilterHolder

public void
addFilterMapping(FilterMapping
the filter mapping
mapping
)

Convenience method to add a preconstructed FilterMapping

public FilterHolder

Returns:

The filter holder.
addFilterWithMapping
(Class<? extends Filter>
class of filter to create
filter
,
String
filter mappings for filter
pathSpec
,
EnumSet<DispatcherType> dispatches)

Convenience method to add a filter.

public FilterHolder

Returns:

The filter holder.
addFilterWithMapping
(String
of filter
className
,
String
filter mappings for filter
pathSpec
,
EnumSet<DispatcherType> dispatches)

Convenience method to add a filter.

public void
addFilterWithMapping(FilterHolder
filter holder to add
holder
,
String
filter mappings for filter
pathSpec
,
EnumSet<DispatcherType> dispatches)

Convenience method to add a filter.

public FilterHolder

Returns:

The filter holder.
addFilterWithMapping
(Class<? extends Filter>
class of filter to create
filter
,
String
filter mappings for filter
pathSpec
,
int dispatches)

Convenience method to add a filter.

public FilterHolder

Returns:

The filter holder.
addFilterWithMapping
(String
of filter
className
,
String
filter mappings for filter
pathSpec
,
int dispatches)

Convenience method to add a filter.

public void
addFilterWithMapping(FilterHolder
filter holder to add
holder
,
String
filter mappings for filter
pathSpec
,
int dispatches)

Convenience method to add a filter.

public void
addListener(ListenerHolder
the listener for the holder
listener
)

Add a holder for a listener

public void
addServlet(ServletHolder
the servlet holder
holder
)

Convenience method to add a pre-constructed ServletHolder.

public void
addServletMapping(ServletMapping
the servlet mapping
mapping
)

Convenience method to add a pre-constructed ServletMapping.

public ServletHolder

Returns:

The servlet holder.
addServletWithMapping
(String
the class name
className
,
String
the path spec
pathSpec
)

Convenience method to add a servlet.

public ServletHolder

Returns:

The servlet holder.
addServletWithMapping
(Class<? extends Servlet>
the servlet class
servlet
,
String
the path spec
pathSpec
)

Convenience method to add a servlet.

public void
addServletWithMapping(ServletHolder
servlet holder to add
servlet
,
String
servlet mappings for the servletHolder
pathSpec
)

Convenience method to add a servlet.

protected PathSpec
asPathSpec(String pathSpec)

protected boolean
protected boolean
pack-priv void
pack-priv void
pack-priv void
protected void
doStart()

Overrides org.eclipse.jetty.server.Handler.Abstract.doStart.

Starts the managed lifecycle beans in the order they were added.
protected void
doStop()

Overrides org.eclipse.jetty.server.Handler.Abstract.doStop.

Stops the managed lifecycle beans in the reverse order they were added.
public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.
public FilterHolder
protected FilterChain
getFilterChain(HttpServletRequest request, String pathInContext, ServletHolder servletHolder)

public FilterMapping[]
public FilterHolder[]
protected IdentityService
public ListenerHolder[]
public ServletHandler.MappedServlet

Returns:

MappedResource to the ServletHolder. Named servlets have a null PathSpec
getMappedServlet
(String
Path within _context or servlet name
target
)

ServletHolder matching path.

public MatchedResource<ServletHandler.MappedServlet>

Returns:

MatchedResource, pointing to the MappedResource for the ServletHolder, and also the pathspec specific name/info sections for the match. Named servlets have a null PathSpec and MatchedResource.
getMatchedServlet
(String
Path within _context or servlet name
target
)

ServletHolder matching target path.

public int

Returns:

The maximum entries in a filter chain cache.
getMaxFilterChainsCacheSize
()

public ServletHolder
public ServletContext
public ServletContextHandler
public ServletMapping

Returns:

the servlet mapping for the path spec (or null if not found)
getServletMapping
(String
the path spec
pathSpec
)

Get the ServletMapping matching the path

public ServletMapping[]
public ServletHolder[]
public List<ServletHolder>
getServlets(Class<?> clazz)

public boolean
handle(Request
the HTTP request to handle
request
,
Response
the HTTP response to handle
response
,
Callback
the callback to complete when the handling is complete
callback
)

Overrides org.eclipse.jetty.server.Handler.Wrapper.handle.

Implements org.eclipse.jetty.server.Request.Handler.handle.

Invoked to handle the passed HTTP request and response.

public void
initialize()

Initialize filters and load-on-startup servlets.

protected void
initializeHolders(Collection<? extends BaseHolder<?>> holders)

protected void
public boolean

Returns:

the allowDuplicateMappings
isAllowDuplicateMappings
()

public boolean

Returns:

true if the handler is started and there are no unavailable servlets
isAvailable
()

public boolean
public boolean
public boolean

Returns:

true if ServletHandler always has a default servlet, using Default404Servlet if no other default servlet is configured.
isEnsureDefaultServlet
()

public boolean

Returns:

whether the filter chains are cached.
isFilterChainsCached
()

public boolean

Returns:

true if initialized has been called, false otherwise
isInitialized
()

public boolean

Returns:

True if this handler will start with unavailable servlets
isStartWithUnavailable
()

pack-priv AutoLock
lock()

protected FilterChain

Returns:

A FilterChain that invokes the filter with the chain
newFilterChain
(FilterHolder
The filter to invoke
filterHolder
,
FilterChain
The chain to pass to the filter
chain
)

Create a FilterChain that calls the passed filter with the passed chain

public FilterHolder
public ListenerHolder
public ServletHolder

Returns:

the servlet holder
newServletHolder
(Source
the holder source
source
)

Add a new servlet holder

protected void
notFound(Request baseRequest, HttpServletRequest request, HttpServletResponse response)

public void
prependFilter(FilterHolder
the filter holder
filter
)

Convenience method to add a preconstructed FilterHolder

public void
prependFilterMapping(FilterMapping
the filter mapping
mapping
)

Convenience method to add a preconstructed FilterMapping

public void
public void
public void
setAllowDuplicateMappings(boolean
the allowDuplicateMappings to set
allowDuplicateMappings
)

Set the allowDuplicateMappings to set.

public void
setDecodeAmbiguousURIs(boolean
True if ambiguous URIs are decoded by ServletApiRequest#getServletPath() and ServletApiRequest#getPathInfo().
decodeAmbiguousURIs
)

public void
setEnsureDefaultServlet(boolean
true if ServletHandler always has a default servlet, using Default404Servlet if no other default servlet is configured.
ensureDefaultServlet
)

public void
setFilterChainsCached(boolean
The filterChainsCached to set.
filterChainsCached
)

public void
setFilterMappings(FilterMapping[]
The filterMappings to set.
filterMappings
)

public void
public void
public void
setMaxFilterChainsCacheSize(int
the maximum number of entries in a filter chain cache.
maxFilterChainsCacheSize
)

Set the maximum filter chain cache size.

public void
setServletMappings(ServletMapping[]
The servletMappings to set.
servletMappings
)

public void
setServlets(ServletHolder[]
Array of servlets to define
holders
)

Set Servlets.

public Set<String>
public void
setStartWithUnavailable(boolean
True if this handler will start with unavailable servlets
start
)

protected void
start(LifeCycle
the lifecycle to start
l
)

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.start.

Starts the given lifecycle.
protected void
stop(LifeCycle
the lifecycle to stop
l
)

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.stop.

Stops the given lifecycle.
private <T> void
updateAndSet(Collection<T> target, Collection<T> values)

protected void
protected void
Inherited from org.eclipse.jetty.server.Handler.Wrapper:
getHandlergetInvocationTypesetHandler