Class BroadleafRequestContext

java.lang.Object
org.broadleafcommerce.common.web.BroadleafRequestContext

public class BroadleafRequestContext extends Object
Convenient holder class for various objects to be automatically available on thread local without invoking the various services yourself
  • 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

      protected SandBox sandBox
    • locale

      protected Locale locale
    • timeZone

      protected TimeZone timeZone
    • broadleafCurrency

      protected BroadleafCurrency broadleafCurrency
    • requestedCurrency

      protected BroadleafCurrency requestedCurrency
    • site

      protected Site site
    • theme

      protected Theme theme
    • javaLocale

      protected Locale javaLocale
    • javaCurrency

      protected Currency javaCurrency
    • currentCatalog

      protected Catalog currentCatalog
    • explicitCatalogs

      protected List<Long> explicitCatalogs
    • currentProfile

      protected Site currentProfile
    • ignoreSite

      protected Boolean ignoreSite
    • additionalProperties

      protected Map<String,Object> additionalProperties
    • messageSource

      protected org.springframework.context.MessageSource messageSource
    • requestDTO

      protected RequestDTO requestDTO
    • isAdmin

      protected Boolean isAdmin
    • adminUserId

      protected Long adminUserId
    • deployState

      protected DeployState deployState
    • deployBehavior

      protected DeployBehavior deployBehavior
    • internalIgnoreFilters

      protected Boolean internalIgnoreFilters
    • validateProductionChangesState

      protected ValidateProductionChangesState validateProductionChangesState
    • enforceEnterpriseCollectionBehaviorState

      protected EnforceEnterpriseCollectionBehaviorState enforceEnterpriseCollectionBehaviorState
    • internalValidateFind

      protected Boolean internalValidateFind
  • Constructor Details

    • BroadleafRequestContext

      public BroadleafRequestContext()
  • Method Details

    • getBroadleafRequestContext

      public static BroadleafRequestContext getBroadleafRequestContext()
      Returns the current, thread-bound BroadleafRequestContext. This creates and binds one if it does not exist.

      This is the same as calling getBroadleafRequestContext(boolean) with the value true.

      Returns:
    • setBroadleafRequestContext

      public static void setBroadleafRequestContext(BroadleafRequestContext broadleafRequestContext)
      Initializes or sets the BroadleafRequestContext on the current thread. If the provided parameter is null, this removes the thread-bound context.
      Parameters:
      broadleafRequestContext -
    • getBroadleafRequestContext

      public static BroadleafRequestContext getBroadleafRequestContext(boolean createIfAbsent)
      Returns the current, thread-bound BroadleafRequestContext, 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 a BroadleafRequestContext already bound to the current thread.
      Returns:
    • hasLocale

      public static boolean hasLocale()
    • hasCurrency

      public static boolean hasCurrency()
    • getCurrency

      public static BroadleafCurrency getCurrency()
    • convertLocaleToJavaLocale

      public static Locale convertLocaleToJavaLocale(Locale broadleafLocale)
    • getRequestParameterMap

      public static Map<String,String[]> 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 invokes setWebRequest(WebRequest) by wrapping request in a ServletWebRequest.
      Parameters:
      request -
    • getRequestAttribute

      public Object getRequestAttribute(String name)
      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 invoking setRequest(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 of ServletWebRequest then setRequest(HttpServletRequest) will be invoked as well with the native underlying HttpServletRequest passed as a parameter.

      Also, if webRequest is an instance of ServletWebRequest then an attempt is made to set the response (note that this could be null if the ServletWebRequest was not instantiated with both the HttpServletRequest and HttpServletResponse
      Parameters:
      webRequest -
    • getSite

      @Deprecated public Site getSite()
      Deprecated.
      this has been changed to getNonPersistentSite() to explicitly indicate that the site being returned is not attached to a Hibernate session
      Returns a Site instance that is not attached to any Hibernate session
      Returns:
    • setSite

      @Deprecated public void setSite(Site site)
      Deprecated.
      this has been changed to #setNonPersistentSite() to explicitly indicate that the site being set is not attached to an active Hibernate session
    • getNonPersistentSite

      public Site 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

      public void setNonPersistentSite(Site site)
    • getSandBox

      public SandBox getSandBox()
    • setSandBox

      public void setSandBox(SandBox sandBox)
    • getSandBoxId

      public Long getSandBoxId()
    • isProductionSandBox

      public boolean isProductionSandBox()
    • getLocale

      public Locale getLocale()
    • setLocale

      public void setLocale(Locale locale)
    • getJavaLocale

      public Locale getJavaLocale()
      Returns the java.util.Locale constructed from the org.broadleafcommerce.common.locale.domain.Locale.
      Returns:
    • getJavaCurrency

      public Currency 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

      public String getRequestURIWithoutContext()
    • convertLocaleToJavaLocale

      protected Locale convertLocaleToJavaLocale()
    • isSecure

      public boolean isSecure()
    • getTheme

      public Theme getTheme()
    • setTheme

      public void setTheme(Theme theme)
    • getBroadleafCurrency

      public BroadleafCurrency getBroadleafCurrency()
    • setBroadleafCurrency

      public void setBroadleafCurrency(BroadleafCurrency broadleafCurrency)
    • getRequestedBroadleafCurrency

      public BroadleafCurrency getRequestedBroadleafCurrency()
    • setRequestedBroadleafCurrency

      public void setRequestedBroadleafCurrency(BroadleafCurrency requestedCurrency)
    • getCurrentCatalog

      public Catalog getCurrentCatalog()
    • setCurrentCatalog

      public void setCurrentCatalog(Catalog currentCatalog)
    • getExplicitCatalogs

      public List<Long> getExplicitCatalogs()
    • setExplicitCatalogs

      public void setExplicitCatalogs(List<Long> explicitCatalogs)
    • getCurrentProfile

      public Site getCurrentProfile()
    • setCurrentProfile

      public void setCurrentProfile(Site currentProfile)
    • getIgnoreSite

      public Boolean getIgnoreSite()
    • setIgnoreSite

      public void setIgnoreSite(Boolean ignoreSite)
    • getAdditionalProperties

      public Map<String,Object> getAdditionalProperties()
    • setAdditionalProperties

      public void setAdditionalProperties(Map<String,Object> additionalProperties)
    • getMessageSource

      public org.springframework.context.MessageSource getMessageSource()
    • setMessageSource

      public void setMessageSource(org.springframework.context.MessageSource messageSource)
    • getTimeZone

      public TimeZone getTimeZone()
    • setTimeZone

      public void setTimeZone(TimeZone timeZone)
    • getRequestDTO

      public RequestDTO getRequestDTO()
    • setRequestDTO

      public void setRequestDTO(RequestDTO requestDTO)
    • getAdmin

      public Boolean getAdmin()
    • setAdmin

      public void setAdmin(Boolean admin)
    • getAdminUserId

      public Long getAdminUserId()
    • setAdminUserId

      public void setAdminUserId(Long adminUserId)
    • getInternalIgnoreFilters

      public Boolean getInternalIgnoreFilters()
      Intended for internal use only
    • setInternalIgnoreFilters

      public 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).
    • getInternalValidateFind

      public Boolean getInternalValidateFind()
      See Also:
    • setInternalValidateFind

      public 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()). 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

      public DeployState getDeployState()
    • setDeployState

      public void setDeployState(DeployState deployState)
    • getDeployBehavior

      public DeployBehavior getDeployBehavior()
    • setDeployBehavior

      public void setDeployBehavior(DeployBehavior deployBehavior)
    • getValidateProductionChangesState

      public ValidateProductionChangesState getValidateProductionChangesState()
    • setValidateProductionChangesState

      public void setValidateProductionChangesState(ValidateProductionChangesState validateProductionChangesState)
    • getEnforceEnterpriseCollectionBehaviorState

      public EnforceEnterpriseCollectionBehaviorState 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

      public BroadleafRequestContext 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

      public String 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: