org.springframework.web.filter

Class DelegatingFilterProxy

    • Method Detail

      • setContextAttribute

        public void setContextAttribute(@Nullable
                                        java.lang.String contextAttribute)
        Set the name of the ServletContext attribute which should be used to retrieve the WebApplicationContext from which to load the delegate Filter bean.
      • getContextAttribute

        @Nullable
        public java.lang.String getContextAttribute()
        Return the name of the ServletContext attribute which should be used to retrieve the WebApplicationContext from which to load the delegate Filter bean.
      • setTargetBeanName

        public void setTargetBeanName(@Nullable
                                      java.lang.String targetBeanName)
        Set the name of the target bean in the Spring application context. The target bean must implement the standard Servlet Filter interface.

        By default, the filter-name as specified for the DelegatingFilterProxy in web.xml will be used.

      • getTargetBeanName

        @Nullable
        protected java.lang.String getTargetBeanName()
        Return the name of the target bean in the Spring application context.
      • setTargetFilterLifecycle

        public void setTargetFilterLifecycle(boolean targetFilterLifecycle)
        Set whether to invoke the Filter.init and Filter.destroy lifecycle methods on the target bean.

        Default is "false"; target beans usually rely on the Spring application context for managing their lifecycle. Setting this flag to "true" means that the servlet container will control the lifecycle of the target Filter, with this proxy delegating the corresponding calls.

      • isTargetFilterLifecycle

        protected boolean isTargetFilterLifecycle()
        Return whether to invoke the Filter.init and Filter.destroy lifecycle methods on the target bean.
      • doFilter

        public void doFilter(ServletRequest request,
                             ServletResponse response,
                             FilterChain filterChain)
                      throws ServletException,
                             java.io.IOException
        Description copied from interface: javax.servlet.Filter
        The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. The FilterChain passed in to this method allows the Filter to pass on the request and response to the next entity in the chain.

        A typical implementation of this method would follow the following pattern:

        1. Examine the request
        2. Optionally wrap the request object with a custom implementation to filter content or headers for input filtering
        3. Optionally wrap the response object with a custom implementation to filter content or headers for output filtering
          • Either invoke the next entity in the chain using the FilterChain object (chain.doFilter()),
          • or not pass on the request/response pair to the next entity in the filter chain to block the request processing
        4. Directly set headers on the response after invocation of the next entity in the filter chain.
        Parameters:
        request - the ServletRequest object contains the client's request
        response - the ServletResponse object contains the filter's response
        filterChain - the FilterChain for invoking the next filter or the resource
        Throws:
        ServletException - if an exception occurs that interferes with the filter's normal operation
        java.io.IOException - if an I/O related error has occurred during the processing
        See Also:
        UnavailableException
      • destroy

        public void destroy()
        Description copied from class: GenericFilterBean
        Subclasses may override this to perform custom filter shutdown.

        Note: This method will be called from standard filter destruction as well as filter bean destruction in a Spring application context.

        This default implementation is empty.

        Specified by:
        destroy in interface Filter
        Specified by:
        destroy in interface DisposableBean
        Overrides:
        destroy in class GenericFilterBean
      • invokeDelegate

        protected void invokeDelegate(Filter delegate,
                                      ServletRequest request,
                                      ServletResponse response,
                                      FilterChain filterChain)
                               throws ServletException,
                                      java.io.IOException
        Actually invoke the delegate Filter with the given request and response.
        Parameters:
        delegate - the delegate Filter
        request - the current HTTP request
        response - the current HTTP response
        filterChain - the current FilterChain
        Throws:
        ServletException - if thrown by the Filter
        java.io.IOException - if thrown by the Filter
      • destroyDelegate

        protected void destroyDelegate(Filter delegate)
        Destroy the Filter delegate. Default implementation simply calls Filter.destroy on it.
        Parameters:
        delegate - the Filter delegate (never null)
        See Also:
        isTargetFilterLifecycle(), Filter.destroy()