Package org.broadleafcommerce.common.web
Class BroadleafRequestContext
java.lang.Object
org.broadleafcommerce.common.web.BroadleafRequestContext
Convenient holder class for various objects to be automatically available on thread local without invoking the various
services yourself
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Long
protected BroadleafCurrency
protected Catalog
protected Site
protected DeployBehavior
protected DeployState
protected EnforceEnterpriseCollectionBehaviorState
protected Boolean
protected Boolean
protected Boolean
protected Boolean
protected Currency
protected Locale
protected Locale
protected static final org.apache.commons.logging.Log
protected org.springframework.context.MessageSource
protected jakarta.servlet.http.HttpServletRequest
protected RequestDTO
protected BroadleafCurrency
protected jakarta.servlet.http.HttpServletResponse
protected SandBox
protected Site
protected Theme
protected TimeZone
protected ValidateProductionChangesState
protected org.springframework.web.context.request.WebRequest
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Locale
static Locale
convertLocaleToJavaLocale
(Locale broadleafLocale) In some cases, it is useful to utilize a clone of the context that does not include the actual container request and response information.static BroadleafRequestContext
createLightWeightCloneFromJson
(String Json, jakarta.persistence.EntityManager em) Resurrect the BroadleafRequestContext state based on a JSON representation.In some cases, it is useful to create a JSON representation of the context that does not include the actual container request and response information.getAdmin()
static BroadleafRequestContext
Returns the current, thread-boundBroadleafRequestContext
.static BroadleafRequestContext
getBroadleafRequestContext
(boolean createIfAbsent) Returns the current, thread-boundBroadleafRequestContext
, or null if one does not exist.static BroadleafCurrency
Defines the state in which sandboxable collections in the Enterprise module should adhere to Broadleaf defined behavior.Intended for internal use onlyReturns the java.util.Currency constructed from the org.broadleafcommerce.common.currency.domain.BroadleafCurrency.Returns the java.util.Locale constructed from the org.broadleafcommerce.common.locale.domain.Locale.org.springframework.context.MessageSource
jakarta.servlet.http.HttpServletRequest
Gets the current request on the contextgetRequestAttribute
(String name) Provide easy access to Request Attributes without introducing a tight dependency on the HttpRequest.jakarta.servlet.http.HttpServletResponse
Returns the response for the contextgetSite()
Deprecated.getTheme()
org.springframework.web.context.request.WebRequest
Returns the generic request for use outside of servlets (like in Portlets).static boolean
static boolean
static boolean
Checks to see if there is aBroadleafRequestContext
already bound to the current thread.boolean
boolean
isSecure()
void
setAdditionalProperties
(Map<String, Object> additionalProperties) void
void
setAdminUserId
(Long adminUserId) void
setBroadleafCurrency
(BroadleafCurrency broadleafCurrency) static void
setBroadleafRequestContext
(BroadleafRequestContext broadleafRequestContext) Initializes or sets theBroadleafRequestContext
on the current thread.void
setCurrentCatalog
(Catalog currentCatalog) void
setCurrentProfile
(Site currentProfile) void
setDeployBehavior
(DeployBehavior deployBehavior) void
setDeployState
(DeployState deployState) void
setEnforceEnterpriseCollectionBehaviorState
(EnforceEnterpriseCollectionBehaviorState enforceEnterpriseCollectionBehaviorState) Returns the state in which sandboxable collections in the Enterprise module should adhere to Broadleaf defined behavior.void
setExplicitCatalogs
(List<Long> explicitCatalogs) void
setIgnoreSite
(Boolean ignoreSite) void
setInternalIgnoreFilters
(Boolean internalIgnoreFilters) Used to ignore all of the underlying automatic Hibernate filters applied by Broadleaf (e.g. for sandboxing, multi-tenant and archiving filters).void
setInternalValidateFind
(Boolean internalValidateFind) Only relevant in multi-tenant scenarios with site-level overrides in a catalog or profile, and only when querying by primary key (e.g. using em.find()).void
void
setMessageSource
(org.springframework.context.MessageSource messageSource) void
setNonPersistentSite
(Site site) void
setRequest
(jakarta.servlet.http.HttpServletRequest request) Sets the current request on the context.void
setRequestDTO
(RequestDTO requestDTO) void
setRequestedBroadleafCurrency
(BroadleafCurrency requestedCurrency) void
setResponse
(jakarta.servlet.http.HttpServletResponse response) Sets the response on the contextvoid
setSandBox
(SandBox sandBox) void
Deprecated.this has been changed to#setNonPersistentSite()
to explicitly indicate that the site being set is not attached to an active Hibernate sessionvoid
void
setTimeZone
(TimeZone timeZone) void
setValidateProductionChangesState
(ValidateProductionChangesState validateProductionChangesState) void
setWebRequest
(org.springframework.web.context.request.WebRequest webRequest) Sets the generic request on the context.
-
Field Details
-
LOG
protected static final org.apache.commons.logging.Log LOG -
request
protected jakarta.servlet.http.HttpServletRequest request -
response
protected jakarta.servlet.http.HttpServletResponse response -
webRequest
protected org.springframework.web.context.request.WebRequest webRequest -
sandBox
-
locale
-
timeZone
-
broadleafCurrency
-
requestedCurrency
-
site
-
theme
-
javaLocale
-
javaCurrency
-
currentCatalog
-
explicitCatalogs
-
currentProfile
-
ignoreSite
-
additionalProperties
-
messageSource
protected org.springframework.context.MessageSource messageSource -
requestDTO
-
isAdmin
-
adminUserId
-
deployState
-
deployBehavior
-
internalIgnoreFilters
-
validateProductionChangesState
-
enforceEnterpriseCollectionBehaviorState
-
internalValidateFind
-
-
Constructor Details
-
BroadleafRequestContext
public BroadleafRequestContext()
-
-
Method Details
-
getBroadleafRequestContext
Returns the current, thread-boundBroadleafRequestContext
. This creates and binds one if it does not exist.This is the same as calling
getBroadleafRequestContext(boolean)
with the value true.- Returns:
-
setBroadleafRequestContext
Initializes or sets theBroadleafRequestContext
on the current thread. If the provided parameter is null, this removes the thread-bound context.- Parameters:
broadleafRequestContext
-
-
getBroadleafRequestContext
Returns the current, thread-boundBroadleafRequestContext
, or null if one does not exist. However, this creates and binds one and returns the newly created context if it does not exist and the createIfAbsent parameter is true.- Parameters:
createIfAbsent
-- Returns:
-
isContextInitialized
public static boolean isContextInitialized()Checks to see if there is aBroadleafRequestContext
already bound to the current thread.- Returns:
-
hasLocale
public static boolean hasLocale() -
hasCurrency
public static boolean hasCurrency() -
getCurrency
-
convertLocaleToJavaLocale
-
getRequestParameterMap
-
createLightWeightCloneFromJson
public static BroadleafRequestContext createLightWeightCloneFromJson(String Json, jakarta.persistence.EntityManager em) Resurrect the BroadleafRequestContext state based on a JSON representation.- Parameters:
Json
-em
-- Returns:
-
getRequest
public jakarta.servlet.http.HttpServletRequest getRequest()Gets the current request on the context- Returns:
-
setRequest
public void setRequest(jakarta.servlet.http.HttpServletRequest request) Sets the current request on the context. Note that this also invokessetWebRequest(WebRequest)
by wrapping request in aServletWebRequest
.- Parameters:
request
-
-
getRequestAttribute
Provide easy access to Request Attributes without introducing a tight dependency on the HttpRequest.- Returns:
-
getResponse
public jakarta.servlet.http.HttpServletResponse getResponse()Returns the response for the context- Returns:
-
setResponse
public void setResponse(jakarta.servlet.http.HttpServletResponse response) Sets the response on the context- Parameters:
response
-
-
getWebRequest
public org.springframework.web.context.request.WebRequest getWebRequest()Returns the generic request for use outside of servlets (like in Portlets). This will be automatically set by invokingsetRequest(HttpServletRequest)
- Returns:
- the generic request
-
setWebRequest
public void setWebRequest(org.springframework.web.context.request.WebRequest webRequest) Sets the generic request on the context. This is available to be used in non-Servlet environments (like Portlets). Note that if webRequest is an instance ofServletWebRequest
thensetRequest(HttpServletRequest)
will be invoked as well with the native underlyingHttpServletRequest
passed as a parameter.
Also, if webRequest is an instance ofServletWebRequest
then an attempt is made to set the response (note that this could be null if the ServletWebRequest was not instantiated with both theHttpServletRequest
andHttpServletResponse
- Parameters:
webRequest
-
-
getSite
Deprecated.this has been changed togetNonPersistentSite()
to explicitly indicate that the site being returned is not attached to a Hibernate sessionReturns a Site instance that is not attached to any Hibernate session- Returns:
-
setSite
Deprecated.this has been changed to#setNonPersistentSite()
to explicitly indicate that the site being set is not attached to an active Hibernate session -
getNonPersistentSite
- Returns:
- the site that is currently associated to this request thread. The site that is returned is not attached to a
Hibernate session and thus cannot lazy-load collection properties. For additional collections that are added to
extensions of
Site
, they should be manually cloned by overriding the clone() method.
-
setNonPersistentSite
-
getSandBox
-
setSandBox
-
getSandBoxId
-
isProductionSandBox
public boolean isProductionSandBox() -
getLocale
-
setLocale
-
getJavaLocale
Returns the java.util.Locale constructed from the org.broadleafcommerce.common.locale.domain.Locale.- Returns:
-
getJavaCurrency
Returns the java.util.Currency constructed from the org.broadleafcommerce.common.currency.domain.BroadleafCurrency. If there is no BroadleafCurrency specified this will return the currency based on the JVM locale- Returns:
-
getRequestURIWithoutContext
-
convertLocaleToJavaLocale
-
isSecure
public boolean isSecure() -
getTheme
-
setTheme
-
getBroadleafCurrency
-
setBroadleafCurrency
-
getRequestedBroadleafCurrency
-
setRequestedBroadleafCurrency
-
getCurrentCatalog
-
setCurrentCatalog
-
getExplicitCatalogs
-
setExplicitCatalogs
-
getCurrentProfile
-
setCurrentProfile
-
getIgnoreSite
-
setIgnoreSite
-
getAdditionalProperties
-
setAdditionalProperties
-
getMessageSource
public org.springframework.context.MessageSource getMessageSource() -
setMessageSource
public void setMessageSource(org.springframework.context.MessageSource messageSource) -
getTimeZone
-
setTimeZone
-
getRequestDTO
-
setRequestDTO
-
getAdmin
-
setAdmin
-
getAdminUserId
-
setAdminUserId
-
getInternalIgnoreFilters
Intended for internal use only -
setInternalIgnoreFilters
Used to ignore all of the underlying automatic Hibernate filters applied by Broadleaf (e.g. for sandboxing, multi-tenant and archiving filters). -
getInternalValidateFind
- See Also:
-
setInternalValidateFind
Only relevant in multi-tenant scenarios with site-level overrides in a catalog or profile, and only when querying by primary key (e.g. using em.find()). Normally querying directly by ID does not engage the clone cache or any filter restrictions across sibling sites. This is done for performance reasons. Activating this behavior ensures that em.find() _does_ engage the clone cache and validation across sibling sites. Generally this is only used within API use cases where you often query for objects on their ID. In all other types of queries (e.g. using query.getResultList()) the automatic filtration and overriding is already applied. -
getDeployState
-
setDeployState
-
getDeployBehavior
-
setDeployBehavior
-
getValidateProductionChangesState
-
setValidateProductionChangesState
public void setValidateProductionChangesState(ValidateProductionChangesState validateProductionChangesState) -
getEnforceEnterpriseCollectionBehaviorState
Defines the state in which sandboxable collections in the Enterprise module should adhere to Broadleaf defined behavior. When FALSE,PersistentCollection
extensions in the Enterprise module will delegate to the standard Hibernate behavior. This is useful when the desire is to build and persist entity object structures (that the Enterprise module would otherwise interpret as sandboxable) without interference from the Enterprise module on the collection persistence behavior. When the Enterprise module is loaded, the behavior is enforced by default.- Returns:
- the definition of how the enterprise module should handle persistent collection behavior
-
setEnforceEnterpriseCollectionBehaviorState
public void setEnforceEnterpriseCollectionBehaviorState(EnforceEnterpriseCollectionBehaviorState enforceEnterpriseCollectionBehaviorState) Returns the state in which sandboxable collections in the Enterprise module should adhere to Broadleaf defined behavior. When FALSE,PersistentCollection
extensions in the Enterprise module will delegate to the standard Hibernate behavior. This is useful when the desire is to build and persist entity object structures (that the Enterprise module would otherwise interpret as sandboxable) without interference from the Enterprise module on the collection persistence behavior. When the Enterprise module is loaded, the behavior is enforced by default.- Parameters:
enforceEnterpriseCollectionBehaviorState
-
-
createLightWeightClone
In some cases, it is useful to utilize a clone of the context that does not include the actual container request and response information. Such a case would be when executing an asynchronous operation on a new thread from an existing request thread. That new thread may still require context information, in which case this lightweight context is useful.- Returns:
- The instance without the container request and response
-
createLightWeightCloneJson
In some cases, it is useful to create a JSON representation of the context that does not include the actual container request and response information. This can be used subsequently to resurrect the BroadleafRequestContext state, presumably on a new thread.- Returns:
-
getNonPersistentSite()
to explicitly indicate that the site being returned is not attached to a Hibernate session