Class InterlinkRequest

java.lang.Object
com.broadleafcommerce.data.tracking.core.interlink.InterlinkRequest

public class InterlinkRequest extends Object
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 Details

    • InterlinkRequest

      public InterlinkRequest(String name)
  • Method Details

    • withUri

      public InterlinkRequest withUri(String uri)
      The uri used for WebClient connection. This information is also used internally in InterlinkClient for determination of ContextInfo, among others. When applicable, uris should use a template convention for replacement via getArguments(). Template replacement is facilitated by the usage of curly brace notated segments. For example, a template of https://localhost:8447/service/{id} and a UrlArgument instance with a name of "id" and a value of "1" will result in a completed url of https://localhost:8447/service/1. Template values also extend to query params. For example, a template of https://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 of https://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 UrlArgument instances, since there is no longer any need for uri variable substitutions.

      Parameters:
      uri - The uri used for WebClient connection
      Returns:
      This
    • withAllowLocalCall

      public InterlinkRequest withAllowLocalCall(boolean allowLocalCall)
      Specifies whether local calls within the system are allowed for this InterlinkRequest. 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 override InterlinkProperties.Interlink.isLoopBackOptimized()}.
      Returns:
      The current InterlinkRequest instance for method chaining.
    • withWebClient

      public InterlinkRequest withWebClient(org.springframework.web.reactive.function.client.WebClient webClient)
      Configures the WebClient instance to be used for making requests. Setting a WebClient allows customization of the HTTP client for making network calls through the configured InterlinkRequest. This setting is optional. If not set, the webclient already injected into DefaultInterlinkClient will be used when making network calls. Only applies when the reflection flow is not used.
      Parameters:
      webClient - The WebClient instance to be used for making network requests.
      Returns:
      The current InterlinkRequest instance.
    • withMonoCustomizer

      public InterlinkRequest withMonoCustomizer(Function<reactor.core.publisher.Mono<?>,reactor.core.publisher.Mono<?>> monoCustomizer)
      Customizes the Mono instance used within the InterlinkRequest. The provided consumer allows additional configuration or transformation of the Mono<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 a reactor.core.publisher.Mono<String> instance for customization or transformation.
      Returns:
      The current InterlinkRequest instance, enabling method chaining.
    • withRequestMethod

      public InterlinkRequest withRequestMethod(org.springframework.http.HttpMethod method)
      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

      public InterlinkRequest withAttributesCustomizer(Consumer<Map<String,Object>> attributesCustomizer)
      Consumer supplying request attributes you can customize. Generally used during WebClient network requests, but may be also interpreted for other purposes in the InterlinkClient.
      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 a HttpHeaders instance you can customize with headers for the request. Generally used during WebClient network requests, but may be also interpreted for other purposes in the InterlinkClient.
      Parameters:
      headersCustomizer - Consumer supplying a HttpHeaders instance you can customize with headers for the request.
      Returns:
      This
    • withContextRequestHeader

      public InterlinkRequest withContextRequestHeader(ContextRequest contextRequest, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Include a ContextRequest to apply as a header during the request. Generally used during WebClient network requests, but may be also interpreted for other purposes in the InterlinkClient.
      Parameters:
      contextRequest - The ContextRequest whose serialized value should be applied as a header
      objectMapper - The Jackson ObjectMapper instance to use for serialization
      Returns:
      This
    • withArguments

      public InterlinkRequest 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. Note, if a method signature calls for a ContextInfo instance, it need not be included in arguments. ContextInfo instances will be constructed dynamically as required. However, any ContextRequest requirements should be included via the withContextRequestHeader(ContextRequest, ObjectMapper) call.
      Parameters:
      arguments - The main object params to pass for the call
      Returns:
      This
      See Also:
    • withPrincipal

      public InterlinkRequest withPrincipal(String principal)
      The authentication principal name that should be associated with the call. This is generally used for construction of ContextInfo instances during direct method calls in the InterlinkClient. 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

      public InterlinkRequest withLocale(Locale locale)
      The locale that should be associated with the call. This is generally used for construction of ContextInfo instances during direct method calls in the InterlinkClient.
      Parameters:
      locale - The locale to use
      Returns:
      This
    • getName

      public String getName()
    • getUri

      public String getUri()
    • getAttributesCustomizer

      public Consumer<Map<String,Object>> getAttributesCustomizer()
    • getHeadersCustomizer

      public Consumer<org.springframework.http.HttpHeaders> getHeadersCustomizer()
    • getContextRequestHeaderCustomizer

      public Consumer<org.springframework.http.HttpHeaders> getContextRequestHeaderCustomizer()
    • getRequestCustomizer

      public Consumer<org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec<?>> getRequestCustomizer()
    • getArguments

      public List<Argument<?>> getArguments()
    • getPrincipal

      public String getPrincipal()
    • getLocale

      public Locale getLocale()
    • getFallback

      public Function<?,?> getFallback()
    • getMethod

      public org.springframework.http.HttpMethod getMethod()
    • getWebClient

      public org.springframework.web.reactive.function.client.WebClient getWebClient()
    • getMonoCustomizer

      public Function<reactor.core.publisher.Mono<?>,reactor.core.publisher.Mono<?>> getMonoCustomizer()
    • getAllowLocalCall

      public Boolean getAllowLocalCall()
    • setUri

      public void setUri(String uri)
    • setAttributesCustomizer

      public void setAttributesCustomizer(Consumer<Map<String,Object>> attributesCustomizer)
    • setHeadersCustomizer

      public void setHeadersCustomizer(Consumer<org.springframework.http.HttpHeaders> headersCustomizer)
    • 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

      public void setArguments(List<Argument<?>> arguments)
    • setPrincipal

      public void setPrincipal(String principal)
    • setLocale

      public void setLocale(Locale locale)
    • setFallback

      public void setFallback(Function<?,?> fallback)
    • 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

      public void setAllowLocalCall(Boolean allowLocalCall)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object