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 aContextInfo.By default this looks for the presence of an X-Context-Request header as JSON to be parsed by the
ContextRequestConverter. This also resolvesContextInfo.localewithWebRequest.getLocale()andContextInfo.ignoreTranslationwith "X-Ignore-Translation" if provided.Note that even if there is no
X-Context-Requestheader specified in the request, a non-nullContextInfowill 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
ContextInforequest information will be parsed from request parametercontextRequestinstead.- See Also:
ContextInfoHandlerMethodArgumentResolver
-
-
Field Summary
Fields Modifier and Type Field Description static StringACCOUNT_ID_HEADERstatic StringCLEAR_OVERRIDE_PARAMstatic StringCONTEXT_REQUEST_PARAMprotected booleandefaultAllowAllAnonymousprotected StringdefaultAuthorstatic StringPREVIEW_SANDBOX_HEADER
-
Constructor Summary
Constructors Constructor Description ContextInfoWebRequestResolver(com.broadleafcommerce.common.extension.data.DataRouteReference reference, List<ContextRequestConverter> converters, PreviewTokenWebRequestResolver previewTokenResolver, PreviewDateWebRequestResolver previewDateResolver, PreviewSandboxWebRequestResolver previewSandboxResolver, List<ContextInfoCustomizer> customizers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidapplyCustomizers(@NonNull ContextInfo contextInfo, org.springframework.core.MethodParameter methodParameter, @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)protected voidapplyPreviewBehaviorIfPossible(org.springframework.web.context.request.NativeWebRequest req, ContextInfo response)protected voiddetermineAccountId(ContextRequest contextRequest, org.springframework.web.context.request.NativeWebRequest req)protected StringdetermineAuthor(@NonNull org.springframework.web.context.request.NativeWebRequest webRequest)protected booleandetermineClearOverride(org.springframework.web.context.request.NativeWebRequest req, OperationType operationType)protected booleandetermineIgnoreTranslation(org.springframework.web.context.request.NativeWebRequest req)protected StringdetermineIpAddress(@NonNull org.springframework.web.context.request.NativeWebRequest webRequest)protected InstantdeterminePreviewDate(org.springframework.web.context.request.NativeWebRequest webRequest)protected StringdeterminePreviewSandbox(org.springframework.web.context.request.NativeWebRequest webRequest)protected PreviewTokendeterminePreviewToken(org.springframework.web.context.request.NativeWebRequest webRequest)protected List<ContextRequestConverter>getConverters()protected List<ContextInfoCustomizer>getCustomizers()protected PreviewDateWebRequestResolvergetPreviewDateResolver()protected PreviewSandboxWebRequestResolvergetPreviewSandboxResolver()protected PreviewTokenWebRequestResolvergetPreviewTokenResolver()protected com.broadleafcommerce.common.extension.data.DataRouteReferencegetReference()ContextInforesolveContextInfo(@NonNull org.springframework.web.context.request.NativeWebRequest req, @NonNull ContextRequest contextRequest, @NonNull OperationType operationType, org.springframework.core.MethodParameter methodParameter)Builds aContextInfowith the givencontextRequestandoperationType, with additional fields populated from data gathered inreq.ContextInforesolveContextInfo(@NonNull org.springframework.web.context.request.NativeWebRequest req, @NonNull OperationType operationType, org.springframework.core.MethodParameter methodParameter)A convenience method that builds both aContextInfoand itsContextRequestfrom the given web request.ContextRequestresolveContextRequest(@NonNull org.springframework.web.context.request.NativeWebRequest webRequest)Resolves theContextRequestof a given request based on either the request headers or request parameters.protected ContextRequestresolveContextRequestFromHeader(String header)protected ContextRequestresolveContextRequestFromParameter(String param)
-
-
-
Field Detail
-
CLEAR_OVERRIDE_PARAM
public static final String CLEAR_OVERRIDE_PARAM
- See Also:
- Constant Field Values
-
CONTEXT_REQUEST_PARAM
public static final String CONTEXT_REQUEST_PARAM
- See Also:
- Constant Field Values
-
PREVIEW_SANDBOX_HEADER
public static final String PREVIEW_SANDBOX_HEADER
- See Also:
- Constant Field Values
-
ACCOUNT_ID_HEADER
public static final String ACCOUNT_ID_HEADER
- See Also:
- Constant Field Values
-
defaultAllowAllAnonymous
@Value("${broadleaf.resource.security.oauth2.defaultAllowAllAnonymous:false}") protected boolean defaultAllowAllAnonymous
-
defaultAuthor
@Value("${broadleaf.tracking.defaultAuthor:DEFAULT_AUTHOR}") protected String defaultAuthor
-
-
Constructor Detail
-
ContextInfoWebRequestResolver
public ContextInfoWebRequestResolver(@Nullable com.broadleafcommerce.common.extension.data.DataRouteReference reference, List<ContextRequestConverter> converters, PreviewTokenWebRequestResolver previewTokenResolver, PreviewDateWebRequestResolver previewDateResolver, PreviewSandboxWebRequestResolver previewSandboxResolver, @Nullable List<ContextInfoCustomizer> customizers)
-
-
Method Detail
-
resolveContextRequest
public ContextRequest resolveContextRequest(@NonNull @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
Resolves theContextRequestof a given request based on either the request headers or request parameters.- Parameters:
webRequest- the web request being consumed- Returns:
- a formed
ContextRequestbased on the request - See Also:
resolveContextInfo(NativeWebRequest, OperationType, MethodParameter)
-
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 aContextInfoand itsContextRequestfrom the given web request.Delegates to
resolveContextRequest(NativeWebRequest)to build theContextRequest, then passes the result toresolveContextInfo(NativeWebRequest, ContextRequest, OperationType, MethodParameter).- Parameters:
req- the web request from which to source information to build the context infooperationType- the operation type to set on the context-infomethodParameter- (optional) the method that initiated the instantiation of this ContextInfo instance, if any. This is passed along to eachContextInfoCustomizer.- Returns:
- a context info built from the information in the web request
- See Also:
resolveContextRequest(NativeWebRequest),resolveContextInfo(NativeWebRequest, ContextRequest, OperationType, MethodParameter)
-
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 aContextInfowith the givencontextRequestandoperationType, with additional fields populated from data gathered inreq.ContextInfoCustomizersare also invoked as part of this process.- Parameters:
req- the web request from which to source information to build the context infocontextRequest- the context request to set on the context-infooperationType- the operation type to set on the context-infomethodParameter- (optional) the method that initiated the instantiation of this ContextInfo instance, if any. This is passed along to eachContextInfoCustomizer.- 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)
-
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()
-
-