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.locale
withWebRequest.getLocale()
andContextInfo.ignoreTranslation
with "X-Ignore-Translation" if provided.Note that even if there is no
X-Context-Request
header specified in the request, a non-nullContextInfo
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 parametercontextRequest
instead.- See Also:
ContextInfoHandlerMethodArgumentResolver
-
-
Field Summary
Fields Modifier and Type Field Description static String
ACCOUNT_ID_HEADER
static String
CLEAR_OVERRIDE_PARAM
static String
CONTEXT_REQUEST_PARAM
protected boolean
defaultAllowAllAnonymous
protected String
defaultAuthor
static String
PREVIEW_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 void
applyCustomizers(@NonNull ContextInfo contextInfo, org.springframework.core.MethodParameter methodParameter, @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
protected void
applyPreviewBehaviorIfPossible(org.springframework.web.context.request.NativeWebRequest req, ContextInfo response)
protected void
determineAccountId(ContextRequest contextRequest, org.springframework.web.context.request.NativeWebRequest req)
protected String
determineAuthor(@NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
protected boolean
determineClearOverride(org.springframework.web.context.request.NativeWebRequest req, OperationType operationType)
protected boolean
determineIgnoreTranslation(org.springframework.web.context.request.NativeWebRequest req)
protected String
determineIpAddress(@NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
protected Instant
determinePreviewDate(org.springframework.web.context.request.NativeWebRequest webRequest)
protected String
determinePreviewSandbox(org.springframework.web.context.request.NativeWebRequest webRequest)
protected PreviewToken
determinePreviewToken(org.springframework.web.context.request.NativeWebRequest webRequest)
protected List<ContextRequestConverter>
getConverters()
protected List<ContextInfoCustomizer>
getCustomizers()
protected PreviewDateWebRequestResolver
getPreviewDateResolver()
protected PreviewSandboxWebRequestResolver
getPreviewSandboxResolver()
protected PreviewTokenWebRequestResolver
getPreviewTokenResolver()
protected com.broadleafcommerce.common.extension.data.DataRouteReference
getReference()
ContextInfo
resolveContextInfo(@NonNull org.springframework.web.context.request.NativeWebRequest req, @NonNull ContextRequest contextRequest, @NonNull OperationType operationType, org.springframework.core.MethodParameter methodParameter)
Builds aContextInfo
with the givencontextRequest
andoperationType
, with additional fields populated from data gathered inreq
.ContextInfo
resolveContextInfo(@NonNull org.springframework.web.context.request.NativeWebRequest req, @NonNull OperationType operationType, org.springframework.core.MethodParameter methodParameter)
A convenience method that builds both aContextInfo
and itsContextRequest
from the given web request.ContextRequest
resolveContextRequest(@NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
Resolves theContextRequest
of a given request based on either the request headers or request parameters.protected ContextRequest
resolveContextRequestFromHeader(String header)
protected ContextRequest
resolveContextRequestFromParameter(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 theContextRequest
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:
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 aContextInfo
and itsContextRequest
from 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 aContextInfo
with the givencontextRequest
andoperationType
, with additional fields populated from data gathered inreq
.ContextInfoCustomizers
are 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()
-
-