Class 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:
    ContextInfoHandlerMethodArgumentResolver
    • Field Detail

      • defaultAllowAllAnonymous

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

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

      • 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 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:
        resolveContextInfo(NativeWebRequest, OperationType, MethodParameter)
      • 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)
      • getReference

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