@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 |
---|---|
static class |
ServletHandler.Default404Servlet |
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
Modifier and Type | Field and Description |
---|---|
static String |
__DEFAULT_SERVLET |
protected ConcurrentMap<String,FilterChain>[] |
_chainCache |
protected Queue<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(String className,
String pathSpec,
EnumSet<DispatcherType> dispatches)
Deprecated.
use
addFilterWithMapping(Class, String, EnumSet) instead |
void |
addFilterMapping(FilterMapping mapping)
Convenience method to add a preconstructed FilterMapping
|
FilterHolder |
addFilterWithMapping(Class<? extends Filter> filter,
String pathSpec,
EnumSet<DispatcherType> dispatches)
Convenience method to add a filter.
|
FilterHolder |
addFilterWithMapping(Class<? extends Filter> filter,
String pathSpec,
int dispatches)
Convenience method to add a filter.
|
void |
addFilterWithMapping(FilterHolder holder,
String pathSpec,
EnumSet<DispatcherType> dispatches)
Convenience method to add a filter.
|
void |
addFilterWithMapping(FilterHolder holder,
String pathSpec,
int dispatches)
Convenience method to add a filter.
|
FilterHolder |
addFilterWithMapping(String className,
String pathSpec,
EnumSet<DispatcherType> dispatches)
Convenience method to add a filter.
|
FilterHolder |
addFilterWithMapping(String className,
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(Class<? extends Servlet> servlet,
String pathSpec)
Convenience method to add a servlet.
|
void |
addServletWithMapping(ServletHolder servlet,
String pathSpec)
Convenience method to add a servlet.
|
ServletHolder |
addServletWithMapping(String className,
String pathSpec)
Convenience method to add a servlet.
|
void |
doHandle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response) |
void |
doScope(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response) |
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.
|
Object |
getContextLog() |
FilterHolder |
getFilter(String name) |
protected FilterChain |
getFilterChain(Request baseRequest,
String pathInContext,
ServletHolder servletHolder) |
FilterMapping[] |
getFilterMappings() |
FilterHolder[] |
getFilters()
Get Filters.
|
PathMap.MappedEntry<ServletHolder> |
getHolderEntry(String pathInContext)
ServletHolder matching path.
|
protected IdentityService |
getIdentityService() |
ListenerHolder[] |
getListeners() |
int |
getMaxFilterChainsCacheSize() |
ServletHolder |
getServlet(String name) |
ServletContext |
getServletContext() |
ServletMapping |
getServletMapping(String pathSpec)
Get the ServletMapping matching the path
|
ServletMapping[] |
getServletMappings() |
ServletHolder[] |
getServlets()
Get Servlets.
|
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 |
isAvailable() |
boolean |
isEnsureDefaultServlet() |
boolean |
isFilterChainsCached() |
boolean |
isStartWithUnavailable() |
FilterHolder |
newFilterHolder(BaseHolder.Source source) |
ListenerHolder |
newListenerHolder(BaseHolder.Source source) |
ServletHolder |
newServletHolder(BaseHolder.Source source)
Add a new servlet holder
|
protected void |
notFound(Request baseRequest,
HttpServletRequest request,
HttpServletResponse response) |
void |
prependFilterMapping(FilterMapping mapping)
Convenience method to add a preconstructed FilterMapping
|
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.
|
Set<String> |
setServletSecurity(ServletRegistration.Dynamic registration,
ServletSecurityElement servletSecurityElement) |
void |
setStartWithUnavailable(boolean start) |
protected void |
start(LifeCycle l)
Starts the given lifecycle.
|
protected void |
updateMappings() |
protected void |
updateNameMappings() |
handle, never, nextHandle, nextScope
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandler
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServer
dumpThis, getServer
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, stop, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public static final String __DEFAULT_SERVLET
protected final ConcurrentMap<String,FilterChain>[] _chainCache
protected void doStart() throws Exception
ContainerLifeCycle
doStart
in class ScopedHandler
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 Exception
ContainerLifeCycle
start
in class ContainerLifeCycle
l
- the lifecycle to startException
- if unable to start lifecycleprotected void doStop() throws Exception
ContainerLifeCycle
doStop
in class AbstractHandler
Exception
protected IdentityService getIdentityService()
public Object getContextLog()
@ManagedAttribute(value="filters", readonly=true) public FilterMapping[] getFilterMappings()
@ManagedAttribute(value="filters", readonly=true) public FilterHolder[] getFilters()
public PathMap.MappedEntry<ServletHolder> getHolderEntry(String pathInContext)
pathInContext
- Path within _context.public ServletContext getServletContext()
@ManagedAttribute(value="mappings of servlets", readonly=true) public ServletMapping[] getServletMappings()
public ServletMapping getServletMapping(String pathSpec)
pathSpec
- the path spec@ManagedAttribute(value="servlets", readonly=true) public ServletHolder[] getServlets()
public ServletHolder getServlet(String name)
public void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
doScope
in class ScopedHandler
IOException
ServletException
public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
doHandle
in class ScopedHandler
IOException
ServletException
protected FilterChain getFilterChain(Request baseRequest, 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 isStartWithUnavailable()
public void initialize() throws Exception
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(BaseHolder.Source source)
public ServletHolder newServletHolder(BaseHolder.Source source)
source
- the holder sourcepublic ServletHolder addServletWithMapping(String className, String pathSpec)
className
- the class namepathSpec
- the path specpublic ServletHolder addServletWithMapping(Class<? extends Servlet> servlet, String pathSpec)
servlet
- the servlet classpathSpec
- the path specpublic void addServletWithMapping(ServletHolder servlet, 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 Set<String> setServletSecurity(ServletRegistration.Dynamic registration, ServletSecurityElement servletSecurityElement)
public FilterHolder newFilterHolder(BaseHolder.Source source)
public FilterHolder getFilter(String name)
public FilterHolder addFilterWithMapping(Class<? extends Filter> filter, String pathSpec, EnumSet<DispatcherType> dispatches)
filter
- class of filter to createpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
public FilterHolder addFilterWithMapping(String className, String pathSpec, EnumSet<DispatcherType> dispatches)
className
- of filterpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
public void addFilterWithMapping(FilterHolder holder, String pathSpec, EnumSet<DispatcherType> dispatches)
holder
- filter holder to addpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
public FilterHolder addFilterWithMapping(Class<? extends Filter> filter, String pathSpec, int dispatches)
filter
- class of filter to createpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
public FilterHolder addFilterWithMapping(String className, String pathSpec, int dispatches)
className
- of filterpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
public void addFilterWithMapping(FilterHolder holder, String pathSpec, int dispatches)
holder
- filter holder to addpathSpec
- filter mappings for filterdispatches
- see FilterMapping.setDispatches(int)
@Deprecated public FilterHolder addFilter(String className, String pathSpec, EnumSet<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, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
IOException
ServletException
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-2016 Webtide. All Rights Reserved.