Class StandardWrapper

  • All Implemented Interfaces:
    ServletConfig, javax.management.MBeanRegistration, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, Container, JmxEnabled, Lifecycle, Wrapper
    Direct Known Subclasses:
    Tomcat.ExistingStandardWrapper

    public class StandardWrapper
    extends ContainerBase
    implements ServletConfig, Wrapper, javax.management.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
    • Field Detail

      • DEFAULT_SERVLET_METHODS

        protected static final java.lang.String[] DEFAULT_SERVLET_METHODS
      • 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 final javax.management.NotificationBroadcasterSupport broadcaster
        The broadcaster that sends EE notifications.
      • countAllocated

        protected final java.util.concurrent.atomic.AtomicInteger countAllocated
        The count of allocations that are currently active.
      • instance

        protected volatile Servlet instance
        The (single) possibly uninitialized instance of this servlet.
      • instanceInitialized

        protected volatile boolean instanceInitialized
        Flag that indicates if this instance has been initialized
      • loadOnStartup

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

        protected final java.util.ArrayList<java.lang.String> mappings
        Mappings associated with the wrapper.
      • parameters

        protected java.util.HashMap<java.lang.String,​java.lang.String> parameters
        The initialization parameters for this servlet, keyed by parameter name.
      • references

        protected java.util.HashMap<java.lang.String,​java.lang.String> 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.
      • runAs

        protected java.lang.String runAs
        The run-as identity for this servlet.
      • sequenceNumber

        protected long sequenceNumber
        The notification sequence number.
      • servletClass

        protected java.lang.String servletClass
        The fully qualified servlet class name for this servlet.
      • unloading

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

        protected long unloadDelay
        Wait time for servlet unload in ms.
      • isJspServlet

        protected boolean isJspServlet
        True if this StandardWrapper is for the JspServlet
      • jspMonitorON

        protected javax.management.ObjectName jspMonitorON
        The ObjectName of the JSP monitoring mbean
      • swallowOutput

        protected boolean swallowOutput
        Should we swallow System.out
      • loadTime

        protected long loadTime
      • classLoadTime

        protected int classLoadTime
      • asyncSupported

        protected boolean asyncSupported
        Async support
      • enabled

        protected boolean enabled
        Enabled
      • classType

        protected static java.lang.Class<?>[] classType
        Static class array used when the SecurityManager is turned on and Servlet.init is invoked.
      • notificationInfo

        protected javax.management.MBeanNotificationInfo[] notificationInfo
    • Constructor Detail

      • StandardWrapper

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

      • isOverridable

        public boolean isOverridable()
        Description copied from interface: Wrapper
        Is the Servlet overridable by a ServletContainerInitializer?
        Specified by:
        isOverridable in interface Wrapper
        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 interface Wrapper
        Parameters:
        overridable - the new value
      • getAvailable

        public long getAvailable()
        Specified by:
        getAvailable in interface Wrapper
        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 interface Wrapper
        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 interface Wrapper
        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 interface Wrapper
        Parameters:
        value - New load-on-startup value
      • setLoadOnStartupString

        public void setLoadOnStartupString​(java.lang.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
      • getLoadOnStartupString

        public java.lang.String getLoadOnStartupString()
        Returns:
        the load-on-startup value that was parsed
      • setParent

        public void setParent​(Container container)
        Set the parent Container of this Wrapper, but only if it is a Context.
        Specified by:
        setParent in interface Container
        Overrides:
        setParent in class ContainerBase
        Parameters:
        container - Proposed parent Container
      • getRunAs

        public java.lang.String getRunAs()
        Specified by:
        getRunAs in interface Wrapper
        Returns:
        the run-as identity for this servlet.
      • setRunAs

        public void setRunAs​(java.lang.String runAs)
        Description copied from interface: Wrapper
        Set the run-as identity for this servlet.
        Specified by:
        setRunAs in interface Wrapper
        Parameters:
        runAs - New run-as identity value
      • getServletClass

        public java.lang.String getServletClass()
        Specified by:
        getServletClass in interface Wrapper
        Returns:
        the fully qualified servlet class name for this servlet.
      • setServletClass

        public void setServletClass​(java.lang.String servletClass)
        Description copied from interface: Wrapper
        Set the fully qualified servlet class name for this servlet.
        Specified by:
        setServletClass in interface Wrapper
        Parameters:
        servletClass - Servlet class name
      • setServletName

        public void setServletName​(java.lang.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
      • isUnavailable

        public boolean isUnavailable()
        Specified by:
        isUnavailable in interface Wrapper
        Returns:
        true if this Servlet is currently unavailable.
      • getServletMethods

        public java.lang.String[] getServletMethods()
                                             throws ServletException
        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 interface Wrapper
        Returns:
        Array of names of the methods supported by the underlying servlet
        Throws:
        ServletException - If the target servlet cannot be loaded
      • getServlet

        public Servlet getServlet()
        Specified by:
        getServlet in interface Wrapper
        Returns:
        the associated Servlet instance.
      • setServlet

        public void setServlet​(Servlet servlet)
        Description copied from interface: Wrapper
        Set the associated Servlet instance
        Specified by:
        setServlet in interface Wrapper
        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 interface Container
        Overrides:
        backgroundProcess in class ContainerBase
      • getRootCause

        public static java.lang.Throwable getRootCause​(ServletException e)
        Extract the root cause from a servlet exception.
        Parameters:
        e - The servlet exception
        Returns:
        the root cause of the Servlet exception
      • addChild

        public void addChild​(Container child)
        Refuse to add a child Container, because Wrappers are the lowest level of the Container hierarchy.
        Specified by:
        addChild in interface Container
        Overrides:
        addChild in class ContainerBase
        Parameters:
        child - Child container to be added
      • addInitParameter

        public void addInitParameter​(java.lang.String name,
                                     java.lang.String value)
        Description copied from interface: Wrapper
        Add a new servlet initialization parameter for this servlet.
        Specified by:
        addInitParameter in interface Wrapper
        Parameters:
        name - Name of this initialization parameter to add
        value - Value of this initialization parameter to add
      • addMapping

        public void addMapping​(java.lang.String mapping)
        Description copied from interface: Wrapper
        Add a mapping associated with the Wrapper.
        Specified by:
        addMapping in interface Wrapper
        Parameters:
        mapping - The new wrapper mapping
      • addSecurityReference

        public void addSecurityReference​(java.lang.String name,
                                         java.lang.String link)
        Description copied from interface: Wrapper
        Add a new security role reference record to the set of records for this servlet.
        Specified by:
        addSecurityReference in interface Wrapper
        Parameters:
        name - Role name used within this servlet
        link - Role name used within the web application
      • allocate

        public Servlet allocate()
                         throws ServletException
        Description copied from interface: Wrapper
        Allocate an initialized instance of this Servlet that is ready to have its service() method called. The previously initialized instance may be returned immediately.
        Specified by:
        allocate in interface Wrapper
        Returns:
        a new Servlet instance
        Throws:
        ServletException - if the Servlet init() method threw an exception
      • deallocate

        public void deallocate​(Servlet servlet)
                        throws ServletException
        Description copied from interface: Wrapper
        Decrement the allocation count for the servlet instance.
        Specified by:
        deallocate in interface Wrapper
        Parameters:
        servlet - The servlet to be returned
        Throws:
        ServletException - if a deallocation error occurs
      • findInitParameter

        public java.lang.String findInitParameter​(java.lang.String name)
        Specified by:
        findInitParameter in interface Wrapper
        Parameters:
        name - Name of the requested initialization parameter
        Returns:
        the value for the specified initialization parameter name, if any; otherwise return null.
      • findInitParameters

        public java.lang.String[] findInitParameters()
        Specified by:
        findInitParameters in interface Wrapper
        Returns:
        the names of all defined initialization parameters for this servlet.
      • findMappings

        public java.lang.String[] findMappings()
        Specified by:
        findMappings in interface Wrapper
        Returns:
        the mappings associated with this wrapper.
      • findSecurityReference

        public java.lang.String findSecurityReference​(java.lang.String name)
        Specified by:
        findSecurityReference in interface Wrapper
        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

        public java.lang.String[] findSecurityReferences()
        Specified by:
        findSecurityReferences in interface Wrapper
        Returns:
        the array of security role reference names associated with this servlet, if any; otherwise return a zero-length array.
      • load

        public void load()
                  throws ServletException
        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 interface Wrapper
        Throws:
        ServletException - if the Servlet init() method threw an exception or if some other loading problem occurs
      • loadServlet

        public Servlet loadServlet()
                            throws ServletException
        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

        public void removeInitParameter​(java.lang.String name)
        Description copied from interface: Wrapper
        Remove the specified initialization parameter from this Servlet.
        Specified by:
        removeInitParameter in interface Wrapper
        Parameters:
        name - Name of the initialization parameter to remove
      • removeMapping

        public void removeMapping​(java.lang.String mapping)
        Description copied from interface: Wrapper
        Remove a mapping associated with the wrapper.
        Specified by:
        removeMapping in interface Wrapper
        Parameters:
        mapping - The pattern to remove
      • removeSecurityReference

        public void removeSecurityReference​(java.lang.String name)
        Description copied from interface: Wrapper
        Remove any security role reference for the specified role name.
        Specified by:
        removeSecurityReference in interface Wrapper
        Parameters:
        name - Security role used within this servlet to be removed
      • unavailable

        public void unavailable​(UnavailableException unavailable)
        Description copied from interface: Wrapper
        Process an UnavailableException, marking this Servlet as unavailable for the specified amount of time.
        Specified by:
        unavailable in interface Wrapper
        Parameters:
        unavailable - The exception that occurred, or null to mark this Servlet as permanently unavailable
      • unload

        public void unload()
                    throws ServletException
        Description copied from interface: Wrapper
        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.
        Specified by:
        unload in interface Wrapper
        Throws:
        ServletException - if an unload error occurs
      • getInitParameter

        public java.lang.String getInitParameter​(java.lang.String name)
        Description copied from interface: jakarta.servlet.ServletConfig
        Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.
        Specified by:
        getInitParameter in interface ServletConfig
        Parameters:
        name - a String specifying the name of the initialization parameter
        Returns:
        a String containing the value of the initialization parameter
      • getInitParameterNames

        public java.util.Enumeration<java.lang.String> getInitParameterNames()
        Description copied from interface: jakarta.servlet.ServletConfig
        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.
        Specified by:
        getInitParameterNames in interface ServletConfig
        Returns:
        an Enumeration of String objects containing the names of the servlet's initialization parameters
      • getServletName

        public java.lang.String 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 interface ServletConfig
        Returns:
        the name of the servlet instance
      • getProcessingTime

        public long getProcessingTime()
      • getMaxTime

        public long getMaxTime()
      • getMinTime

        public long getMinTime()
      • getRequestCount

        @Deprecated
        public int 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
        public int 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 interface Wrapper
      • getLoadTime

        public long getLoadTime()
      • getClassLoadTime

        public int getClassLoadTime()
      • getMultipartConfigElement

        public MultipartConfigElement getMultipartConfigElement()
        Specified by:
        getMultipartConfigElement in interface Wrapper
        Returns:
        the multipart configuration for the associated Servlet. If no multipart configuration has been defined, then null will be returned.
      • setMultipartConfigElement

        public void setMultipartConfigElement​(MultipartConfigElement multipartConfigElement)
        Description copied from interface: Wrapper
        Set the multipart configuration for the associated Servlet. To clear the multipart configuration specify null as the new value.
        Specified by:
        setMultipartConfigElement in interface Wrapper
        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 to false.
        Specified by:
        isAsyncSupported in interface Wrapper
        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 interface Wrapper
        Parameters:
        asyncSupported - the new value
      • isEnabled

        public boolean isEnabled()
        Description copied from interface: Wrapper
        Is the associated Servlet enabled? Defaults to true.
        Specified by:
        isEnabled in interface Wrapper
        Returns:
        true if the Servlet is enabled
      • setEnabled

        public void setEnabled​(boolean enabled)
        Description copied from interface: Wrapper
        Sets the enabled attribute for the associated servlet.
        Specified by:
        setEnabled in interface Wrapper
        Parameters:
        enabled - the new value
      • getAllDeclaredMethods

        protected java.lang.reflect.Method[] getAllDeclaredMethods​(java.lang.Class<?> c)
      • getObjectNameKeyProperties

        protected java.lang.String getObjectNameKeyProperties()
        Description copied from class: LifecycleMBeanBase
        Allow subclasses to specify the key properties component of the ObjectName that will be used to register this component.
        Specified by:
        getObjectNameKeyProperties in class LifecycleMBeanBase
        Returns:
        The string representation of the key properties component of the desired ObjectName
      • removeNotificationListener

        public void removeNotificationListener​(javax.management.NotificationListener listener,
                                               javax.management.NotificationFilter filter,
                                               java.lang.Object object)
                                        throws javax.management.ListenerNotFoundException
        Specified by:
        removeNotificationListener in interface javax.management.NotificationEmitter
        Throws:
        javax.management.ListenerNotFoundException
      • getNotificationInfo

        public javax.management.MBeanNotificationInfo[] getNotificationInfo()
        Specified by:
        getNotificationInfo in interface javax.management.NotificationBroadcaster
      • addNotificationListener

        public void addNotificationListener​(javax.management.NotificationListener listener,
                                            javax.management.NotificationFilter filter,
                                            java.lang.Object object)
                                     throws java.lang.IllegalArgumentException
        Specified by:
        addNotificationListener in interface javax.management.NotificationBroadcaster
        Throws:
        java.lang.IllegalArgumentException
      • removeNotificationListener

        public void removeNotificationListener​(javax.management.NotificationListener listener)
                                        throws javax.management.ListenerNotFoundException
        Specified by:
        removeNotificationListener in interface javax.management.NotificationBroadcaster
        Throws:
        javax.management.ListenerNotFoundException