Class InterlinkRequest
java.lang.Object
com.broadleafcommerce.data.tracking.core.interlink.InterlinkRequest
Describes a request for making a call to another microservice. The information at this level is
abstract. Some parts of the request may apply to both local and remote interlink calls. However,
some parts may only apply to remote requests (e.g. uri and method).
READ configuration (using a read endpoint method either reflectively, or via webclient)
In a Spring configuration class (establishes the method to use for reflection, when available)
@Bean
public InterlinkReflectionInfo interlinkReflectionInfoRead() {
return new InterlinkReflectionInfo(
"readSchool",
"com.broadleafcommerce.TestEndpoint",
"handleRead",
List.of(String.class.getName(), int.class.getName(),
ContextInfo.class.getName()));
}
In your implementation where you want to make the interlink request
InterlinkRequest request = new InterlinkRequest("readSchool")
.withRequestMethod(HttpMethod.GET)
.withUri("/some/uri/{school}/{assignment}")
.withArguments(List.of(
new UrlArgument("school", "school1"),
new UrlArgument("assignment", "1"),
new MethodArgument(0, "school1"),
new MethodArgument(1, 1)))
.withAttributesCustomizer(ServerOAuth2AuthorizedClientExchangeFilterFunction
.clientRegistrationId("my-service-client"))
.withContextRequestHeader(
new ContextRequest().withTenantId("MyTenantId"),
objectMapper);
return defaultInterlinkClient.invoke(request);
CREATE configuration (using a create endpoint method either reflectively, or via webclient)
In a Spring configuration class (establishes the method to use for reflection, when available)
@Bean
public InterlinkReflectionInfo interlinkReflectionInfoCreate() {
return new InterlinkReflectionInfo(
"createSchool",
"com.broadleafcommerce.TestEndpoint",
"handleCreate",
List.of(Pojo.class.getName(), ContextInfo.class.getName()));
}
In your implementation where you want to make the interlink request
InterlinkRequest request = new InterlinkRequest("createSchool")
.withRequestMethod(HttpMethod.POST)
.withUri("/some/uri")
.withArguments(List.of(
new BodyArgument(json),
new MethodArgument(0, json)))
.withAttributesCustomizer(ServerOAuth2AuthorizedClientExchangeFilterFunction
.clientRegistrationId("my-service-client"))
.withContextRequestHeader(
new ContextRequest().withTenantId("MyTenantId"),
objectMapper);
return defaultInterlinkClient.invoke(request);
UPDATE configuration (using an update endpoint method either reflectively, or via webclient)
In a Spring configuration class (establishes the method to use for reflection, when available)
@Bean
public InterlinkReflectionInfo interlinkReflectionInfoUpdate() {
return new InterlinkReflectionInfo(
"updateSchool",
"com.broadleafcommerce.TestEndpoint",
"handleUpdate",
List.of(String.class.getName(), int.class.getName(),
Pojo.class.getName(), ContextInfo.class.getName()));
}
In your implementation where you want to make the interlink request (this could be PUT or PATCH, depending on the case)
InterlinkRequest request = new InterlinkRequest("updateSchool")
.withRequestMethod(HttpMethod.PUT)
.withUri("/some/uri/{school}/{assignment}")
.withArguments(List.of(
new UrlArgument("school", "school1"),
new UrlArgument("assignment", "1"),
new BodyArgument(json),
new MethodArgument(0, "school1"),
new MethodArgument(1, 1),
new MethodArgument(2, json)))
.withAttributesCustomizer(ServerOAuth2AuthorizedClientExchangeFilterFunction
.clientRegistrationId("my-service-client"))
.withContextRequestHeader(
new ContextRequest().withTenantId("MyTenantId"),
objectMapper);
return defaultInterlinkClient.invoke(request);
DELETE configuration (using a delete endpoint method either reflectively, or via webclient)
In a Spring configuration class (establishes the method to use for reflection, when available)
@Bean
public InterlinkReflectionInfo interlinkReflectionInfoDelete() {
return new InterlinkReflectionInfo(
"deleteSchool",
"com.broadleafcommerce.TestEndpoint",
"handleDelete",
List.of(String.class.getName(), int.class.getName(),
ContextInfo.class.getName()));
}
In your implementation where you want to make the interlink request
InterlinkRequest request = new InterlinkRequest("deleteSchool")
.withRequestMethod(HttpMethod.DELETE)
.withUri("/some/uri/{school}/{assignment}")
.withArguments(List.of(
new UrlArgument("school", "school1"),
new UrlArgument("assignment", "1"),
new MethodArgument(0, "school1"),
new MethodArgument(1, 1)))
.withAttributesCustomizer(ServerOAuth2AuthorizedClientExchangeFilterFunction
.clientRegistrationId("my-service-client"))
.withContextRequestHeader(
new ContextRequest().withTenantId("MyTenantId"),
objectMapper);
defaultInterlinkClient.invoke(request);
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleanConsumer<org.springframework.http.HttpHeaders>Function<?,?> Consumer<org.springframework.http.HttpHeaders>org.springframework.http.HttpMethodFunction<reactor.core.publisher.Mono<?>,reactor.core.publisher.Mono<?>> getName()Consumer<org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec<?>>getUri()org.springframework.web.reactive.function.client.WebClientinthashCode()voidsetAllowLocalCall(Boolean allowLocalCall) voidsetArguments(List<Argument<?>> arguments) voidsetAttributesCustomizer(Consumer<Map<String, Object>> attributesCustomizer) voidsetContextRequestHeaderCustomizer(Consumer<org.springframework.http.HttpHeaders> contextRequestHeaderCustomizer) voidsetFallback(Function<?, ?> fallback) voidsetHeadersCustomizer(Consumer<org.springframework.http.HttpHeaders> headersCustomizer) voidvoidsetMethod(org.springframework.http.HttpMethod method) voidsetMonoCustomizer(Function<reactor.core.publisher.Mono<?>, reactor.core.publisher.Mono<?>> monoCustomizer) voidsetPrincipal(String principal) voidsetRequestCustomizer(Consumer<org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec<?>> requestCustomizer) voidvoidsetWebClient(org.springframework.web.reactive.function.client.WebClient webClient) toString()withAllowLocalCall(boolean allowLocalCall) Specifies whether local calls within the system are allowed for thisInterlinkRequest.withArguments(List<Argument<?>> arguments) One or more argument objects that may either be used as direct method call params, serialized as JSON in request body posts, or replaced into url templates.withAttributesCustomizer(Consumer<Map<String, Object>> attributesCustomizer) Consumer supplying request attributes you can customize.withContextRequestHeader(ContextRequest contextRequest, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Include aContextRequestto apply as a header during the request.withHeadersCustomizer(Consumer<org.springframework.http.HttpHeaders> headersCustomizer) Consumer supplying aHttpHeadersinstance you can customize with headers for the request.withLocale(Locale locale) The locale that should be associated with the call.withMonoCustomizer(Function<reactor.core.publisher.Mono<?>, reactor.core.publisher.Mono<?>> monoCustomizer) Customizes theMonoinstance used within theInterlinkRequest.withPrincipal(String principal) The authentication principal name that should be associated with the call.withRequestCustomizer(Consumer<org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec<?>> requestCustomizer) Consumer supplying a webclient request spec you can customize.withRequestMethod(org.springframework.http.HttpMethod method) When making remote calls, the HTTP request method that should be used to make the call.The uri used for WebClient connection.withWebClient(org.springframework.web.reactive.function.client.WebClient webClient) Configures theWebClientinstance to be used for making requests.
-
Constructor Details
-
InterlinkRequest
-
-
Method Details
-
withUri
The uri used for WebClient connection. This information is also used internally inInterlinkClientfor determination ofContextInfo, among others. When applicable,urisshould use a template convention for replacement viagetArguments(). Template replacement is facilitated by the usage of curly brace notated segments. For example, a template ofhttps://localhost:8447/service/{id}and a UrlArgument instance with a name of "id" and a value of "1" will result in a completed url ofhttps://localhost:8447/service/1. Template values also extend to query params. For example, a template ofhttps://localhost:8447/service/{id}?param1={param1}and a UrlArgument instance with a name of "param1" and a value of "2" will result in a completed url ofhttps://localhost:8447/service/1?param1=2.Note, if you pre-build the URI before passing in (i.e. no template variables used), then you will not need to use
UrlArgumentinstances, since there is no longer any need for uri variable substitutions.- Parameters:
uri- The uri used for WebClient connection- Returns:
- This
-
withAllowLocalCall
Specifies whether local calls within the system are allowed for thisInterlinkRequest. By enabling or disabling this option, it controls whether the request can bypass external routing and execute within the local system context.- Parameters:
allowLocalCall- A boolean flag indicating if local calls are permitted. If true, local calls are enabled; otherwise, they are disabled. Defaults to true. If set, will overrideInterlinkProperties.Interlink.isLoopBackOptimized()}.- Returns:
- The current
InterlinkRequestinstance for method chaining.
-
withWebClient
public InterlinkRequest withWebClient(org.springframework.web.reactive.function.client.WebClient webClient) Configures theWebClientinstance to be used for making requests. Setting a WebClient allows customization of the HTTP client for making network calls through the configuredInterlinkRequest. This setting is optional. If not set, the webclient already injected intoDefaultInterlinkClientwill be used when making network calls. Only applies when the reflection flow is not used.- Parameters:
webClient- TheWebClientinstance to be used for making network requests.- Returns:
- The current
InterlinkRequestinstance.
-
withMonoCustomizer
public InterlinkRequest withMonoCustomizer(Function<reactor.core.publisher.Mono<?>, reactor.core.publisher.Mono<?>> monoCustomizer) Customizes theMonoinstance used within theInterlinkRequest. The provided consumer allows additional configuration or transformation of theMono<String>instance within the request processing workflow. This setting is optional. Only applies when the reflection flow is not used.- Parameters:
monoCustomizer- A consumer that accepts areactor.core.publisher.Mono<String>instance for customization or transformation.- Returns:
- The current
InterlinkRequestinstance, enabling method chaining.
-
withRequestMethod
When making remote calls, the HTTP request method that should be used to make the call.- Parameters:
method- The HTTP request method that should be used to make the call- Returns:
- This
-
withAttributesCustomizer
Consumer supplying request attributes you can customize. Generally used during WebClient network requests, but may be also interpreted for other purposes in theInterlinkClient.- Parameters:
attributesCustomizer- Consumer supplying request attributes you can customize- Returns:
- This
-
withRequestCustomizer
public InterlinkRequest withRequestCustomizer(Consumer<org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec<?>> requestCustomizer) Consumer supplying a webclient request spec you can customize. Generally used for more specific fine-tuning of a webclient request beyond what is standard (e.g. adding cookies).- Parameters:
requestCustomizer- Consumer supplying a webclient request spec you can customize.- Returns:
- This
-
withHeadersCustomizer
public InterlinkRequest withHeadersCustomizer(Consumer<org.springframework.http.HttpHeaders> headersCustomizer) Consumer supplying aHttpHeadersinstance you can customize with headers for the request. Generally used during WebClient network requests, but may be also interpreted for other purposes in theInterlinkClient.- Parameters:
headersCustomizer- Consumer supplying aHttpHeadersinstance you can customize with headers for the request.- Returns:
- This
-
withContextRequestHeader
public InterlinkRequest withContextRequestHeader(ContextRequest contextRequest, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Include aContextRequestto apply as a header during the request. Generally used during WebClient network requests, but may be also interpreted for other purposes in theInterlinkClient.- Parameters:
contextRequest- TheContextRequestwhose serialized value should be applied as a headerobjectMapper- The JacksonObjectMapperinstance to use for serialization- Returns:
- This
-
withArguments
One or more argument objects that may either be used as direct method call params, serialized as JSON in request body posts, or replaced into url templates. Note, if a method signature calls for aContextInfoinstance, it need not be included in arguments.ContextInfoinstances will be constructed dynamically as required. However, anyContextRequestrequirements should be included via thewithContextRequestHeader(ContextRequest, ObjectMapper)call.- Parameters:
arguments- The main object params to pass for the call- Returns:
- This
- See Also:
-
withPrincipal
The authentication principal name that should be associated with the call. This is generally used for construction ofContextInfoinstances during direct method calls in theInterlinkClient. For network requests, the principal will generally be determined via the authorization mechanism based on the oauth token, in which case, this value is ignored.- Parameters:
principal- The principal name to use- Returns:
- This
-
withLocale
The locale that should be associated with the call. This is generally used for construction ofContextInfoinstances during direct method calls in theInterlinkClient.- Parameters:
locale- The locale to use- Returns:
- This
-
getName
-
getUri
-
getAttributesCustomizer
-
getHeadersCustomizer
-
getContextRequestHeaderCustomizer
-
getRequestCustomizer
public Consumer<org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec<?>> getRequestCustomizer() -
getArguments
-
getPrincipal
-
getLocale
-
getFallback
-
getMethod
public org.springframework.http.HttpMethod getMethod() -
getWebClient
public org.springframework.web.reactive.function.client.WebClient getWebClient() -
getMonoCustomizer
-
getAllowLocalCall
-
setUri
-
setAttributesCustomizer
-
setHeadersCustomizer
-
setContextRequestHeaderCustomizer
public void setContextRequestHeaderCustomizer(Consumer<org.springframework.http.HttpHeaders> contextRequestHeaderCustomizer) -
setRequestCustomizer
public void setRequestCustomizer(Consumer<org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec<?>> requestCustomizer) -
setArguments
-
setPrincipal
-
setLocale
-
setFallback
-
setMethod
public void setMethod(org.springframework.http.HttpMethod method) -
setWebClient
public void setWebClient(org.springframework.web.reactive.function.client.WebClient webClient) -
setMonoCustomizer
public void setMonoCustomizer(Function<reactor.core.publisher.Mono<?>, reactor.core.publisher.Mono<?>> monoCustomizer) -
setAllowLocalCall
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-