Class RequestContextHolder
- java.lang.Object
- org.springframework.web.context.request.RequestContextHolder
public abstract class RequestContextHolder extends Object
Holder class to expose the web request in the form of a thread-boundRequestAttributes
object. The request will be inherited by any child threads spawned by the current thread if theinheritable
flag is set totrue
.Use
RequestContextListener
orRequestContextFilter
to expose the current web request. Note thatDispatcherServlet
already exposes the current request by default.- Since:
- 2.0
- Author:
- Juergen Hoeller, Rod Johnson
- See Also:
RequestContextListener
,RequestContextFilter
,DispatcherServlet
Constructor Summary
Constructors Constructor Description RequestContextHolder()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RequestAttributes
currentRequestAttributes()
Return the RequestAttributes currently bound to the thread.static RequestAttributes
getRequestAttributes()
Return the RequestAttributes currently bound to the thread.static void
resetRequestAttributes()
Reset the RequestAttributes for the current thread.static void
setRequestAttributes(RequestAttributes attributes)
Bind the given RequestAttributes to the current thread, not exposing it as inheritable for child threads.static void
setRequestAttributes(RequestAttributes attributes, boolean inheritable)
Bind the given RequestAttributes to the current thread.
Constructor Detail
RequestContextHolder
public RequestContextHolder()
Method Detail
resetRequestAttributes
public static void resetRequestAttributes()
Reset the RequestAttributes for the current thread.
setRequestAttributes
public static void setRequestAttributes(@Nullable RequestAttributes attributes)
Bind the given RequestAttributes to the current thread, not exposing it as inheritable for child threads.- Parameters:
attributes
- the RequestAttributes to expose- See Also:
setRequestAttributes(RequestAttributes, boolean)
setRequestAttributes
public static void setRequestAttributes(@Nullable RequestAttributes attributes, boolean inheritable)
Bind the given RequestAttributes to the current thread.- Parameters:
attributes
- the RequestAttributes to expose, ornull
to reset the thread-bound contextinheritable
- whether to expose the RequestAttributes as inheritable for child threads (using anInheritableThreadLocal
)
getRequestAttributes
@Nullable public static RequestAttributes getRequestAttributes()
Return the RequestAttributes currently bound to the thread.- Returns:
- the RequestAttributes currently bound to the thread, or
null
if none bound
currentRequestAttributes
public static RequestAttributes currentRequestAttributes() throws IllegalStateException
Return the RequestAttributes currently bound to the thread.Exposes the previously bound RequestAttributes instance, if any. Falls back to the current JSF FacesContext, if any.
- Returns:
- the RequestAttributes currently bound to the thread
- Throws:
IllegalStateException
- if no RequestAttributes object is bound to the current thread- See Also:
setRequestAttributes(org.springframework.web.context.request.RequestAttributes)
,ServletRequestAttributes
,FacesRequestAttributes
,FacesContext.getCurrentInstance()