org.apache.catalina.core

Class StandardWrapper

public class StandardWrapper extends ContainerBase implements ServletConfig, Wrapper, NotificationEmitter

Standard implementation of the Wrapper interface that represents an individual servlet definition. No child Containers are allowed, and the parent Container must be a Context.

Version: $Revision: 771014 $ $Date: 2009-05-03 03:33:01 +0200 (Sun, 03 May 2009) $

Author: Craig R. McClanahan Remy Maucherat

Field Summary
protected longavailable
The date and time at which this servlet will become available (in milliseconds since the epoch), or zero if the servlet is available.
protected NotificationBroadcasterSupportbroadcaster
The broadcaster that sends j2ee notifications.
protected intclassLoadTime
protected static Class[]classType
Static class array used when the SecurityManager is turned on and Servlet.init is invoked.
protected static Class[]classTypeUsedInService
Static class array used when the SecurityManager is turned on and Servlet.service is invoked.
protected AtomicIntegercountAllocated
The count of allocations that are currently active (even if they are for the same instance, as will be true on a non-STM servlet).
protected static String[]DEFAULT_SERVLET_METHODS
protected StandardWrapperFacadefacade
The facade associated with this wrapper.
protected static Stringinfo
The descriptive information string for this implementation.
protected Servletinstance
The (single) initialized instance of this servlet.
protected StackinstancePool
Stack containing the STM instances.
protected InstanceSupportinstanceSupport
The support object for our instance listeners.
protected booleanisJspServlet
True if this StandardWrapper is for the JspServlet
protected StringjspFile
The context-relative URI of the JSP file for this servlet.
protected ObjectNamejspMonitorON
The ObjectName of the JSP monitoring mbean
protected intloadOnStartup
The load-on-startup order value (negative value means load on first call) for this servlet.
protected longloadTime
protected static Loglog
protected ArrayListmappings
Mappings associated with the wrapper.
protected intmaxInstances
Maximum number of STM instances.
protected intnInstances
Number of instances currently loaded for a STM servlet.
protected MBeanNotificationInfo[]notificationInfo
protected HashMapparameters
The initialization parameters for this servlet, keyed by parameter name.
protected HashMapreferences
The security role references for this servlet, keyed by role name used in the servlet.
protected static PropertiesrestrictedServlets
Restricted servlets (which can only be loaded by a privileged webapp).
protected StringrunAs
The run-as identity for this servlet.
protected longsequenceNumber
The notification sequence number.
protected StringservletClass
The fully qualified servlet class name for this servlet.
protected booleansingleThreadModel
Does this servlet implement the SingleThreadModel interface?
protected booleanswallowOutput
Should we swallow System.out
protected StandardWrapperValveswValve
protected longunloadDelay
Wait time for servlet unload in ms.
protected booleanunloading
Are we unloading our servlet instance at the moment?
Constructor Summary
StandardWrapper()
Create a new StandardWrapper component with the default basic Valve.
Method Summary
voidaddChild(Container child)
Refuse to add a child Container, because Wrappers are the lowest level of the Container hierarchy.
protected voidaddDefaultMapper(String mapperClass)
Add a default Mapper implementation if none have been configured explicitly.
voidaddInitParameter(String name, String value)
Add a new servlet initialization parameter for this servlet.
voidaddInstanceListener(InstanceListener listener)
Add a new listener interested in InstanceEvents.
voidaddMapping(String mapping)
Add a mapping associated with the Wrapper.
voidaddNotificationListener(NotificationListener listener, NotificationFilter filter, Object object)
voidaddSecurityReference(String name, String link)
Add a new security role reference record to the set of records for this servlet.
Servletallocate()
Allocate an initialized instance of this Servlet that is ready to have its service() method called.
voidbackgroundProcess()
Execute a periodic task, such as reloading, etc.
voiddeallocate(Servlet servlet)
Return this previously allocated servlet to the pool of available instances.
StringfindInitParameter(String name)
Return the value for the specified initialization parameter name, if any; otherwise return null.
String[]findInitParameters()
Return the names of all defined initialization parameters for this servlet.
WrapperfindMappingObject()
FIXME: Fooling introspection ...
String[]findMappings()
Return the mappings associated with this wrapper.
StringfindSecurityReference(String name)
Return the security role link for the specified security role reference name, if any; otherwise return null.
String[]findSecurityReferences()
Return the set of security role reference names associated with this servlet, if any; otherwise return a zero-length array.
protected Method[]getAllDeclaredMethods(Class c)
longgetAvailable()
Return the available date/time for this servlet, in milliseconds since the epoch.
intgetClassLoadTime()
intgetCountAllocated()
Return the number of active allocations of this servlet, even if they are all for the same instance (as will be true for servlets that do not implement SingleThreadModel.
StringgetEngineName()
intgetErrorCount()
StringgetInfo()
Return descriptive information about this Container implementation and the corresponding version number, in the format <description>/<version>.
StringgetInitParameter(String name)
Return the initialization parameter value for the specified name, if any; otherwise return null.
EnumerationgetInitParameterNames()
Return the set of initialization parameter names defined for this servlet.
InstanceSupportgetInstanceSupport()
Return the InstanceSupport object for this Wrapper instance.
StringgetJspFile()
Return the context-relative URI of the JSP file for this servlet.
intgetLoadOnStartup()
Return the load-on-startup order value (negative value means load on first call).
StringgetLoadOnStartupString()
longgetLoadTime()
intgetMaxInstances()
Return maximum number of instances that will be allocated when a single thread model servlet is used.
longgetMaxTime()
longgetMinTime()
MBeanNotificationInfo[]getNotificationInfo()
longgetProcessingTime()
intgetRequestCount()
static ThrowablegetRootCause(ServletException e)
Extract the root cause from a servlet exception.
StringgetRunAs()
Return the run-as identity for this servlet.
ServletgetServlet()
Return the associated servlet instance.
StringgetServletClass()
Return the fully qualified servlet class name for this servlet.
ServletContextgetServletContext()
Return the servlet context with which this servlet is associated.
String[]getServletMethods()
Gets the names of the methods supported by the underlying servlet.
StringgetServletName()
Return the name of this servlet.
voidincrementErrorCount()
Increment the error count used for monitoring.
protected booleanisContainerProvidedServlet(String classname)
Return true if the specified class name represents a container provided servlet class that should be loaded by the server class loader.
booleanisEventProvider()
protected booleanisServletAllowed(Object servlet)
Return true if loading this servlet is allowed.
booleanisSingleThreadModel()
Return true if the servlet class represented by this component implements the SingleThreadModel interface.
booleanisStateManageable()
booleanisStatisticsProvider()
booleanisUnavailable()
Is this servlet currently unavailable?
voidload()
Load and initialize an instance of this servlet, if there is not already at least one initialized instance.
ServletloadServlet()
Load and initialize an instance of this servlet, if there is not already at least one initialized instance.
protected voidregisterJMX(StandardContext ctx)
voidremoveInitParameter(String name)
Remove the specified initialization parameter from this servlet.
voidremoveInstanceListener(InstanceListener listener)
Remove a listener no longer interested in InstanceEvents.
voidremoveMapping(String mapping)
Remove a mapping associated with the wrapper.
voidremoveNotificationListener(NotificationListener listener, NotificationFilter filter, Object object)
voidremoveNotificationListener(NotificationListener listener)
Remove a JMX-NotificationListener
voidremoveSecurityReference(String name)
Remove any security role reference for the specified role name.
voidsetAvailable(long available)
Set the available date/time for this servlet, in milliseconds since the epoch.
voidsetErrorCount(int errorCount)
voidsetJspFile(String jspFile)
Set the context-relative URI of the JSP file for this servlet.
voidsetLoadOnStartup(int value)
Set the load-on-startup order value (negative value means load on first call).
voidsetLoadOnStartupString(String value)
Set the load-on-startup order value from a (possibly null) string.
voidsetLoadTime(long loadTime)
voidsetMaxInstances(int maxInstances)
Set the maximum number of instances that will be allocated when a single thread model servlet is used.
voidsetMaxTime(long maxTime)
voidsetMinTime(long minTime)
voidsetParent(Container container)
Set the parent Container of this Wrapper, but only if it is a Context.
voidsetProcessingTime(long processingTime)
voidsetRequestCount(int requestCount)
voidsetRunAs(String runAs)
Set the run-as identity for this servlet.
voidsetServletClass(String servletClass)
Set the fully qualified servlet class name for this servlet.
voidsetServletName(String name)
Set the name of this servlet.
voidstart()
Start this component, pre-loading the servlet if the load-on-startup value is set appropriately.
voidstop()
Stop this component, gracefully shutting down the servlet if it has been initialized.
StringtoString()
Return a String representation of this component.
voidunavailable(UnavailableException unavailable)
Process an UnavailableException, marking this servlet as unavailable for the specified amount of time.
voidunload()
Unload all initialized instances of this servlet, after calling the destroy() method for each instance.

Field Detail

available

protected long available
The date and time at which this servlet will become available (in milliseconds since the epoch), or zero if the servlet is available. If this value equals Long.MAX_VALUE, the unavailability of this servlet is considered permanent.

broadcaster

protected NotificationBroadcasterSupport broadcaster
The broadcaster that sends j2ee notifications.

classLoadTime

protected int classLoadTime

classType

protected static Class[] classType
Static class array used when the SecurityManager is turned on and Servlet.init is invoked.

classTypeUsedInService

protected static Class[] classTypeUsedInService
Static class array used when the SecurityManager is turned on and Servlet.service is invoked.

countAllocated

protected AtomicInteger countAllocated
The count of allocations that are currently active (even if they are for the same instance, as will be true on a non-STM servlet).

DEFAULT_SERVLET_METHODS

protected static final String[] DEFAULT_SERVLET_METHODS

facade

protected StandardWrapperFacade facade
The facade associated with this wrapper.

info

protected static final String info
The descriptive information string for this implementation.

instance

protected Servlet instance
The (single) initialized instance of this servlet.

instancePool

protected Stack instancePool
Stack containing the STM instances.

instanceSupport

protected InstanceSupport instanceSupport
The support object for our instance listeners.

isJspServlet

protected boolean isJspServlet
True if this StandardWrapper is for the JspServlet

jspFile

protected String jspFile
The context-relative URI of the JSP file for this servlet.

jspMonitorON

protected ObjectName jspMonitorON
The ObjectName of the JSP monitoring mbean

loadOnStartup

protected int loadOnStartup
The load-on-startup order value (negative value means load on first call) for this servlet.

loadTime

protected long loadTime

log

protected static Log log

mappings

protected ArrayList mappings
Mappings associated with the wrapper.

maxInstances

protected int maxInstances
Maximum number of STM instances.

nInstances

protected int nInstances
Number of instances currently loaded for a STM servlet.

notificationInfo

protected MBeanNotificationInfo[] notificationInfo

parameters

protected HashMap parameters
The initialization parameters for this servlet, keyed by parameter name.

references

protected HashMap references
The security role references for this servlet, keyed by role name used in the servlet. The corresponding value is the role name of the web application itself.

restrictedServlets

protected static Properties restrictedServlets
Restricted servlets (which can only be loaded by a privileged webapp).

runAs

protected String runAs
The run-as identity for this servlet.

sequenceNumber

protected long sequenceNumber
The notification sequence number.

servletClass

protected String servletClass
The fully qualified servlet class name for this servlet.

singleThreadModel

protected boolean singleThreadModel
Does this servlet implement the SingleThreadModel interface?

swallowOutput

protected boolean swallowOutput
Should we swallow System.out

swValve

protected StandardWrapperValve swValve

unloadDelay

protected long unloadDelay
Wait time for servlet unload in ms.

unloading

protected boolean unloading
Are we unloading our servlet instance at the moment?

Constructor Detail

StandardWrapper

public StandardWrapper()
Create a new StandardWrapper component with the default basic Valve.

Method Detail

addChild

public void addChild(Container child)
Refuse to add a child Container, because Wrappers are the lowest level of the Container hierarchy.

Parameters: child Child container to be added

addDefaultMapper

protected void addDefaultMapper(String mapperClass)
Add a default Mapper implementation if none have been configured explicitly.

Parameters: mapperClass Java class name of the default Mapper

addInitParameter

public void addInitParameter(String name, String value)
Add a new servlet initialization parameter for this servlet.

Parameters: name Name of this initialization parameter to add value Value of this initialization parameter to add

addInstanceListener

public void addInstanceListener(InstanceListener listener)
Add a new listener interested in InstanceEvents.

Parameters: listener The new listener

addMapping

public void addMapping(String mapping)
Add a mapping associated with the Wrapper.

Parameters: mapping The new wrapper mapping

addNotificationListener

public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object object)

addSecurityReference

public void addSecurityReference(String name, String link)
Add a new security role reference record to the set of records for this servlet.

Parameters: name Role name used within this servlet link Role name used within the web application

allocate

public Servlet allocate()
Allocate an initialized instance of this Servlet that is ready to have its service() method called. If the servlet class does not implement SingleThreadModel, the (only) initialized instance may be returned immediately. If the servlet class implements SingleThreadModel, the Wrapper implementation must ensure that this instance is not allocated again until it is deallocated by a call to deallocate().

Throws: ServletException if the servlet init() method threw an exception ServletException if a loading error occurs

backgroundProcess

public void backgroundProcess()
Execute a periodic task, such as reloading, etc. This method will be invoked inside the classloading context of this container. Unexpected throwables will be caught and logged.

deallocate

public void deallocate(Servlet servlet)
Return this previously allocated servlet to the pool of available instances. If this servlet class does not implement SingleThreadModel, no action is actually required.

Parameters: servlet The servlet to be returned

Throws: ServletException if a deallocation error occurs

findInitParameter

public String findInitParameter(String name)
Return the value for the specified initialization parameter name, if any; otherwise return null.

Parameters: name Name of the requested initialization parameter

findInitParameters

public String[] findInitParameters()
Return the names of all defined initialization parameters for this servlet.

findMappingObject

public Wrapper findMappingObject()
FIXME: Fooling introspection ...

findMappings

public String[] findMappings()
Return the mappings associated with this wrapper.

findSecurityReference

public String findSecurityReference(String name)
Return the security role link for the specified security role reference name, if any; otherwise return null.

Parameters: name Security role reference used within this servlet

findSecurityReferences

public String[] findSecurityReferences()
Return the set of security role reference names associated with this servlet, if any; otherwise return a zero-length array.

getAllDeclaredMethods

protected Method[] getAllDeclaredMethods(Class c)

getAvailable

public long getAvailable()
Return the available date/time for this servlet, in milliseconds since the epoch. If this date/time is Long.MAX_VALUE, it is considered to mean that unavailability is permanent and any request for this servlet will return an SC_NOT_FOUND error. If this date/time is in the future, any request for this servlet will return an SC_SERVICE_UNAVAILABLE error. If it is zero, the servlet is currently available.

getClassLoadTime

public int getClassLoadTime()

getCountAllocated

public int getCountAllocated()
Return the number of active allocations of this servlet, even if they are all for the same instance (as will be true for servlets that do not implement SingleThreadModel.

getEngineName

public String getEngineName()

getErrorCount

public int getErrorCount()

getInfo

public String getInfo()
Return descriptive information about this Container implementation and the corresponding version number, in the format <description>/<version>.

getInitParameter

public String getInitParameter(String name)
Return the initialization parameter value for the specified name, if any; otherwise return null.

Parameters: name Name of the initialization parameter to retrieve

getInitParameterNames

public Enumeration getInitParameterNames()
Return the set of initialization parameter names defined for this servlet. If none are defined, an empty Enumeration is returned.

getInstanceSupport

public InstanceSupport getInstanceSupport()
Return the InstanceSupport object for this Wrapper instance.

getJspFile

public String getJspFile()
Return the context-relative URI of the JSP file for this servlet.

getLoadOnStartup

public int getLoadOnStartup()
Return the load-on-startup order value (negative value means load on first call).

getLoadOnStartupString

public String getLoadOnStartupString()

getLoadTime

public long getLoadTime()

getMaxInstances

public int getMaxInstances()
Return maximum number of instances that will be allocated when a single thread model servlet is used.

getMaxTime

public long getMaxTime()

getMinTime

public long getMinTime()

getNotificationInfo

public MBeanNotificationInfo[] getNotificationInfo()

getProcessingTime

public long getProcessingTime()

getRequestCount

public int getRequestCount()

getRootCause

public static Throwable getRootCause(ServletException e)
Extract the root cause from a servlet exception.

Parameters: e The servlet exception

getRunAs

public String getRunAs()
Return the run-as identity for this servlet.

getServlet

public Servlet getServlet()
Return the associated servlet instance.

getServletClass

public String getServletClass()
Return the fully qualified servlet class name for this servlet.

getServletContext

public ServletContext getServletContext()
Return the servlet context with which this servlet is associated.

getServletMethods

public String[] getServletMethods()
Gets the names of the methods supported by the underlying servlet. This is the same set of methods included in the Allow response header in response to an OPTIONS request method processed by the underlying servlet.

Returns: Array of names of the methods supported by the underlying servlet

getServletName

public String getServletName()
Return the name of this servlet.

incrementErrorCount

public void incrementErrorCount()
Increment the error count used for monitoring.

isContainerProvidedServlet

protected boolean isContainerProvidedServlet(String classname)
Return true if the specified class name represents a container provided servlet class that should be loaded by the server class loader.

Parameters: classname Name of the class to be checked

isEventProvider

public boolean isEventProvider()

isServletAllowed

protected boolean isServletAllowed(Object servlet)
Return true if loading this servlet is allowed.

isSingleThreadModel

public boolean isSingleThreadModel()
Return true if the servlet class represented by this component implements the SingleThreadModel interface.

isStateManageable

public boolean isStateManageable()

isStatisticsProvider

public boolean isStatisticsProvider()

isUnavailable

public boolean isUnavailable()
Is this servlet currently unavailable?

load

public void load()
Load and initialize an instance of this servlet, if there is not already at least one initialized instance. This can be used, for example, to load servlets that are marked in the deployment descriptor to be loaded at server startup time.

IMPLEMENTATION NOTE: Servlets whose classnames begin with org.apache.catalina. (so-called "container" servlets) are loaded by the same classloader that loaded this class, rather than the classloader for the current web application. This gives such classes access to Catalina internals, which are prevented for classes loaded for web applications.

Throws: ServletException if the servlet init() method threw an exception ServletException if some other loading problem occurs

loadServlet

public Servlet loadServlet()
Load and initialize an instance of this servlet, if there is not already at least one initialized instance. This can be used, for example, to load servlets that are marked in the deployment descriptor to be loaded at server startup time.

registerJMX

protected void registerJMX(StandardContext ctx)

removeInitParameter

public void removeInitParameter(String name)
Remove the specified initialization parameter from this servlet.

Parameters: name Name of the initialization parameter to remove

removeInstanceListener

public void removeInstanceListener(InstanceListener listener)
Remove a listener no longer interested in InstanceEvents.

Parameters: listener The listener to remove

removeMapping

public void removeMapping(String mapping)
Remove a mapping associated with the wrapper.

Parameters: mapping The pattern to remove

removeNotificationListener

public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object object)

removeNotificationListener

public void removeNotificationListener(NotificationListener listener)
Remove a JMX-NotificationListener

See Also: javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener)

removeSecurityReference

public void removeSecurityReference(String name)
Remove any security role reference for the specified role name.

Parameters: name Security role used within this servlet to be removed

setAvailable

public void setAvailable(long available)
Set the available date/time for this servlet, in milliseconds since the epoch. If this date/time is Long.MAX_VALUE, it is considered to mean that unavailability is permanent and any request for this servlet will return an SC_NOT_FOUND error. If this date/time is in the future, any request for this servlet will return an SC_SERVICE_UNAVAILABLE error.

Parameters: available The new available date/time

setErrorCount

public void setErrorCount(int errorCount)

setJspFile

public void setJspFile(String jspFile)
Set the context-relative URI of the JSP file for this servlet.

Parameters: jspFile JSP file URI

setLoadOnStartup

public void setLoadOnStartup(int value)
Set the load-on-startup order value (negative value means load on first call).

Parameters: value New load-on-startup value

setLoadOnStartupString

public void setLoadOnStartupString(String value)
Set the load-on-startup order value from a (possibly null) string. Per the specification, any missing or non-numeric value is converted to a zero, so that this servlet will still be loaded at startup time, but in an arbitrary order.

Parameters: value New load-on-startup value

setLoadTime

public void setLoadTime(long loadTime)

setMaxInstances

public void setMaxInstances(int maxInstances)
Set the maximum number of instances that will be allocated when a single thread model servlet is used.

Parameters: maxInstances New value of maxInstances

setMaxTime

public void setMaxTime(long maxTime)

setMinTime

public void setMinTime(long minTime)

setParent

public void setParent(Container container)
Set the parent Container of this Wrapper, but only if it is a Context.

Parameters: container Proposed parent Container

setProcessingTime

public void setProcessingTime(long processingTime)

setRequestCount

public void setRequestCount(int requestCount)

setRunAs

public void setRunAs(String runAs)
Set the run-as identity for this servlet.

Parameters: runAs New run-as identity value

setServletClass

public void setServletClass(String servletClass)
Set the fully qualified servlet class name for this servlet.

Parameters: servletClass Servlet class name

setServletName

public void setServletName(String name)
Set the name of this servlet. This is an alias for the normal Container.setName() method, and complements the getServletName() method required by the ServletConfig interface.

Parameters: name The new name of this servlet

start

public void start()
Start this component, pre-loading the servlet if the load-on-startup value is set appropriately.

Throws: LifecycleException if a fatal error occurs during startup

stop

public void stop()
Stop this component, gracefully shutting down the servlet if it has been initialized.

Throws: LifecycleException if a fatal error occurs during shutdown

toString

public String toString()
Return a String representation of this component.

unavailable

public void unavailable(UnavailableException unavailable)
Process an UnavailableException, marking this servlet as unavailable for the specified amount of time.

Parameters: unavailable The exception that occurred, or null to mark this servlet as permanently unavailable

unload

public void unload()
Unload all initialized instances of this servlet, after calling the destroy() method for each instance. This can be used, for example, prior to shutting down the entire servlet engine, or prior to reloading all of the classes from the Loader associated with our Loader's repository.

Throws: ServletException if an exception is thrown by the destroy() method

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.