Package org.apache.catalina.core
Class StandardWrapper
java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.util.LifecycleMBeanBase
org.apache.catalina.core.ContainerBase
org.apache.catalina.core.StandardWrapper
- All Implemented Interfaces:
ServletConfig
,MBeanRegistration
,NotificationBroadcaster
,NotificationEmitter
,Container
,JmxEnabled
,Lifecycle
,Wrapper
- Direct Known Subclasses:
Tomcat.ExistingStandardWrapper
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.
- Author:
- Craig R. McClanahan, Remy Maucherat
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.catalina.core.ContainerBase
ContainerBase.ContainerBackgroundProcessor, ContainerBase.ContainerBackgroundProcessorMonitor, ContainerBase.PrivilegedAddChild
Nested classes/interfaces inherited from interface org.apache.catalina.Lifecycle
Lifecycle.SingleUse
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Async supportprotected long
The date and time at which this servlet will become available (in milliseconds since the epoch), or zero if the servlet is available.protected final NotificationBroadcasterSupport
The broadcaster that sends j2ee notifications.protected int
protected static Class<?>[]
Static class array used when the SecurityManager is turned on andServlet.init
is invoked.protected final AtomicInteger
The count of allocations that are currently active.protected static final String[]
protected boolean
Enabledprotected final StandardWrapperFacade
The facade associated with this wrapper.protected Servlet
The (single) possibly uninitialized instance of this servlet.protected boolean
Flag that indicates if this instance has been initializedprotected boolean
True if this StandardWrapper is for the JspServletprotected ObjectName
The ObjectName of the JSP monitoring mbeanprotected int
The load-on-startup order value (negative value means load on first call) for this servlet.protected long
Mappings associated with the wrapper.protected MultipartConfigElement
Multipart configprotected MBeanNotificationInfo[]
The initialization parameters for this servlet, keyed by parameter name.The security role references for this servlet, keyed by role name used in the servlet.protected String
The run-as identity for this servlet.protected long
The notification sequence number.protected String
The fully qualified servlet class name for this servlet.protected boolean
Should we swallow System.outprotected org.apache.catalina.core.StandardWrapperValve
protected long
Wait time for servlet unload in ms.protected boolean
Are we unloading our servlet instance at the moment?Fields inherited from class org.apache.catalina.core.ContainerBase
accessLog, backgroundProcessorDelay, backgroundProcessorFuture, children, cluster, listeners, logger, logName, monitorFuture, name, parent, parentClassLoader, pipeline, sm, startChildren, startStopExecutor, support
Fields inherited from interface org.apache.catalina.Container
ADD_CHILD_EVENT, ADD_VALVE_EVENT, REMOVE_CHILD_EVENT, REMOVE_VALVE_EVENT
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
Fields inherited from interface org.apache.catalina.Wrapper
ADD_MAPPING_EVENT, REMOVE_MAPPING_EVENT
-
Constructor Summary
ConstructorDescriptionCreate a new StandardWrapper component with the default basic Valve. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Refuse to add a child Container, because Wrappers are the lowest level of the Container hierarchy.void
addInitParameter
(String name, String value) Add a new servlet initialization parameter for this servlet.void
addMapping
(String mapping) Add a mapping associated with the Wrapper.void
addNotificationListener
(NotificationListener listener, NotificationFilter filter, Object object) void
addSecurityReference
(String name, String link) Add a new security role reference record to the set of records for this servlet.allocate()
Allocate an initialized instance of this Servlet that is ready to have itsservice()
method called.void
Execute a periodic task, such as reloading, etc.void
deallocate
(Servlet servlet) Decrement the allocation count for the servlet instance.findInitParameter
(String name) String[]
String[]
findSecurityReference
(String name) String[]
protected Method[]
getAllDeclaredMethods
(Class<?> c) long
int
int
int
Deprecated.The return type will change to long in Tomcat 11 onwards.getInitParameter
(String name) Returns aString
containing the value of the named initialization parameter, ornull
if the parameter does not exist.Returns the names of the servlet's initialization parameters as anEnumeration
ofString
objects, or an emptyEnumeration
if the servlet has no initialization parameters.int
long
long
long
protected String
Allow sub-classes to specify the key properties component of theObjectName
that will be used to register this component.long
int
Deprecated.The return type will change to long in Tomcat 11 onwards.static Throwable
Extract the root cause from a servlet exception.getRunAs()
Returns a reference to theServletContext
in which the caller is executing.String[]
Gets the names of the methods supported by the underlying servlet.Returns the name of this servlet instance.void
Increment the error count used for monitoring.boolean
Does the associated Servlet support async processing?boolean
Is the associated Servlet enabled?boolean
Is the Servlet overridable by a ServletContainerInitializer?boolean
void
load()
Load and initialize an instance of this Servlet, if there is not already at least one initialized instance.Load and initialize an instance of this servlet, if there is not already an initialized instance.void
removeInitParameter
(String name) Remove the specified initialization parameter from this Servlet.void
removeMapping
(String mapping) Remove a mapping associated with the wrapper.void
void
removeNotificationListener
(NotificationListener listener, NotificationFilter filter, Object object) void
Remove any security role reference for the specified role name.void
setAsyncSupported
(boolean asyncSupported) Set the async support for the associated Servlet.void
setAvailable
(long available) Set the available date/time for this servlet, in milliseconds since the epoch.void
setEnabled
(boolean enabled) Sets the enabled attribute for the associated servlet.void
setLoadOnStartup
(int value) Set the load-on-startup order value (negative value means load on first call).void
setLoadOnStartupString
(String value) Set the load-on-startup order value from a (possibly null) string.void
setMultipartConfigElement
(MultipartConfigElement multipartConfigElement) Set the multi-part configuration for the associated Servlet.void
setOverridable
(boolean overridable) Sets the overridable attribute for this Servlet.void
Set the parent Container of this Wrapper, but only if it is a Context.void
Set the run-as identity for this servlet.void
setServlet
(Servlet servlet) Set the associated Servlet instancevoid
setServletClass
(String servletClass) Set the fully qualified servlet class name for this servlet.void
setServletName
(String name) Set the name of this servlet.protected void
Start this component and implement the requirements ofLifecycleBase.startInternal()
.protected void
Stop this component and implement the requirements ofLifecycleBase.stopInternal()
.void
unavailable
(UnavailableException unavailable) Process an UnavailableException, marking this Servlet as unavailable for the specified amount of time.void
unload()
Unload all initialized instances of this servlet, after calling thedestroy()
method for each instance.Methods inherited from class org.apache.catalina.core.ContainerBase
addContainerListener, addPropertyChangeListener, addValve, destroyInternal, findChild, findChildren, findContainerListeners, fireContainerEvent, getAccessLog, getBackgroundProcessorDelay, getCatalinaBase, getCatalinaHome, getChildren, getCluster, getClusterInternal, getDomainInternal, getLogger, getLogName, getMBeanKeyProperties, getName, getParent, getParentClassLoader, getPipeline, getRealm, getRealmInternal, getStartChildren, getStartStopThreads, logAccess, removeChild, removeContainerListener, removePropertyChangeListener, setBackgroundProcessorDelay, setCluster, setName, setParentClassLoader, setRealm, setStartChildren, setStartStopThreads, threadStart, threadStop, toString
Methods inherited from class org.apache.catalina.util.LifecycleMBeanBase
getDomain, getObjectName, initInternal, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregister
Methods inherited from class org.apache.catalina.util.LifecycleBase
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.catalina.Container
addContainerListener, addPropertyChangeListener, findChild, findChildren, findContainerListeners, fireContainerEvent, getAccessLog, getBackgroundProcessorDelay, getCatalinaBase, getCatalinaHome, getCluster, getDomain, getLogger, getLogName, getMBeanKeyProperties, getName, getObjectName, getParent, getParentClassLoader, getPipeline, getRealm, getStartStopThreads, logAccess, removeChild, removeContainerListener, removePropertyChangeListener, setBackgroundProcessorDelay, setCluster, setName, setParentClassLoader, setRealm, setStartStopThreads
Methods inherited from interface org.apache.catalina.Lifecycle
addLifecycleListener, destroy, findLifecycleListeners, getState, getStateName, init, removeLifecycleListener, start, stop
-
Field Details
-
DEFAULT_SERVLET_METHODS
-
available
protected long availableThe 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
The broadcaster that sends j2ee notifications. -
countAllocated
The count of allocations that are currently active. -
facade
The facade associated with this wrapper. -
instance
The (single) possibly uninitialized instance of this servlet. -
instanceInitialized
protected volatile boolean instanceInitializedFlag that indicates if this instance has been initialized -
loadOnStartup
protected int loadOnStartupThe load-on-startup order value (negative value means load on first call) for this servlet. -
mappings
-
parameters
-
references
-
runAs
The run-as identity for this servlet. -
sequenceNumber
protected long sequenceNumberThe notification sequence number. -
servletClass
The fully qualified servlet class name for this servlet. -
unloading
protected volatile boolean unloadingAre we unloading our servlet instance at the moment? -
unloadDelay
protected long unloadDelayWait time for servlet unload in ms. -
isJspServlet
protected boolean isJspServletTrue if this StandardWrapper is for the JspServlet -
jspMonitorON
The ObjectName of the JSP monitoring mbean -
swallowOutput
protected boolean swallowOutputShould we swallow System.out -
swValve
protected org.apache.catalina.core.StandardWrapperValve swValve -
loadTime
protected long loadTime -
classLoadTime
protected int classLoadTime -
multipartConfigElement
Multipart config -
asyncSupported
protected boolean asyncSupportedAsync support -
enabled
protected boolean enabledEnabled -
classType
Static class array used when the SecurityManager is turned on andServlet.init
is invoked. -
notificationInfo
-
-
Constructor Details
-
StandardWrapper
public StandardWrapper()Create a new StandardWrapper component with the default basic Valve.
-
-
Method Details
-
isOverridable
public boolean isOverridable()Description copied from interface:Wrapper
Is the Servlet overridable by a ServletContainerInitializer?- Specified by:
isOverridable
in interfaceWrapper
- Returns:
true
if the Servlet can be overridden in a ServletContainerInitializer
-
setOverridable
public void setOverridable(boolean overridable) Description copied from interface:Wrapper
Sets the overridable attribute for this Servlet.- Specified by:
setOverridable
in interfaceWrapper
- Parameters:
overridable
- the new value
-
getAvailable
public long getAvailable()- Specified by:
getAvailable
in interfaceWrapper
- Returns:
- the available date/time for this servlet, in milliseconds since the epoch. 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. A value equal to Long.MAX_VALUE is considered to mean that unavailability is permanent.
-
setAvailable
public void setAvailable(long available) Description copied from interface:Wrapper
Set the available date/time for this servlet, in milliseconds since the epoch. If this date/time is in the future, any request for this servlet will return an SC_SERVICE_UNAVAILABLE error. A value equal to Long.MAX_VALUE is considered to mean that unavailability is permanent.- Specified by:
setAvailable
in interfaceWrapper
- Parameters:
available
- The new available date/time
-
getCountAllocated
public int getCountAllocated()- Returns:
- the number of active allocations of this servlet.
-
getLoadOnStartup
public int getLoadOnStartup()- Specified by:
getLoadOnStartup
in interfaceWrapper
- Returns:
- the load-on-startup order value (negative value means load on first call).
-
setLoadOnStartup
public void setLoadOnStartup(int value) Description copied from interface:Wrapper
Set the load-on-startup order value (negative value means load on first call).- Specified by:
setLoadOnStartup
in interfaceWrapper
- Parameters:
value
- New load-on-startup value
-
setLoadOnStartupString
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
-
getLoadOnStartupString
- Returns:
- the load-on-startup value that was parsed
-
setParent
Set the parent Container of this Wrapper, but only if it is a Context.- Specified by:
setParent
in interfaceContainer
- Overrides:
setParent
in classContainerBase
- Parameters:
container
- Proposed parent Container
-
getRunAs
-
setRunAs
-
getServletClass
- Specified by:
getServletClass
in interfaceWrapper
- Returns:
- the fully qualified servlet class name for this servlet.
-
setServletClass
Description copied from interface:Wrapper
Set the fully qualified servlet class name for this servlet.- Specified by:
setServletClass
in interfaceWrapper
- Parameters:
servletClass
- Servlet class name
-
setServletName
Set the name of this servlet. This is an alias for the normalContainer.setName()
method, and complements thegetServletName()
method required by theServletConfig
interface.- Parameters:
name
- The new name of this servlet
-
getServletMethods
Description copied from interface:Wrapper
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.- Specified by:
getServletMethods
in interfaceWrapper
- Returns:
- Array of names of the methods supported by the underlying servlet
- Throws:
ServletException
- If the target servlet cannot be loaded
-
getServlet
- Specified by:
getServlet
in interfaceWrapper
- Returns:
- the associated Servlet instance.
-
setServlet
Description copied from interface:Wrapper
Set the associated Servlet instance- Specified by:
setServlet
in interfaceWrapper
- Parameters:
servlet
- The associated Servlet
-
backgroundProcess
public void backgroundProcess()Description copied from interface:Container
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.- Specified by:
backgroundProcess
in interfaceContainer
- Overrides:
backgroundProcess
in classContainerBase
-
getRootCause
Extract the root cause from a servlet exception.- Parameters:
e
- The servlet exception- Returns:
- the root cause of the Servlet exception
-
addChild
Refuse to add a child Container, because Wrappers are the lowest level of the Container hierarchy.- Specified by:
addChild
in interfaceContainer
- Overrides:
addChild
in classContainerBase
- Parameters:
child
- Child container to be added
-
addInitParameter
Description copied from interface:Wrapper
Add a new servlet initialization parameter for this servlet.- Specified by:
addInitParameter
in interfaceWrapper
- Parameters:
name
- Name of this initialization parameter to addvalue
- Value of this initialization parameter to add
-
addMapping
Description copied from interface:Wrapper
Add a mapping associated with the Wrapper.- Specified by:
addMapping
in interfaceWrapper
- Parameters:
mapping
- The new wrapper mapping
-
addSecurityReference
Description copied from interface:Wrapper
Add a new security role reference record to the set of records for this servlet.- Specified by:
addSecurityReference
in interfaceWrapper
- Parameters:
name
- Role name used within this servletlink
- Role name used within the web application
-
allocate
Description copied from interface:Wrapper
Allocate an initialized instance of this Servlet that is ready to have itsservice()
method called. The previously initialized instance may be returned immediately.- Specified by:
allocate
in interfaceWrapper
- Returns:
- a new Servlet instance
- Throws:
ServletException
- if the Servlet init() method threw an exceptionServletException
- if a loading error occurs
-
deallocate
Description copied from interface:Wrapper
Decrement the allocation count for the servlet instance.- Specified by:
deallocate
in interfaceWrapper
- Parameters:
servlet
- The servlet to be returned- Throws:
ServletException
- if a deallocation error occurs
-
findInitParameter
- Specified by:
findInitParameter
in interfaceWrapper
- Parameters:
name
- Name of the requested initialization parameter- Returns:
- the value for the specified initialization parameter name, if any; otherwise return
null
.
-
findInitParameters
- Specified by:
findInitParameters
in interfaceWrapper
- Returns:
- the names of all defined initialization parameters for this servlet.
-
findMappings
- Specified by:
findMappings
in interfaceWrapper
- Returns:
- the mappings associated with this wrapper.
-
findSecurityReference
- Specified by:
findSecurityReference
in interfaceWrapper
- Parameters:
name
- Security role reference used within this servlet- Returns:
- the security role link for the specified security role reference name, if any; otherwise return
null
.
-
findSecurityReferences
- Specified by:
findSecurityReferences
in interfaceWrapper
- Returns:
- the set of security role reference names associated with this servlet, if any; otherwise return a zero-length array.
-
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.- Specified by:
load
in interfaceWrapper
- Throws:
ServletException
- if the Servlet init() method threw an exception or if some other loading problem occurs
-
loadServlet
Load and initialize an instance of this servlet, if there is not already an 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.- Returns:
- the loaded Servlet instance
- Throws:
ServletException
- for a Servlet load error
-
removeInitParameter
Description copied from interface:Wrapper
Remove the specified initialization parameter from this Servlet.- Specified by:
removeInitParameter
in interfaceWrapper
- Parameters:
name
- Name of the initialization parameter to remove
-
removeMapping
Description copied from interface:Wrapper
Remove a mapping associated with the wrapper.- Specified by:
removeMapping
in interfaceWrapper
- Parameters:
mapping
- The pattern to remove
-
removeSecurityReference
Description copied from interface:Wrapper
Remove any security role reference for the specified role name.- Specified by:
removeSecurityReference
in interfaceWrapper
- Parameters:
name
- Security role used within this servlet to be removed
-
unload
Description copied from interface:Wrapper
Unload all initialized instances of this servlet, after calling thedestroy()
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.- Specified by:
unload
in interfaceWrapper
- Throws:
ServletException
- if an unload error occurs
-
getInitParameter
Description copied from interface:jakarta.servlet.ServletConfig
Returns aString
containing the value of the named initialization parameter, ornull
if the parameter does not exist.- Specified by:
getInitParameter
in interfaceServletConfig
- Parameters:
name
- aString
specifying the name of the initialization parameter- Returns:
- a
String
containing the value of the initialization parameter
-
getInitParameterNames
Description copied from interface:jakarta.servlet.ServletConfig
Returns the names of the servlet's initialization parameters as anEnumeration
ofString
objects, or an emptyEnumeration
if the servlet has no initialization parameters.- Specified by:
getInitParameterNames
in interfaceServletConfig
- Returns:
- an
Enumeration
ofString
objects containing the names of the servlet's initialization parameters
-
getServletContext
Description copied from interface:jakarta.servlet.ServletConfig
Returns a reference to theServletContext
in which the caller is executing.- Specified by:
getServletContext
in interfaceServletConfig
- Returns:
- a
ServletContext
object, used by the caller to interact with its servlet container - See Also:
-
getServletName
Description copied from interface:jakarta.servlet.ServletConfig
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.- Specified by:
getServletName
in interfaceServletConfig
- Returns:
- the name of the servlet instance
-
getProcessingTime
public long getProcessingTime() -
getMaxTime
public long getMaxTime() -
getMinTime
public long getMinTime() -
getRequestCount
Deprecated.The return type will change to long in Tomcat 11 onwards. Callers of this method should switch to storing the result of calls to this method in a long value rather than an int.Returns the number of requests processed by the wrapper.- Returns:
- the number of requests processed by the wrapper.
-
getErrorCount
Deprecated.The return type will change to long in Tomcat 11 onwards. Callers of this method should switch to storing the result of calls to this method in a long value rather than an int.Returns the number of requests processed by the wrapper that resulted in an error.- Returns:
- the number of requests processed by the wrapper that resulted in an error.
-
incrementErrorCount
public void incrementErrorCount()Increment the error count used for monitoring.- Specified by:
incrementErrorCount
in interfaceWrapper
-
getLoadTime
public long getLoadTime() -
getClassLoadTime
public int getClassLoadTime() -
getMultipartConfigElement
- Specified by:
getMultipartConfigElement
in interfaceWrapper
- Returns:
- the multi-part configuration for the associated Servlet. If no multi-part configuration has been defined,
then
null
will be returned.
-
setMultipartConfigElement
Description copied from interface:Wrapper
Set the multi-part configuration for the associated Servlet. To clear the multi-part configuration specifynull
as the new value.- Specified by:
setMultipartConfigElement
in interfaceWrapper
- Parameters:
multipartConfigElement
- The configuration associated with the Servlet
-
isAsyncSupported
public boolean isAsyncSupported()Description copied from interface:Wrapper
Does the associated Servlet support async processing? Defaults tofalse
.- Specified by:
isAsyncSupported
in interfaceWrapper
- Returns:
true
if the Servlet supports async
-
setAsyncSupported
public void setAsyncSupported(boolean asyncSupported) Description copied from interface:Wrapper
Set the async support for the associated Servlet.- Specified by:
setAsyncSupported
in interfaceWrapper
- Parameters:
asyncSupported
- the new value
-
isEnabled
-
setEnabled
public void setEnabled(boolean enabled) Description copied from interface:Wrapper
Sets the enabled attribute for the associated servlet.- Specified by:
setEnabled
in interfaceWrapper
- Parameters:
enabled
- the new value
-
getAllDeclaredMethods
-
startInternal
Start this component and implement the requirements ofLifecycleBase.startInternal()
.- Overrides:
startInternal
in classContainerBase
- Throws:
LifecycleException
- if this component detects a fatal error that prevents this component from being used
-
stopInternal
Stop this component and implement the requirements ofLifecycleBase.stopInternal()
.- Overrides:
stopInternal
in classContainerBase
- Throws:
LifecycleException
- if this component detects a fatal error that prevents this component from being used
-
getObjectNameKeyProperties
Description copied from class:LifecycleMBeanBase
Allow sub-classes to specify the key properties component of theObjectName
that will be used to register this component.- Specified by:
getObjectNameKeyProperties
in classLifecycleMBeanBase
- Returns:
- The string representation of the key properties component of the desired
ObjectName
-
removeNotificationListener
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object object) throws ListenerNotFoundException - Specified by:
removeNotificationListener
in interfaceNotificationEmitter
- Throws:
ListenerNotFoundException
-
getNotificationInfo
- Specified by:
getNotificationInfo
in interfaceNotificationBroadcaster
-
addNotificationListener
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object object) throws IllegalArgumentException - Specified by:
addNotificationListener
in interfaceNotificationBroadcaster
- Throws:
IllegalArgumentException
-
removeNotificationListener
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException - Specified by:
removeNotificationListener
in interfaceNotificationBroadcaster
- Throws:
ListenerNotFoundException
-