Class ContextInfoWebRequestResolver
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionContextInfoWebRequestResolver(com.broadleafcommerce.common.extension.data.DataRouteReference reference, List<ContextRequestConverter> converters, PreviewTokenWebRequestResolver previewTokenResolver, PreviewDateWebRequestResolver previewDateResolver, PreviewSandboxWebRequestResolver previewSandboxResolver, List<ContextInfoCustomizer> customizers) -
Method Summary
Modifier and TypeMethodDescriptionprotected 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>protected List<ContextInfoCustomizer>protected PreviewDateWebRequestResolverprotected PreviewSandboxWebRequestResolverprotected PreviewTokenWebRequestResolverprotected com.broadleafcommerce.common.extension.data.DataRouteReferenceresolveContextInfo(@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.resolveContextInfo(@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.resolveContextRequest(@NonNull org.springframework.web.context.request.NativeWebRequest webRequest) Resolves theContextRequestof a given request based on either the request headers or request parameters.protected ContextRequestprotected ContextRequest
-
Field Details
-
CLEAR_OVERRIDE_PARAM
- See Also:
-
CONTEXT_REQUEST_PARAM
- See Also:
-
PREVIEW_SANDBOX_HEADER
- See Also:
-
ACCOUNT_ID_HEADER
- See Also:
-
defaultAllowAllAnonymous
@Value("${broadleaf.resource.security.oauth2.defaultAllowAllAnonymous:false}") protected boolean defaultAllowAllAnonymous -
defaultAuthor
-
-
Constructor Details
-
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 Details
-
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:
-
resolveContextRequestFromHeader
-
resolveContextRequestFromParameter
-
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:
-
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:
-
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
-
getPreviewTokenResolver
-
getPreviewDateResolver
-
getPreviewSandboxResolver
-
getCustomizers
-