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 Longprotected BroadleafCurrencyprotected Catalogprotected Siteprotected DeployBehaviorprotected DeployStateprotected EnforceEnterpriseCollectionBehaviorStateprotected Booleanprotected Booleanprotected Booleanprotected Booleanprotected Currencyprotected Localeprotected Localeprotected static final org.apache.commons.logging.Logprotected org.springframework.context.MessageSourceprotected jakarta.servlet.http.HttpServletRequestprotected RequestDTOprotected BroadleafCurrencyprotected jakarta.servlet.http.HttpServletResponseprotected SandBoxprotected Siteprotected Themeprotected TimeZoneprotected ValidateProductionChangesStateprotected org.springframework.web.context.request.WebRequest -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Localestatic LocaleconvertLocaleToJavaLocale(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 BroadleafRequestContextcreateLightWeightCloneFromJson(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 BroadleafRequestContextReturns the current, thread-boundBroadleafRequestContext.static BroadleafRequestContextgetBroadleafRequestContext(boolean createIfAbsent) Returns the current, thread-boundBroadleafRequestContext, or null if one does not exist.static BroadleafCurrencyDefines 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.MessageSourcejakarta.servlet.http.HttpServletRequestGets 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.HttpServletResponseReturns the response for the contextgetSite()Deprecated.getTheme()org.springframework.web.context.request.WebRequestReturns the generic request for use outside of servlets (like in Portlets).static booleanstatic booleanstatic booleanChecks to see if there is aBroadleafRequestContextalready bound to the current thread.booleanbooleanisSecure()voidsetAdditionalProperties(Map<String, Object> additionalProperties) voidvoidsetAdminUserId(Long adminUserId) voidsetBroadleafCurrency(BroadleafCurrency broadleafCurrency) static voidsetBroadleafRequestContext(BroadleafRequestContext broadleafRequestContext) Initializes or sets theBroadleafRequestContexton the current thread.voidsetCurrentCatalog(Catalog currentCatalog) voidsetCurrentProfile(Site currentProfile) voidsetDeployBehavior(DeployBehavior deployBehavior) voidsetDeployState(DeployState deployState) voidsetEnforceEnterpriseCollectionBehaviorState(EnforceEnterpriseCollectionBehaviorState enforceEnterpriseCollectionBehaviorState) Returns the state in which sandboxable collections in the Enterprise module should adhere to Broadleaf defined behavior.voidsetExplicitCatalogs(List<Long> explicitCatalogs) voidsetIgnoreSite(Boolean ignoreSite) voidsetInternalIgnoreFilters(Boolean internalIgnoreFilters) Used to ignore all of the underlying automatic Hibernate filters applied by Broadleaf (e.g. for sandboxing, multi-tenant and archiving filters).voidsetInternalValidateFind(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()).voidvoidsetMessageSource(org.springframework.context.MessageSource messageSource) voidsetNonPersistentSite(Site site) voidsetRequest(jakarta.servlet.http.HttpServletRequest request) Sets the current request on the context.voidsetRequestDTO(RequestDTO requestDTO) voidsetRequestedBroadleafCurrency(BroadleafCurrency requestedCurrency) voidsetResponse(jakarta.servlet.http.HttpServletResponse response) Sets the response on the contextvoidsetSandBox(SandBox sandBox) voidDeprecated.this has been changed to#setNonPersistentSite()to explicitly indicate that the site being set is not attached to an active Hibernate sessionvoidvoidsetTimeZone(TimeZone timeZone) voidsetValidateProductionChangesState(ValidateProductionChangesState validateProductionChangesState) voidsetWebRequest(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 theBroadleafRequestContexton 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 aBroadleafRequestContextalready 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 ofServletWebRequestthensetRequest(HttpServletRequest)will be invoked as well with the native underlyingHttpServletRequestpassed as a parameter.
Also, if webRequest is an instance ofServletWebRequestthen an attempt is made to set the response (note that this could be null if the ServletWebRequest was not instantiated with both theHttpServletRequestandHttpServletResponse- 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,PersistentCollectionextensions 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,PersistentCollectionextensions 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