org.springframework.web.context.support

Class ContextExposingHttpServletRequest

  • All Implemented Interfaces:
    HttpServletRequest, ServletRequest


    public class ContextExposingHttpServletRequest
    extends HttpServletRequestWrapper
    HttpServletRequest decorator that makes all Spring beans in a given WebApplicationContext accessible as request attributes, through lazy checking once an attribute gets accessed.
    Since:
    2.5
    Author:
    Juergen Hoeller
    • Constructor Detail

      • ContextExposingHttpServletRequest

        public ContextExposingHttpServletRequest(HttpServletRequest originalRequest,
                                                 WebApplicationContext context)
        Create a new ContextExposingHttpServletRequest for the given request.
        Parameters:
        originalRequest - the original HttpServletRequest
        context - the WebApplicationContext that this request runs in
      • ContextExposingHttpServletRequest

        public ContextExposingHttpServletRequest(HttpServletRequest originalRequest,
                                                 WebApplicationContext context,
                                                 @Nullable
                                                 java.util.Set<java.lang.String> exposedContextBeanNames)
        Create a new ContextExposingHttpServletRequest for the given request.
        Parameters:
        originalRequest - the original HttpServletRequest
        context - the WebApplicationContext that this request runs in
        exposedContextBeanNames - the names of beans in the context which are supposed to be exposed (if this is non-null, only the beans in this Set are eligible for exposure as attributes)
    • Method Detail

      • getWebApplicationContext

        public final WebApplicationContext getWebApplicationContext()
        Return the WebApplicationContext that this request runs in.
      • getAttribute

        @Nullable
        public java.lang.Object getAttribute(java.lang.String name)
        Description copied from class: javax.servlet.ServletRequestWrapper
        The default behavior of this method is to call getAttribute(String name) on the wrapped request object.
        Specified by:
        getAttribute in interface ServletRequest
        Overrides:
        getAttribute in class ServletRequestWrapper
        Parameters:
        name - a String specifying the name of the attribute
        Returns:
        an Object containing the value of the attribute, or null if the attribute does not exist
      • setAttribute

        public void setAttribute(java.lang.String name,
                                 java.lang.Object value)
        Description copied from class: javax.servlet.ServletRequestWrapper
        The default behavior of this method is to return setAttribute(String name, Object o) on the wrapped request object.
        Specified by:
        setAttribute in interface ServletRequest
        Overrides:
        setAttribute in class ServletRequestWrapper
        Parameters:
        name - a String specifying the name of the attribute
        value - the Object to be stored