org.mortbay.jetty.servlet
Class ServletHandler

java.lang.Object
  extended by org.mortbay.component.AbstractLifeCycle
      extended by org.mortbay.jetty.handler.AbstractHandler
          extended by org.mortbay.jetty.servlet.ServletHandler
All Implemented Interfaces:
LifeCycle, Handler

public class ServletHandler
extends AbstractHandler

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.

Author:
Greg Wilkins
See Also:
org.mortbay.jetty.servlet.WebAppContext

Nested Class Summary
private  class ServletHandler.CachedChain
           
private  class ServletHandler.Chain
           
 
Field Summary
private static String __AllowString
           
static String __DEFAULT_SERVLET
           
static String __J_S_CONTEXT_TEMPDIR
           
static String __J_S_ERROR_EXCEPTION
           
static String __J_S_ERROR_EXCEPTION_TYPE
           
static String __J_S_ERROR_MESSAGE
           
static String __J_S_ERROR_REQUEST_URI
           
static String __J_S_ERROR_SERVLET_NAME
           
static String __J_S_ERROR_STATUS_CODE
           
protected  HashMap[] _chainCache
           
private  ContextHandler _contextHandler
           
private  boolean _filterChainsCached
           
private  FilterMapping[] _filterMappings
           
private  Map _filterNameMap
           
private  MultiMap _filterNameMappings
           
private  List _filterPathMappings
           
private  FilterHolder[] _filters
           
private  boolean _initializeAtStart
           
protected  HashMap[] _namedChainCache
           
private  ContextHandler.Context _servletContext
           
private  ServletMapping[] _servletMappings
           
private  Map _servletNameMap
           
private  PathMap _servletPathMap
           
private  ServletHolder[] _servlets
           
 
Fields inherited from class org.mortbay.jetty.handler.AbstractHandler
_string
 
Fields inherited from interface org.mortbay.jetty.Handler
ALL, DEFAULT, ERROR, FORWARD, INCLUDE, REQUEST
 
Constructor Summary
ServletHandler()
          Constructor.
 
Method Summary
protected  void doStart()
           
protected  void doStop()
           
 Object getContextLog()
           
private  FilterChain getFilterChain(int requestType, String pathInContext, ServletHolder servletHolder)
           
 FilterMapping[] getFilterMappings()
           
 FilterHolder[] getFilters()
          Get Filters.
private  PathMap.Entry getHolderEntry(String pathInContext)
          ServletHolder matching path.
 RequestDispatcher getRequestDispatcher(String uriInContext)
           
 ServletContext getServletContext()
           
 ServletMapping[] getServletMappings()
           
 ServletHolder[] getServlets()
          Get Servlets.
 boolean handle(String target, HttpServletRequest request, HttpServletResponse response, int type)
          Generic Jetty request handler.
 void initialize()
          Initialize filters and load-on-startup servlets.
 boolean isFilterChainsCached()
           
 boolean isInitializeAtStart()
           
protected  void notFound(HttpServletRequest request, HttpServletResponse response)
           
 void setContextLog(Object contextLog)
           
 void setFilterChainsCached(boolean filterChainsCached)
           
 void setFilterMappings(FilterMapping[] filterMappings)
           
 void setFilters(FilterHolder[] holders)
          Get Filters.
 void setInitializeAtStart(boolean initializeAtStart)
           
 void setServer(Server server)
           
 void setServletMappings(ServletMapping[] servletMappings)
           
 void setServlets(ServletHolder[] holders)
          Get Servlets.
protected  void updateMappings()
           
 
Methods inherited from class org.mortbay.jetty.handler.AbstractHandler
getServer, toString
 
Methods inherited from class org.mortbay.component.AbstractLifeCycle
isFailed, isRunning, isStarted, isStarting, isStopping, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mortbay.component.LifeCycle
isFailed, isRunning, isStarted, isStarting, isStopping, start, stop
 

Field Detail

__AllowString

private static String __AllowString

__DEFAULT_SERVLET

public static final String __DEFAULT_SERVLET
See Also:
Constant Field Values

__J_S_CONTEXT_TEMPDIR

public static final String __J_S_CONTEXT_TEMPDIR
See Also:
Constant Field Values

__J_S_ERROR_EXCEPTION

public static final String __J_S_ERROR_EXCEPTION
See Also:
Constant Field Values

__J_S_ERROR_EXCEPTION_TYPE

public static final String __J_S_ERROR_EXCEPTION_TYPE
See Also:
Constant Field Values

__J_S_ERROR_MESSAGE

public static final String __J_S_ERROR_MESSAGE
See Also:
Constant Field Values

__J_S_ERROR_REQUEST_URI

public static final String __J_S_ERROR_REQUEST_URI
See Also:
Constant Field Values

__J_S_ERROR_SERVLET_NAME

public static final String __J_S_ERROR_SERVLET_NAME
See Also:
Constant Field Values

__J_S_ERROR_STATUS_CODE

public static final String __J_S_ERROR_STATUS_CODE
See Also:
Constant Field Values

_contextHandler

private ContextHandler _contextHandler

_servletContext

private ContextHandler.Context _servletContext

_filters

private FilterHolder[] _filters

_filterMappings

private FilterMapping[] _filterMappings

_filterChainsCached

private boolean _filterChainsCached

_servlets

private ServletHolder[] _servlets

_servletMappings

private ServletMapping[] _servletMappings

_initializeAtStart

private boolean _initializeAtStart

_filterNameMap

private transient Map _filterNameMap

_filterPathMappings

private transient List _filterPathMappings

_filterNameMappings

private transient MultiMap _filterNameMappings

_servletNameMap

private transient Map _servletNameMap

_servletPathMap

private transient PathMap _servletPathMap

_chainCache

protected transient HashMap[] _chainCache

_namedChainCache

protected transient HashMap[] _namedChainCache
Constructor Detail

ServletHandler

public ServletHandler()
Constructor.

Method Detail

setServer

public void setServer(Server server)
Specified by:
setServer in interface Handler
Overrides:
setServer in class AbstractHandler

doStart

protected void doStart()
                throws Exception
Overrides:
doStart in class AbstractHandler
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Overrides:
doStop in class AbstractHandler
Throws:
Exception

getContextLog

public Object getContextLog()
Returns:
Returns the contextLog.

getFilterMappings

public FilterMapping[] getFilterMappings()
Returns:
Returns the filterMappings.

getFilters

public FilterHolder[] getFilters()
Get Filters.

Returns:
Array of defined servlets

getHolderEntry

private PathMap.Entry getHolderEntry(String pathInContext)
ServletHolder matching path.

Parameters:
pathInContext - Path within _context.
Returns:
PathMap Entries pathspec to ServletHolder

getRequestDispatcher

public RequestDispatcher getRequestDispatcher(String uriInContext)
Parameters:
ipath -
Returns:

getServletContext

public ServletContext getServletContext()

getServletMappings

public ServletMapping[] getServletMappings()
Returns:
Returns the servletMappings.

getServlets

public ServletHolder[] getServlets()
Get Servlets.

Returns:
Array of defined servlets

handle

public boolean handle(String target,
                      HttpServletRequest request,
                      HttpServletResponse response,
                      int type)
               throws IOException
Description copied from interface: Handler
Generic Jetty request handler.

Parameters:
target - The target of the request - either a URI or a name.
request - 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 - 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 - The dispatch mode: Handler.REQUEST, Handler.FORWARD, Handler.INCLUDE, Handler.ERROR
Returns:
True if the request has been handled
Throws:
IOException

getFilterChain

private FilterChain getFilterChain(int requestType,
                                   String pathInContext,
                                   ServletHolder servletHolder)

isInitializeAtStart

public boolean isInitializeAtStart()
Returns:
Returns the initializeAtStart.

setInitializeAtStart

public void setInitializeAtStart(boolean initializeAtStart)
Parameters:
initializeAtStart - The initializeAtStart to set.

initialize

public void initialize()
                throws Exception
Initialize filters and load-on-startup servlets. Called automatically from start if autoInitializeServlet is true.

Throws:
Exception

isFilterChainsCached

public boolean isFilterChainsCached()
Returns:
Returns the filterChainsCached.

updateMappings

protected void updateMappings()

notFound

protected void notFound(HttpServletRequest request,
                        HttpServletResponse response)
                 throws IOException
Throws:
IOException

setContextLog

public void setContextLog(Object contextLog)
Parameters:
contextLog - The contextLog to set.

setFilterChainsCached

public void setFilterChainsCached(boolean filterChainsCached)
Parameters:
filterChainsCached - The filterChainsCached to set.

setFilterMappings

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

setFilters

public void setFilters(FilterHolder[] holders)
Get Filters.


setServletMappings

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

setServlets

public void setServlets(ServletHolder[] holders)
Get Servlets.