Top Description Fields Constructors Methods
org.springframework.web.context.support

public Class ContextExposingHttpServletRequest

extends HttpServletRequestWrapper
Class Inheritance
Imports
java.util.HashSet, .Set, jakarta.servlet.http.HttpServletRequest, .HttpServletRequestWrapper, org.springframework.lang.Nullable, org.springframework.util.Assert, org.springframework.web.context.WebApplicationContext

HttpServletRequest decorator that makes all Spring beans in a given WebApplicationContext accessible as request attributes, through lazy checking once an attribute gets accessed.
Author
Juergen Hoeller
Since
2.5

Field Summary

Modifier and TypeField and Description
private Set<String>
private final Set<String>
private final WebApplicationContext

Constructor Summary

AccessConstructor and Description
public
ContextExposingHttpServletRequest(HttpServletRequest
the original HttpServletRequest
originalRequest
,
WebApplicationContext
the WebApplicationContext that this request runs in
context
)

Create a new ContextExposingHttpServletRequest for the given request.

public
ContextExposingHttpServletRequest(HttpServletRequest
the original HttpServletRequest
originalRequest
,
WebApplicationContext
the WebApplicationContext that this request runs in
context
,
Set<String>
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)
exposedContextBeanNames
)

Create a new ContextExposingHttpServletRequest for the given request.

Method Summary

Modifier and TypeMethod and Description
public Object
getAttribute(String
a String specifying the name of the attribute
name
)

Overrides jakarta.servlet.ServletRequestWrapper.getAttribute.

Implements jakarta.servlet.ServletRequest.getAttribute.

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
public final WebApplicationContext
getWebApplicationContext()

Return the WebApplicationContext that this request runs in.

public void
setAttribute(String
a String specifying the name of the attribute
name
,
Object
the Object to be stored
value
)

Overrides jakarta.servlet.ServletRequestWrapper.setAttribute.

Implements jakarta.servlet.ServletRequest.setAttribute.

Stores an attribute in this request.
Inherited from jakarta.servlet.http.HttpServletRequestWrapper:
authenticatechangeSessionIdgetAuthTypegetContextPathgetCookiesgetDateHeadergetHeadergetHeaderNamesgetHeadersgetHttpServletMappinggetIntHeadergetMethodgetPartgetPartsgetPathInfogetPathTranslatedgetQueryStringgetRemoteUsergetRequestedSessionIdgetRequestURIgetRequestURLgetServletPathgetSessiongetSessiongetTrailerFieldsgetUserPrincipalisRequestedSessionIdFromCookieisRequestedSessionIdFromURLisRequestedSessionIdValidisTrailerFieldsReadyisUserInRoleloginlogoutnewPushBuilderupgrade

Field Detail

explicitAttributesback to summary
private Set<String> explicitAttributes
Annotations
@Nullable
exposedContextBeanNamesback to summary
private final Set<String> exposedContextBeanNames
Annotations
@Nullable
webApplicationContextback to summary
private final WebApplicationContext webApplicationContext

Constructor Detail

ContextExposingHttpServletRequestback to summary
public ContextExposingHttpServletRequest(HttpServletRequest originalRequest, WebApplicationContext context)

Create a new ContextExposingHttpServletRequest for the given request.

Parameters
originalRequest:HttpServletRequest

the original HttpServletRequest

context:WebApplicationContext

the WebApplicationContext that this request runs in

ContextExposingHttpServletRequestback to summary
public ContextExposingHttpServletRequest(HttpServletRequest originalRequest, WebApplicationContext context, Set<String> exposedContextBeanNames)

Create a new ContextExposingHttpServletRequest for the given request.

Parameters
originalRequest:HttpServletRequest

the original HttpServletRequest

context:WebApplicationContext

the WebApplicationContext that this request runs in

exposedContextBeanNames:Set<String>

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

getAttributeback to summary
public Object getAttribute(String name)

Overrides jakarta.servlet.ServletRequestWrapper.getAttribute.

Implements jakarta.servlet.ServletRequest.getAttribute.

Doc from jakarta.servlet.ServletRequest.getAttribute.

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Attributes can be set two ways. The servlet container may set attributes to make available custom information about a request. For example, for requests made using HTTPS, the attribute jakarta.servlet.request.X509Certificate can be used to retrieve information on the certificate of the client. Attributes can also be set programmatically using ServletRequest#setAttribute. This allows information to be embedded into a request before a RequestDispatcher call.

Attribute names should follow the same conventions as package names. Names beginning with jakarta.* are reserved for use by the Jakarta EE platform.

Parameters
name:String

a String specifying the name of the attribute

Returns:Object

an Object containing the value of the attribute, or null if the attribute does not exist

Annotations
@Override
@Nullable
getWebApplicationContextback to summary
public final WebApplicationContext getWebApplicationContext()

Return the WebApplicationContext that this request runs in.

setAttributeback to summary
public void setAttribute(String name, Object value)

Overrides jakarta.servlet.ServletRequestWrapper.setAttribute.

Implements jakarta.servlet.ServletRequest.setAttribute.

Doc from jakarta.servlet.ServletRequest.setAttribute.

Stores an attribute in this request. Attributes are reset between requests. This method is most often used in conjunction with RequestDispatcher.

Attribute names should follow the same conventions as package names. Names beginning with jakarta.* are reserved for use by the Jakarta EE platform.

If the object passed in is null, the effect is the same as calling removeAttribute.
It is warned that when the request is dispatched from the servlet resides in a different web application by RequestDispatcher, the object set by this method may not be correctly retrieved in the caller servlet.

Parameters
name:String

a String specifying the name of the attribute

value:Object

the Object to be stored

Annotations
@Override