org.mortbay.jetty.servlet
Class ServletHandler

java.lang.Object
  |
  +--org.mortbay.http.handler.AbstractHttpHandler
        |
        +--org.mortbay.jetty.servlet.ServletHandler
All Implemented Interfaces:
HttpHandler, LifeCycle, java.io.Serializable
Direct Known Subclasses:
WebApplicationHandler

public class ServletHandler
extends AbstractHttpHandler

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.

If a SessionManager is not added to the handler before it is initialized, then a HashSessionManager with a standard java.util.Random generator is created.

Version:
$Id: ServletHandler.java,v 1.90.2.6 2004/02/29 18:38:47 gregwilkins Exp $
Author:
Greg Wilkins
See Also:
WebApplicationHandler, Serialized Form

Field Summary
static java.lang.String __DEFAULT_SERVLET
           
 
Constructor Summary
ServletHandler()
          Constructor.
 
Method Summary
 void addEventListener(java.util.EventListener listener)
           
 ServletHolder addServlet(java.lang.String pathSpec, java.lang.String servletClass)
           
 ServletHolder addServlet(java.lang.String name, java.lang.String pathSpec, java.lang.String servletClass)
          Add a servlet.
 ServletHolder addServlet(java.lang.String name, java.lang.String pathSpec, java.lang.String servletClass, java.lang.String forcedPath)
          Add a servlet.
 void formAuthInit(java.lang.String formLoginPage, java.lang.String formErrorPage)
           
 java.lang.ClassLoader getClassLoader()
           
 java.util.Map.Entry getHolderEntry(java.lang.String pathInContext)
          ServletHolder matching path.
 LogSink getLogSink()
           
 RequestDispatcher getNamedDispatcher(java.lang.String name)
          Get Named dispatcher.
 java.lang.String getRealPath(java.lang.String path)
           
 RequestDispatcher getRequestDispatcher(java.lang.String uriInContext)
           
 java.net.URL getResource(java.lang.String uriInContext)
          Get a Resource.
 java.io.InputStream getResourceAsStream(java.lang.String uriInContext)
           
 java.util.Set getResourcePaths(java.lang.String uriInContext)
           
 ServletContext getServletContext()
           
 ServletHolder getServletHolder(java.lang.String name)
           
 PathMap getServletMap()
           
 ServletHolder[] getServlets()
          Get Servlets.
 SessionManager getSessionManager()
           
 void handle(java.lang.String pathInContext, java.lang.String pathParams, HttpRequest httpRequest, HttpResponse httpResponse)
          Handle request.
 void initialize(HttpContext context)
          Initialize with a HttpContext.
 void initializeServlets()
          Initialize load-on-startup servlets.
 boolean isAutoInitializeServlets()
           
 boolean isUsingCookies()
           
 ServletHolder mapPathToServlet(java.lang.String pathSpec, java.lang.String servletName)
           
 ServletHolder newServletHolder(java.lang.String name, java.lang.String servletClass)
           
 ServletHolder newServletHolder(java.lang.String name, java.lang.String servletClass, java.lang.String forcedPath)
           
 void removeEventListener(java.util.EventListener listener)
           
 void setAutoInitializeServlets(boolean b)
           
 void setDynamicInitParams(java.util.Map initParams)
          Deprecated. Use org.mortbay.jetty.servlet.Invoker
 void setDynamicServletPathSpec(java.lang.String dynamicServletPathSpec)
          Deprecated. Use org.mortbay.jetty.servlet.Invoker
 void setLogSink(LogSink logSink)
           
 void setServeDynamicSystemServlets(boolean b)
          Deprecated. Use org.mortbay.jetty.servlet.Invoker
 void setSessionManager(SessionManager sm)
           
 void setUsingCookies(boolean uc)
           
 void start()
          Start the LifeCycle.
 void stop()
          Stop the LifeCycle.
 
Methods inherited from class org.mortbay.http.handler.AbstractHttpHandler
getHttpContext, getName, handleTrace, isStarted, setName, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

__DEFAULT_SERVLET

public static final java.lang.String __DEFAULT_SERVLET
See Also:
Constant Field Values
Constructor Detail

ServletHandler

public ServletHandler()
Constructor.

Method Detail

initialize

public void initialize(HttpContext context)
Description copied from class: AbstractHttpHandler
Initialize with a HttpContext. Called by addHandler methods of HttpContext.

Specified by:
initialize in interface HttpHandler
Overrides:
initialize in class AbstractHttpHandler
Parameters:
context - Must be the HttpContext of the handler

formAuthInit

public void formAuthInit(java.lang.String formLoginPage,
                         java.lang.String formErrorPage)

setSessionManager

public void setSessionManager(SessionManager sm)

getSessionManager

public SessionManager getSessionManager()

getServletContext

public ServletContext getServletContext()

getServletMap

public PathMap getServletMap()

isUsingCookies

public boolean isUsingCookies()

setDynamicServletPathSpec

public void setDynamicServletPathSpec(java.lang.String dynamicServletPathSpec)
Deprecated. Use org.mortbay.jetty.servlet.Invoker

Set the dynamic servlet path.


setDynamicInitParams

public void setDynamicInitParams(java.util.Map initParams)
Deprecated. Use org.mortbay.jetty.servlet.Invoker

Set dynamic servlet initial parameters.


setServeDynamicSystemServlets

public void setServeDynamicSystemServlets(boolean b)
Deprecated. Use org.mortbay.jetty.servlet.Invoker

Set serving dynamic system servlets.


getClassLoader

public java.lang.ClassLoader getClassLoader()

setUsingCookies

public void setUsingCookies(boolean uc)
Parameters:
uc - If true, cookies are used for sessions

setLogSink

public void setLogSink(LogSink logSink)

getLogSink

public LogSink getLogSink()

newServletHolder

public ServletHolder newServletHolder(java.lang.String name,
                                      java.lang.String servletClass,
                                      java.lang.String forcedPath)

newServletHolder

public ServletHolder newServletHolder(java.lang.String name,
                                      java.lang.String servletClass)

getServletHolder

public ServletHolder getServletHolder(java.lang.String name)

mapPathToServlet

public ServletHolder mapPathToServlet(java.lang.String pathSpec,
                                      java.lang.String servletName)

addServlet

public ServletHolder addServlet(java.lang.String name,
                                java.lang.String pathSpec,
                                java.lang.String servletClass,
                                java.lang.String forcedPath)
Add a servlet.

Parameters:
name - The servlet name.
pathSpec - A path specification to map this servlet to.
servletClass - The class name of the servlet.
forcedPath - If non null, the request attribute javax.servlet.include.servlet_path will be set to this path before service is called.
Returns:
The ServletHolder for the servlet.

addServlet

public ServletHolder addServlet(java.lang.String name,
                                java.lang.String pathSpec,
                                java.lang.String servletClass)
Add a servlet.

Parameters:
name - The servlet name.
pathSpec - A path specification to map this servlet to.
servletClass - The class name of the servlet.
Returns:
The ServletHolder for the servlet.

addServlet

public ServletHolder addServlet(java.lang.String pathSpec,
                                java.lang.String servletClass)

addEventListener

public void addEventListener(java.util.EventListener listener)
                      throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException

removeEventListener

public void removeEventListener(java.util.EventListener listener)

isAutoInitializeServlets

public boolean isAutoInitializeServlets()

setAutoInitializeServlets

public void setAutoInitializeServlets(boolean b)

start

public void start()
           throws java.lang.Exception
Description copied from interface: LifeCycle
Start the LifeCycle.

Specified by:
start in interface LifeCycle
Overrides:
start in class AbstractHttpHandler
Throws:
java.lang.Exception - An arbitrary exception may be thrown.

getServlets

public ServletHolder[] getServlets()
Get Servlets.

Returns:
Array of defined servlets

initializeServlets

public void initializeServlets()
                        throws java.lang.Exception
Initialize load-on-startup servlets. Called automatically from start if autoInitializeServlet is true.

java.lang.Exception

stop

public void stop()
          throws java.lang.InterruptedException
Description copied from interface: LifeCycle
Stop the LifeCycle. The LifeCycle may wait for current activities to complete normally, but it can be interrupted.

Specified by:
stop in interface LifeCycle
Overrides:
stop in class AbstractHttpHandler
Throws:
java.lang.InterruptedException - Stopping a lifecycle is rarely atomic and may be interrupted by another thread. If this happens InterruptedException is throw and the component will be in an indeterminant state and should probably be discarded.

handle

public void handle(java.lang.String pathInContext,
                   java.lang.String pathParams,
                   HttpRequest httpRequest,
                   HttpResponse httpResponse)
            throws java.io.IOException
Handle request.

Parameters:
pathInContext -
pathParams -
httpRequest -
httpResponse -
Throws:
java.io.IOException

getHolderEntry

public java.util.Map.Entry getHolderEntry(java.lang.String pathInContext)
ServletHolder matching path.

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

getResourcePaths

public java.util.Set getResourcePaths(java.lang.String uriInContext)

getResource

public java.net.URL getResource(java.lang.String uriInContext)
                         throws java.net.MalformedURLException
Get a Resource. If no resource is found, resource aliases are tried.

Parameters:
uriInContext -
Returns:
URL of the resource.
Throws:
java.net.MalformedURLException

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String uriInContext)

getRealPath

public java.lang.String getRealPath(java.lang.String path)

getRequestDispatcher

public RequestDispatcher getRequestDispatcher(java.lang.String uriInContext)

getNamedDispatcher

public RequestDispatcher getNamedDispatcher(java.lang.String name)
Get Named dispatcher.

Parameters:
name - The name of the servlet. If null or empty string, the containers default servlet is returned.
Returns:
Request dispatcher for the named servlet.


Copyright ? 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.