public class ContextInfoWebRequestResolver extends Object
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.
ContextInfoHandlerMethodArgumentResolver
Modifier and Type | Field and Description |
---|---|
static String |
CLEAR_OVERRIDE_PARAM |
static String |
CONTEXT_REQUEST_PARAM |
protected boolean |
defaultAllowAllAnonymous |
protected String |
defaultAuthor |
static String |
PREVIEW_SANDBOX_HEADER |
Constructor and Description |
---|
ContextInfoWebRequestResolver(com.broadleafcommerce.common.extension.data.DataRouteReference reference,
List<ContextRequestConverter> converters,
PreviewTokenWebRequestResolver previewTokenResolver,
PreviewDateWebRequestResolver previewDateResolver,
PreviewSandboxWebRequestResolver previewSandboxResolver,
List<ContextInfoCustomizer> customizers) |
Modifier and Type | Method and 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 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 a
ContextInfo with the given contextRequest and operationType ,
with additional fields populated from data gathered in req . |
ContextInfo |
resolveContextInfo(@NonNull org.springframework.web.context.request.NativeWebRequest req,
@NonNull OperationType operationType,
org.springframework.core.MethodParameter methodParameter)
A convenience method that builds both a
ContextInfo and its ContextRequest
from the given web request. |
ContextRequest |
resolveContextRequest(@NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
Resolves the
ContextRequest of a given request based on either the request headers or
request parameters. |
protected ContextRequest |
resolveContextRequestFromHeader(String header) |
protected ContextRequest |
resolveContextRequestFromParameter(String param) |
public static final String CLEAR_OVERRIDE_PARAM
public static final String CONTEXT_REQUEST_PARAM
public static final String PREVIEW_SANDBOX_HEADER
@Value(value="${broadleaf.resource.security.oauth2.defaultAllowAllAnonymous:false}") protected boolean defaultAllowAllAnonymous
@Value(value="${broadleaf.tracking.defaultAuthor:DEFAULT_AUTHOR}") protected String defaultAuthor
public ContextInfoWebRequestResolver(@Nullable com.broadleafcommerce.common.extension.data.DataRouteReference reference, List<ContextRequestConverter> converters, PreviewTokenWebRequestResolver previewTokenResolver, PreviewDateWebRequestResolver previewDateResolver, PreviewSandboxWebRequestResolver previewSandboxResolver, @Nullable List<ContextInfoCustomizer> customizers)
public ContextRequest resolveContextRequest(@NonNull @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
ContextRequest
of a given request based on either the request headers or
request parameters.webRequest
- the web request being consumedContextRequest
based on the requestresolveContextInfo(NativeWebRequest, OperationType, MethodParameter)
protected ContextRequest resolveContextRequestFromHeader(String header)
protected ContextRequest resolveContextRequestFromParameter(String param)
public ContextInfo resolveContextInfo(@NonNull @NonNull org.springframework.web.context.request.NativeWebRequest req, @NonNull @NonNull OperationType operationType, @Nullable org.springframework.core.MethodParameter methodParameter)
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)
.
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 each
ContextInfoCustomizer
.resolveContextRequest(NativeWebRequest)
,
resolveContextInfo(NativeWebRequest, ContextRequest, OperationType, MethodParameter)
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)
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.
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 each
ContextInfoCustomizer
.resolveContextInfo(NativeWebRequest, OperationType, MethodParameter)
protected void applyPreviewBehaviorIfPossible(org.springframework.web.context.request.NativeWebRequest req, ContextInfo response)
protected String determineIpAddress(@NonNull @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
@Nullable protected String determineAuthor(@NonNull @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
protected PreviewToken determinePreviewToken(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 boolean determineClearOverride(org.springframework.web.context.request.NativeWebRequest req, OperationType operationType)
protected boolean determineIgnoreTranslation(org.springframework.web.context.request.NativeWebRequest req)
protected void applyCustomizers(@NonNull @NonNull ContextInfo contextInfo, @Nullable org.springframework.core.MethodParameter methodParameter, @NonNull @NonNull org.springframework.web.context.request.NativeWebRequest webRequest)
@Nullable protected com.broadleafcommerce.common.extension.data.DataRouteReference getReference()
protected List<ContextRequestConverter> getConverters()
protected PreviewTokenWebRequestResolver getPreviewTokenResolver()
protected PreviewDateWebRequestResolver getPreviewDateResolver()
protected PreviewSandboxWebRequestResolver getPreviewSandboxResolver()
@Nullable protected List<ContextInfoCustomizer> getCustomizers()
Copyright © 2021. All rights reserved.