Class ContextInfoWebRequestResolver

java.lang.Object
com.broadleafcommerce.data.tracking.core.context.ContextInfoWebRequestResolver

public class ContextInfoWebRequestResolver extends Object
Provides functionality for resolving information from a web request into a ContextInfo.

By default this looks for the presence of an X-Context-Request header as JSON to be parsed by the ContextRequestConverter. This also resolves ContextInfo.locale with WebRequest.getLocale() and ContextInfo.ignoreTranslation with "X-Ignore-Translation" if provided.

Note that even if there is no X-Context-Request header specified in the request, a non-null ContextInfo will be created to hold other information about the request like the user principal and ip address.

If the X-Context-Request header is not provided, then the ContextInfo request information will be parsed from request parameter contextRequest instead.

See Also:
  • Field Details

    • CLEAR_OVERRIDE_PARAM

      public static final String CLEAR_OVERRIDE_PARAM
      See Also:
    • CONTEXT_REQUEST_PARAM

      public static final String CONTEXT_REQUEST_PARAM
      See Also:
    • PREVIEW_SANDBOX_HEADER

      public static final String PREVIEW_SANDBOX_HEADER
      See Also:
    • ACCOUNT_ID_HEADER

      public static final String ACCOUNT_ID_HEADER
      See Also:
    • defaultAllowAllAnonymous

      @Value("${broadleaf.resource.security.oauth2.defaultAllowAllAnonymous:false}") protected boolean defaultAllowAllAnonymous
    • defaultAuthor

      @Value("${broadleaf.tracking.defaultAuthor:DEFAULT_AUTHOR}") protected String defaultAuthor
  • Constructor Details

  • Method Details

    • resolveContextRequest

      public ContextRequest resolveContextRequest(@NonNull @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
      Resolves the ContextRequest of a given request based on either the request headers or request parameters.
      Parameters:
      webRequest - the web request being consumed
      Returns:
      a formed ContextRequest based on the request
      See Also:
    • resolveContextRequestFromHeader

      protected ContextRequest resolveContextRequestFromHeader(String header)
    • resolveContextRequestFromParameter

      protected ContextRequest resolveContextRequestFromParameter(String param)
    • resolveContextInfo

      public ContextInfo resolveContextInfo(@NonNull @NonNull org.springframework.web.context.request.NativeWebRequest req, @NonNull @NonNull OperationType operationType, @Nullable org.springframework.core.MethodParameter methodParameter)
      A convenience method that builds both a ContextInfo and its ContextRequest from the given web request.

      Delegates to resolveContextRequest(NativeWebRequest) to build the ContextRequest, then passes the result to resolveContextInfo(NativeWebRequest, ContextRequest, OperationType, MethodParameter).

      Parameters:
      req - the web request from which to source information to build the context info
      operationType - the operation type to set on the context-info
      methodParameter - (optional) the method that initiated the instantiation of this ContextInfo instance, if any. This is passed along to each ContextInfoCustomizer.
      Returns:
      a context info built from the information in the web request
      See Also:
    • resolveContextInfo

      public ContextInfo resolveContextInfo(@NonNull @NonNull org.springframework.web.context.request.NativeWebRequest req, @NonNull @NonNull ContextRequest contextRequest, @NonNull @NonNull OperationType operationType, @Nullable org.springframework.core.MethodParameter methodParameter)
      Builds a ContextInfo with the given contextRequest and operationType, with additional fields populated from data gathered in req.

      ContextInfoCustomizers are also invoked as part of this process.

      Parameters:
      req - the web request from which to source information to build the context info
      contextRequest - the context request to set on the context-info
      operationType - the operation type to set on the context-info
      methodParameter - (optional) the method that initiated the instantiation of this ContextInfo instance, if any. This is passed along to each ContextInfoCustomizer.
      Returns:
      a context info built from the information in the web request, context request, and operation type
      See Also:
    • applyPreviewBehaviorIfPossible

      protected void applyPreviewBehaviorIfPossible(org.springframework.web.context.request.NativeWebRequest req, ContextInfo response)
    • determineIpAddress

      protected String determineIpAddress(@NonNull @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
    • determineAuthor

      @Nullable protected String determineAuthor(@NonNull @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
    • determinePreviewToken

      protected PreviewToken determinePreviewToken(org.springframework.web.context.request.NativeWebRequest webRequest)
    • determinePreviewDate

      protected Instant determinePreviewDate(org.springframework.web.context.request.NativeWebRequest webRequest)
    • determinePreviewSandbox

      protected String determinePreviewSandbox(org.springframework.web.context.request.NativeWebRequest webRequest)
    • determineClearOverride

      protected boolean determineClearOverride(org.springframework.web.context.request.NativeWebRequest req, OperationType operationType)
    • determineIgnoreTranslation

      protected boolean determineIgnoreTranslation(org.springframework.web.context.request.NativeWebRequest req)
    • applyCustomizers

      protected void applyCustomizers(@NonNull @NonNull ContextInfo contextInfo, @Nullable org.springframework.core.MethodParameter methodParameter, @NonNull @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
    • determineAccountId

      protected void determineAccountId(ContextRequest contextRequest, org.springframework.web.context.request.NativeWebRequest req)
    • getReference

      @Nullable protected com.broadleafcommerce.common.extension.data.DataRouteReference getReference()
    • getConverters

      protected List<ContextRequestConverter> getConverters()
    • getPreviewTokenResolver

      protected PreviewTokenWebRequestResolver getPreviewTokenResolver()
    • getPreviewDateResolver

      protected PreviewDateWebRequestResolver getPreviewDateResolver()
    • getPreviewSandboxResolver

      protected PreviewSandboxWebRequestResolver getPreviewSandboxResolver()
    • getCustomizers

      @Nullable protected List<ContextInfoCustomizer> getCustomizers()