public abstract class RequestContextHolder
extends java.lang.Object
RequestAttributes
object. The request will be inherited
by any child threads spawned by the current thread if the
inheritable
flag is set to true
.
Use RequestContextListener
or
RequestContextFilter
to expose
the current web request. Note that
DispatcherServlet
and
DispatcherPortlet
already
expose the current request by default.
RequestContextListener
,
RequestContextFilter
,
DispatcherServlet
,
DispatcherPortlet
Modifier and Type | Class and Description |
---|---|
private static class |
RequestContextHolder.FacesRequestAttributesFactory
Inner class to avoid hard-coded JSF dependency.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.ThreadLocal<RequestAttributes> |
inheritableRequestAttributesHolder |
private static boolean |
jsfPresent |
private static java.lang.ThreadLocal<RequestAttributes> |
requestAttributesHolder |
Constructor and Description |
---|
RequestContextHolder() |
Modifier and Type | Method and 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.
|
private static final boolean jsfPresent
private static final java.lang.ThreadLocal<RequestAttributes> requestAttributesHolder
private static final java.lang.ThreadLocal<RequestAttributes> inheritableRequestAttributesHolder
public static void resetRequestAttributes()
public static void setRequestAttributes(RequestAttributes attributes)
attributes
- the RequestAttributes to exposesetRequestAttributes(RequestAttributes, boolean)
public static void setRequestAttributes(RequestAttributes attributes, boolean inheritable)
attributes
- the RequestAttributes to expose,
or null
to reset the thread-bound contextinheritable
- whether to expose the RequestAttributes as inheritable
for child threads (using an InheritableThreadLocal
)public static RequestAttributes getRequestAttributes()
null
if none boundpublic static RequestAttributes currentRequestAttributes() throws java.lang.IllegalStateException
Exposes the previously bound RequestAttributes instance, if any. Falls back to the current JSF FacesContext, if any.
java.lang.IllegalStateException
- if no RequestAttributes object
is bound to the current threadsetRequestAttributes(org.springframework.web.context.request.RequestAttributes)
,
ServletRequestAttributes
,
FacesRequestAttributes
,
javax.faces.context.FacesContext#getCurrentInstance()