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

public Class ServletHolder

extends Holder
implements Comparable
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.io.IOException, java.security.Principal, java.util.Enumeration, .HashMap, .Map, .Stack, javax.servlet.Servlet, .ServletConfig, .ServletContext, .ServletException, .ServletRequest, .ServletResponse, .SingleThreadModel, .UnavailableException, org.mortbay.jetty.HttpConnection, .Request, .UserRealm, org.mortbay.jetty.handler.ContextHandler, .SecurityHandler, org.mortbay.log.Log

Servlet Instance and Context Holder. Holds the name, params and some state of a javax.servlet.Servlet instance. It implements the ServletConfig interface. This class will organise the loading of the servlet when needed or requested.
Author
Greg Wilkins

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
private class

Field Summary

Modifier and TypeField and Description
private transient ServletHolder.Config
private String
private boolean
private int
private UserRealm
private Map<K, V>
private String
private transient Servlet
private transient long
private transient UnavailableException
Inherited from org.mortbay.jetty.servlet.Holder:
_class_className_displayName_extInstance_initParams_name_servletHandler

Constructor Summary

AccessConstructor and Description
public
ServletHolder()

Constructor .

public
ServletHolder(Servlet servlet)

Constructor for existing servlet.

public
ServletHolder(Class<T> servlet)

Constructor for existing servlet.

Method Summary

Modifier and TypeMethod and Description
public void
checkServletType()

Check to ensure class of servlet is acceptable.

public int
compareTo(Object
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Comparitor by init order.
public void
public void
public void
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public String

Returns:

Returns the forcedPath.
getForcedPath
()

public int
public Map<K, V>
public String
public synchronized Servlet

Returns:

The servlet
getServlet
()

Get the servlet.

public UnavailableException

Returns:

The unavailable exception or null if not unavailable
getUnavailableException
()

public void
handle(ServletRequest request, ServletResponse response)

Service a request with this servlet.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
private void
public boolean

Returns:

true if the holder is started and is not unavailable
isAvailable
()

private void
private void
public void
setForcedPath(String
The forcedPath to set.
forcedPath
)

public void
setInitOrder(int order)

Set the initialize order.

public void
setRunAs(String
Role name that is added to UserPrincipal when this servlet is called.
role
)

public synchronized void
Inherited from org.mortbay.jetty.servlet.Holder:
getClassNamegetDisplayNamegetHeldClassgetInitParametergetInitParameterNamesgetInitParametersgetNamegetServletHandlernewInstancesetClassNamesetDisplayNamesetHeldClasssetInitParametersetInitParameterssetNamesetServletHandlertoString

Field Detail

_configback to summary
private transient ServletHolder.Config _config
_forcedPathback to summary
private String _forcedPath
_initOnStartupback to summary
private boolean _initOnStartup
_initOrderback to summary
private int _initOrder
_realmback to summary
private UserRealm _realm
_roleMapback to summary
private Map<K, V> _roleMap
_runAsback to summary
private String _runAs
_servletback to summary
private transient Servlet _servlet
_unavailableback to summary
private transient long _unavailable
_unavailableExback to summary
private transient UnavailableException _unavailableEx

Constructor Detail

ServletHolderback to summary
public ServletHolder()

Constructor .

ServletHolderback to summary
public ServletHolder(Servlet servlet)

Constructor for existing servlet.

ServletHolderback to summary
public ServletHolder(Class<T> servlet)

Constructor for existing servlet.

Method Detail

checkServletTypeback to summary
public void checkServletType() throws UnavailableException

Check to ensure class of servlet is acceptable.

compareToback to summary
public int compareTo(Object o)

Implements java.lang.Comparable.compareTo.

Comparitor by init order.

Parameters
o:Object

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

Doc from java.lang.Comparable.compareTo.

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

destroyInstanceback to summary
public void destroyInstance(Object o) throws Exception

Overrides org.mortbay.jetty.servlet.Holder.destroyInstance.

doStartback to summary
public void doStart() throws Exception

Overrides org.mortbay.jetty.servlet.Holder.doStart.

doStopback to summary
public void doStop()

Overrides org.mortbay.jetty.servlet.Holder.doStop.

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

getForcedPathback to summary
public String getForcedPath()
Returns:String

Returns the forcedPath.

getInitOrderback to summary
public int getInitOrder()
getRoleMapback to summary
public Map<K, V> getRoleMap()
getRunAsback to summary
public String getRunAs()
getServletback to summary
public synchronized Servlet getServlet() throws ServletException

Get the servlet.

Returns:Servlet

The servlet

getUnavailableExceptionback to summary
public UnavailableException getUnavailableException()
Returns:UnavailableException

The unavailable exception or null if not unavailable

handleback to summary
public void handle(ServletRequest request, ServletResponse response) throws ServletException, UnavailableException, IOException

Service a request with this servlet.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

initServletback to summary
private void initServlet() throws ServletException
isAvailableback to summary
public boolean isAvailable()
Returns:boolean

true if the holder is started and is not unavailable

makeUnavailableback to summary
private void makeUnavailable(UnavailableException e)
makeUnavailableback to summary
private void makeUnavailable(Throwable e)
setForcedPathback to summary
public void setForcedPath(String forcedPath)
Parameters
forcedPath:String

The forcedPath to set.

setInitOrderback to summary
public void setInitOrder(int order)

Set the initialize order. Holders with order<0, are initialized on use. Those with order>=0 are initialized in increasing order when the handler is started.

setRunAsback to summary
public void setRunAs(String role)
Parameters
role:String

Role name that is added to UserPrincipal when this servlet is called.

setServletback to summary
public synchronized void setServlet(Servlet servlet)
org.mortbay.jetty.servlet back to summary

pack-priv Class ServletHolder.Config

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

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String
getInitParameter(String
the name of the initialization parameter whose value to get
param
)

Implements javax.servlet.ServletConfig.getInitParameter.

Gets the value of the initialization parameter with the given name.
public Enumeration<E>
getInitParameterNames()

Implements javax.servlet.ServletConfig.getInitParameterNames.

Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters.
public ServletContext
getServletContext()

Implements javax.servlet.ServletConfig.getServletContext.

Returns a reference to the ServletContext in which the caller is executing.
public String
getServletName()

Implements javax.servlet.ServletConfig.getServletName.

Returns the name of this servlet instance.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Configback to summary
pack-priv Config()

Method Detail

getInitParameterback to summary
public String getInitParameter(String param)

Implements javax.servlet.ServletConfig.getInitParameter.

Doc from javax.servlet.ServletConfig.getInitParameter.

Gets the value of the initialization parameter with the given name.

Parameters
param:String

the name of the initialization parameter whose value to get

Returns:String

a String containing the value of the initialization parameter, or null if the initialization parameter does not exist

getInitParameterNamesback to summary
public Enumeration<E> getInitParameterNames()

Implements javax.servlet.ServletConfig.getInitParameterNames.

Doc from javax.servlet.ServletConfig.getInitParameterNames.

Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters.

Returns:Enumeration<E>

an Enumeration of String objects containing the names of the servlet's initialization parameters

getServletContextback to summary
public ServletContext getServletContext()

Implements javax.servlet.ServletConfig.getServletContext.

Doc from javax.servlet.ServletConfig.getServletContext.

Returns a reference to the ServletContext in which the caller is executing.

Returns:ServletContext

a ServletContext object, used by the caller to interact with its servlet container

getServletNameback to summary
public String getServletName()

Implements javax.servlet.ServletConfig.getServletName.

Doc from javax.servlet.ServletConfig.getServletName.

Returns the name of this servlet instance. The name may be provided via server administration, assigned in the web application deployment descriptor, or for an unregistered (and thus unnamed) servlet instance it will be the servlet's class name.

Returns:String

the name of the servlet instance

org.mortbay.jetty.servlet back to summary

private Class ServletHolder.SingleThreadedWrapper

extends Object
implements Servlet
Class Inheritance
  • java.lang.Object
  • org.mortbay.jetty.servlet.ServletHolder.SingleThreadedWrapper
All Implemented Interfaces
javax.servlet.Servlet

Field Summary

Modifier and TypeField and Description
pack-priv Stack<E>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

Implements javax.servlet.Servlet.destroy.

Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.
public ServletConfig
getServletConfig()

Implements javax.servlet.Servlet.getServletConfig.

Returns a ServletConfig object, which contains initialization and startup parameters for this servlet.
public String
getServletInfo()

Implements javax.servlet.Servlet.getServletInfo.

Returns information about the servlet, such as author, version, and copyright.
public void
init(ServletConfig
a ServletConfig object containing the servlet's configuration and initialization parameters
config
)

Implements javax.servlet.Servlet.init.

Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
public void
service(ServletRequest
the ServletRequest object that contains the client's request
req
,
ServletResponse
the ServletResponse object that contains the servlet's response
res
)

Implements javax.servlet.Servlet.service.

Called by the servlet container to allow the servlet to respond to a request.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_stackback to summary
pack-priv Stack<E> _stack

Constructor Detail

SingleThreadedWrapperback to summary
private SingleThreadedWrapper()

Method Detail

destroyback to summary
public void destroy()

Implements javax.servlet.Servlet.destroy.

Doc from javax.servlet.Servlet.destroy.

Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the service method again on this servlet.

This method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the servlet's current state in memory.

getServletConfigback to summary
public ServletConfig getServletConfig()

Implements javax.servlet.Servlet.getServletConfig.

Doc from javax.servlet.Servlet.getServletConfig.

Returns a ServletConfig object, which contains initialization and startup parameters for this servlet. The ServletConfig object returned is the one passed to the init method.

Implementations of this interface are responsible for storing the ServletConfig object so that this method can return it. The GenericServlet class, which implements this interface, already does this.

Returns:ServletConfig

the ServletConfig object that initializes this servlet

getServletInfoback to summary
public String getServletInfo()

Implements javax.servlet.Servlet.getServletInfo.

Doc from javax.servlet.Servlet.getServletInfo.

Returns information about the servlet, such as author, version, and copyright.

The string that this method returns should be plain text and not markup of any kind (such as HTML, XML, etc.).

Returns:String

a String containing servlet information

initback to summary
public void init(ServletConfig config) throws ServletException

Implements javax.servlet.Servlet.init.

Doc from javax.servlet.Servlet.init.

Called by the servlet container to indicate to a servlet that the servlet is being placed into service.

The servlet container calls the init method exactly once after instantiating the servlet. The init method must complete successfully before the servlet can receive any requests.

The servlet container cannot place the servlet into service if the init method

  1. Throws a ServletException
  2. Does not return within a time period defined by the Web server
Parameters
config:ServletConfig

a ServletConfig object containing the servlet's configuration and initialization parameters

Exceptions
ServletException:
if an exception has occurred that interferes with the servlet's normal operation
serviceback to summary
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException

Implements javax.servlet.Servlet.service.

Doc from javax.servlet.Servlet.service.

Called by the servlet container to allow the servlet to respond to a request.

This method is only called after the servlet's init() method has completed successfully.

The status code of the response always should be set for a servlet that throws or sends an error.

Servlets typically run inside multithreaded servlet containers that can handle multiple requests concurrently. Developers must be aware to synchronize access to any shared resources such as files, network connections, and as well as the servlet's class and instance variables. More information on multithreaded programming in Java is available in the Java tutorial on multi-threaded programming.

Parameters
req:ServletRequest

the ServletRequest object that contains the client's request

res:ServletResponse

the ServletResponse object that contains the servlet's response

Exceptions
ServletException:
if an exception occurs that interferes with the servlet's normal operation
IOException:
if an input or output exception occurs