Top Description Inners Fields Constructors Methods
org.mortbay.jetty.servlet

public Class ServletHandler

extends AbstractHandler
Class Inheritance
Imports
java.io.IOException, java.util.ArrayList, .Arrays, .HashMap, .List, .Map, java.util.concurrent.ConcurrentHashMap, javax.servlet.Filter, .FilterChain, .RequestDispatcher, .Servlet, .ServletContext, .ServletException, .ServletRequest, .ServletResponse, .UnavailableException, javax.servlet.http.HttpServletRequest, .HttpServletResponse, org.mortbay.jetty.Dispatcher, .EofException, .HttpConnection, .HttpException, .Request, .RetryRequest, .Server, org.mortbay.jetty.handler.AbstractHandler, .ContextHandler, org.mortbay.log.Log, org.mortbay.util.LazyList, .MultiException, .MultiMap, .URIUtil

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 when a full web application is not required. Specifically filters and request wrapping are not supported. Unless run as part of a Context or derivative, the initialize() method must be called manually after start().

Author
Greg Wilkins
See Also
org.mortbay.jetty.webapp.WebAppContext

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
protected transient ConcurrentHashMap<K, V>[]
private ContextHandler
private boolean
private FilterMapping[]
private transient Map<K, V>
private transient MultiMap<K>
private transient List<E>
private FilterHolder[]
private int
private ContextHandler.SContext
private ServletMapping[]
private transient Map<K, V>
private transient PathMap
private ServletHolder[]
private boolean
Inherited from org.mortbay.jetty.handler.AbstractHandler:
_string

Constructor Summary

AccessConstructor and Description
public
ServletHandler()

Constructor.

Method Summary

Modifier and TypeMethod and Description
public FilterHolder
addFilter(String className, String pathSpec, int dispatches)

Deprecated
Convenience method to add a filter with a mapping
public void
addFilter(FilterHolder filter, FilterMapping filterMapping)

convenience method to add a filter and mapping

public void
addFilter(FilterHolder filter)

Convenience method to add a preconstructed FilterHolder

public void
addFilterMapping(FilterMapping mapping)

Convenience method to add a preconstructed FilterMapping

public FilterHolder

Returns:

The filter holder.
addFilterWithMapping
(Class<T> filter, String pathSpec, int dispatches)

conveniance method to add a filter.

public FilterHolder

Returns:

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

conveniance method to add a filter.

public void

Returns:

The filter holder.
addFilterWithMapping
(FilterHolder holder, String pathSpec, int dispatches)

conveniance method to add a filter.

public ServletHolder
addServlet(String className, String pathSpec)

Deprecated
Convenience method to add a servlet with a servlet mapping.
public void
addServlet(ServletHolder holder)

Convenience method to add a pre-constructed ServletHolder.

public void
addServletMapping(ServletMapping mapping)

Convenience method to add a pre-constructed ServletMapping.

public ServletHolder

Returns:

The servlet holder.
addServletWithMapping
(String className, String pathSpec)

conveniance method to add a servlet.

public ServletHolder

Returns:

The servlet holder.
addServletWithMapping
(Class<T> servlet, String pathSpec)

conveniance method to add a servlet.

public void

Returns:

The servlet holder.
addServletWithMapping
(ServletHolder servlet, String pathSpec)

conveniance method to add a servlet.

public Filter
customizeFilter(Filter filter)

Customize a Filter.

public Filter
public Servlet
customizeServlet(Servlet servlet)

Customize a servlet.

public Servlet
protected synchronized void
protected synchronized void
public Object

Returns:

Returns the contextLog.
getContextLog
()

public FilterHolder
private FilterChain
getFilterChain(int requestType, String pathInContext, ServletHolder servletHolder, boolean initial)

public FilterMapping[]

Returns:

Returns the filterMappings.
getFilterMappings
()

public FilterHolder[]

Returns:

Array of defined servlets
getFilters
()

Get Filters.

public PathMap.Entry

Returns:

PathMap Entries pathspec to ServletHolder
getHolderEntry
(String
Path within _context.
pathInContext
)

ServletHolder matching path.

public int

Returns:

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

public RequestDispatcher

Returns:

A dispatcher wrapping the resource at uriInContext, or null if the specified uri cannot be dispatched to.
getRequestDispatcher
(String uriInContext)

public ServletHolder
public ServletContext
public ServletMapping[]

Returns:

Returns the servletMappings.
getServletMappings
()

public ServletHolder[]

Returns:

Array of defined servlets
getServlets
()

Get Servlets.

public void
handle(String
The target of the request - either a URI or a name.
target
,
HttpServletRequest
The request either as the Request object or a wrapper of that request. The HttpConnection#getCurrentConnection() method can be used access the Request object if required.
request
,
HttpServletResponse
The response as the Response object or a wrapper of that request. The HttpConnection#getCurrentConnection() method can be used access the Response object if required.
response
,
int
The dispatch mode: REQUEST, FORWARD, INCLUDE, ERROR
type
)

Implements org.mortbay.jetty.Handler.handle.

Handle a request.
public void
initialize()

Initialize filters and load-on-startup servlets.

public boolean

Returns:

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

public boolean

Returns:

Returns the filterChainsCached.
isFilterChainsCached
()

public boolean

Returns:

Returns the initializeAtStart.
isInitializeAtStart
()

Deprecated
public boolean

Returns:

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

public FilterHolder
public FilterHolder
public ServletHolder
public ServletHolder
newServletHolder(Class<T> servlet)

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

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

public synchronized void
public void
setInitializeAtStart(boolean
The initializeAtStart to set.
initializeAtStart
)

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

Set the maximum filter chain cache size.

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

public synchronized void
setServlets(ServletHolder[]
Array of servletsto define
holders
)

Set Servlets.

public void
setStartWithUnavailable(boolean
True if this handler will start with unavailable servlets
start
)

protected synchronized void
protected synchronized void
Inherited from org.mortbay.jetty.handler.AbstractHandler:
destroygetServertoString

Field Detail

__DEFAULT_SERVLETback to summary
public static final String __DEFAULT_SERVLET
__J_S_CONTEXT_TEMPDIRback to summary
public static final String __J_S_CONTEXT_TEMPDIR
__J_S_ERROR_EXCEPTIONback to summary
public static final String __J_S_ERROR_EXCEPTION
__J_S_ERROR_EXCEPTION_TYPEback to summary
public static final String __J_S_ERROR_EXCEPTION_TYPE
__J_S_ERROR_MESSAGEback to summary
public static final String __J_S_ERROR_MESSAGE
__J_S_ERROR_REQUEST_URIback to summary
public static final String __J_S_ERROR_REQUEST_URI
__J_S_ERROR_SERVLET_NAMEback to summary
public static final String __J_S_ERROR_SERVLET_NAME
__J_S_ERROR_STATUS_CODEback to summary
public static final String __J_S_ERROR_STATUS_CODE
_chainCacheback to summary
protected transient ConcurrentHashMap<K, V>[] _chainCache
_contextHandlerback to summary
private ContextHandler _contextHandler
_filterChainsCachedback to summary
private boolean _filterChainsCached
_filterMappingsback to summary
private FilterMapping[] _filterMappings
_filterNameMapback to summary
private transient Map<K, V> _filterNameMap
_filterNameMappingsback to summary
private transient MultiMap<K> _filterNameMappings
_filterPathMappingsback to summary
private transient List<E> _filterPathMappings
_filtersback to summary
private FilterHolder[] _filters
_maxFilterChainsCacheSizeback to summary
private int _maxFilterChainsCacheSize
_servletContextback to summary
private ContextHandler.SContext _servletContext
_servletMappingsback to summary
private ServletMapping[] _servletMappings
_servletNameMapback to summary
private transient Map<K, V> _servletNameMap
_servletPathMapback to summary
private transient PathMap _servletPathMap
_servletsback to summary
private ServletHolder[] _servlets
_startWithUnavailableback to summary
private boolean _startWithUnavailable

Constructor Detail

ServletHandlerback to summary
public ServletHandler()

Constructor.

Method Detail

addFilterback to summary
public FilterHolder addFilter(String className, String pathSpec, int dispatches)

Deprecated

Convenience method to add a filter with a mapping

addFilterback to summary
public void addFilter(FilterHolder filter, FilterMapping filterMapping)

convenience method to add a filter and mapping

addFilterback to summary
public void addFilter(FilterHolder filter)

Convenience method to add a preconstructed FilterHolder

addFilterMappingback to summary
public void addFilterMapping(FilterMapping mapping)

Convenience method to add a preconstructed FilterMapping

addFilterWithMappingback to summary
public FilterHolder addFilterWithMapping(Class<T> filter, String pathSpec, int dispatches)

conveniance method to add a filter.

Parameters
dispatches:int

see FilterMapping#setDispatches(int)

Returns:FilterHolder

The filter holder.

addFilterWithMappingback to summary
public FilterHolder addFilterWithMapping(String className, String pathSpec, int dispatches)

conveniance method to add a filter.

Parameters
dispatches:int

see FilterMapping#setDispatches(int)

Returns:FilterHolder

The filter holder.

addFilterWithMappingback to summary
public void addFilterWithMapping(FilterHolder holder, String pathSpec, int dispatches)

conveniance method to add a filter.

Parameters
dispatches:int

see FilterMapping#setDispatches(int)

Returns:void

The filter holder.

addServletback to summary
public ServletHolder addServlet(String className, String pathSpec)

Deprecated

Convenience method to add a servlet with a servlet mapping.

addServletback to summary
public void addServlet(ServletHolder holder)

Convenience method to add a pre-constructed ServletHolder.

addServletMappingback to summary
public void addServletMapping(ServletMapping mapping)

Convenience method to add a pre-constructed ServletMapping.

addServletWithMappingback to summary
public ServletHolder addServletWithMapping(String className, String pathSpec)

conveniance method to add a servlet.

Returns:ServletHolder

The servlet holder.

addServletWithMappingback to summary
public ServletHolder addServletWithMapping(Class<T> servlet, String pathSpec)

conveniance method to add a servlet.

Returns:ServletHolder

The servlet holder.

addServletWithMappingback to summary
public void addServletWithMapping(ServletHolder servlet, String pathSpec)

conveniance method to add a servlet.

Returns:void

The servlet holder.

customizeFilterback to summary
public Filter customizeFilter(Filter filter) throws Exception

Customize a Filter. Called before the Filter goes into service. Subclasses of ServletHandler should override this method.

customizeFilterDestroyback to summary
public Filter customizeFilterDestroy(Filter filter) throws Exception
customizeServletback to summary
public Servlet customizeServlet(Servlet servlet) throws Exception

Customize a servlet. Called before the servlet goes into service. Subclasses of ServletHandler should override this method.

customizeServletDestroyback to summary
public Servlet customizeServletDestroy(Servlet servlet) throws Exception
doStartback to summary
protected synchronized void doStart() throws Exception

Overrides org.mortbay.jetty.handler.AbstractHandler.doStart.

doStopback to summary
protected synchronized void doStop() throws Exception

Overrides org.mortbay.jetty.handler.AbstractHandler.doStop.

getContextLogback to summary
public Object getContextLog()
Returns:Object

Returns the contextLog.

getFilterback to summary
public FilterHolder getFilter(String name)
getFilterChainback to summary
private FilterChain getFilterChain(int requestType, String pathInContext, ServletHolder servletHolder, boolean initial)
getFilterMappingsback to summary
public FilterMapping[] getFilterMappings()
Returns:FilterMapping[]

Returns the filterMappings.

getFiltersback to summary
public FilterHolder[] getFilters()

Get Filters.

Returns:FilterHolder[]

Array of defined servlets

getHolderEntryback to summary
public PathMap.Entry getHolderEntry(String pathInContext)

ServletHolder matching path.

Parameters
pathInContext:String

Path within _context.

Returns:PathMap.Entry

PathMap Entries pathspec to ServletHolder

getMaxFilterChainsCacheSizeback to summary
public int getMaxFilterChainsCacheSize()
Returns:int

The maximum entries in a filter chain cache.

getRequestDispatcherback to summary
public RequestDispatcher getRequestDispatcher(String uriInContext)
Returns:RequestDispatcher

A dispatcher wrapping the resource at uriInContext, or null if the specified uri cannot be dispatched to.

getServletback to summary
public ServletHolder getServlet(String name)
getServletContextback to summary
public ServletContext getServletContext()
getServletMappingsback to summary
public ServletMapping[] getServletMappings()
Returns:ServletMapping[]

Returns the servletMappings.

getServletsback to summary
public ServletHolder[] getServlets()

Get Servlets.

Returns:ServletHolder[]

Array of defined servlets

handleback to summary
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int type) throws IOException, ServletException

Implements org.mortbay.jetty.Handler.handle.

Doc from org.mortbay.jetty.Handler.handle.

Handle a request.

Parameters
target:String

The target of the request - either a URI or a name.

request:HttpServletRequest

The request either as the Request object or a wrapper of that request. The HttpConnection#getCurrentConnection() method can be used access the Request object if required.

response:HttpServletResponse

The response as the Response object or a wrapper of that request. The HttpConnection#getCurrentConnection() method can be used access the Response object if required.

type:int

The dispatch mode: REQUEST, FORWARD, INCLUDE, ERROR

initializeback to summary
public void initialize() throws Exception

Initialize filters and load-on-startup servlets. Called automatically from start if autoInitializeServlet is true.

isAvailableback to summary
public boolean isAvailable()
Returns:boolean

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

isFilterChainsCachedback to summary
public boolean isFilterChainsCached()
Returns:boolean

Returns the filterChainsCached.

isInitializeAtStartback to summary
public boolean isInitializeAtStart()

Deprecated

Returns:boolean

Returns the initializeAtStart.

isStartWithUnavailableback to summary
public boolean isStartWithUnavailable()
Returns:boolean

True if this handler will start with unavailable servlets

newFilterHolderback to summary
public FilterHolder newFilterHolder(Class<T> filter)
newFilterHolderback to summary
public FilterHolder newFilterHolder()
See Also
newFilterHolder(Class)
newServletHolderback to summary
public ServletHolder newServletHolder()
See Also
newServletHolder(Class)
newServletHolderback to summary
public ServletHolder newServletHolder(Class<T> servlet)
notFoundback to summary
protected void notFound(HttpServletRequest request, HttpServletResponse response) throws IOException
setFilterChainsCachedback to summary
public void setFilterChainsCached(boolean filterChainsCached)
Parameters
filterChainsCached:boolean

The filterChainsCached to set.

setFilterMappingsback to summary
public void setFilterMappings(FilterMapping[] filterMappings)
Parameters
filterMappings:FilterMapping[]

The filterMappings to set.

setFiltersback to summary
public synchronized void setFilters(FilterHolder[] holders)
setInitializeAtStartback to summary
public void setInitializeAtStart(boolean initializeAtStart)

Deprecated

Parameters
initializeAtStart:boolean

The initializeAtStart to set.

setMaxFilterChainsCacheSizeback to summary
public void setMaxFilterChainsCacheSize(int maxFilterChainsCacheSize)

Set the maximum filter chain cache size. Filter chains are cached if isFilterChainsCached() 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:int

the maximum number of entries in a filter chain cache.

setServerback to summary
public void setServer(Server server)

Overrides org.mortbay.jetty.handler.AbstractHandler.setServer.

Implements org.mortbay.jetty.Handler.setServer.

setServletMappingsback to summary
public void setServletMappings(ServletMapping[] servletMappings)
Parameters
servletMappings:ServletMapping[]

The servletMappings to set.

setServletsback to summary
public synchronized void setServlets(ServletHolder[] holders)

Set Servlets.

Parameters
holders:ServletHolder[]

Array of servletsto define

setStartWithUnavailableback to summary
public void setStartWithUnavailable(boolean start)
Parameters
start:boolean

True if this handler will start with unavailable servlets

updateMappingsback to summary
protected synchronized void updateMappings()
updateNameMappingsback to summary
protected synchronized void updateNameMappings()
org.mortbay.jetty.servlet back to summary

private Class ServletHandler.CachedChain

extends Object
implements FilterChain
Class Inheritance
All Implemented Interfaces
javax.servlet.FilterChain

Field Summary

Modifier and TypeField and Description
pack-priv FilterHolder
pack-priv ServletHandler.CachedChain
pack-priv ServletHolder

Constructor Summary

AccessConstructor and Description
pack-priv
CachedChain(Object filters, ServletHolder servletHolder)

Method Summary

Modifier and TypeMethod and Description
public void
doFilter(ServletRequest
the request to pass along the chain.
request
,
ServletResponse
the response to pass along the chain.
response
)

Implements javax.servlet.FilterChain.doFilter.

Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_filterHolderback to summary
pack-priv FilterHolder _filterHolder
_nextback to summary
pack-priv ServletHandler.CachedChain _next
_servletHolderback to summary
pack-priv ServletHolder _servletHolder

Constructor Detail

CachedChainback to summary
pack-priv CachedChain(Object filters, ServletHolder servletHolder)

Method Detail

doFilterback to summary
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException

Implements javax.servlet.FilterChain.doFilter.

Doc from javax.servlet.FilterChain.doFilter.

Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked.

Parameters
request:ServletRequest

the request to pass along the chain.

response:ServletResponse

the response to pass along the chain.

Exceptions
IOException:
if an I/O related error has occurred during the processing
ServletException:
if an exception has occurred that interferes with the filterChain's normal operation
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

org.mortbay.jetty.servlet back to summary

private Class ServletHandler.Chain

extends Object
implements FilterChain
Class Inheritance
All Implemented Interfaces
javax.servlet.FilterChain

Field Summary

Modifier and TypeField and Description
pack-priv Object
pack-priv int
pack-priv ServletHolder

Constructor Summary

AccessConstructor and Description
pack-priv
Chain(Object filters, ServletHolder servletHolder)

Method Summary

Modifier and TypeMethod and Description
public void
doFilter(ServletRequest
the request to pass along the chain.
request
,
ServletResponse
the response to pass along the chain.
response
)

Implements javax.servlet.FilterChain.doFilter.

Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_chainback to summary
pack-priv Object _chain
_filterback to summary
pack-priv int _filter
_servletHolderback to summary
pack-priv ServletHolder _servletHolder

Constructor Detail

Chainback to summary
pack-priv Chain(Object filters, ServletHolder servletHolder)

Method Detail

doFilterback to summary
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException

Implements javax.servlet.FilterChain.doFilter.

Doc from javax.servlet.FilterChain.doFilter.

Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked.

Parameters
request:ServletRequest

the request to pass along the chain.

response:ServletResponse

the response to pass along the chain.

Exceptions
IOException:
if an I/O related error has occurred during the processing
ServletException:
if an exception has occurred that interferes with the filterChain's normal operation
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.