Class CommonInternalServiceClientConnectorFactory

java.lang.Object
com.broadleafcommerce.common.extension.webclient.autoconfigure.CommonInternalServiceClientConnectorFactory

public class CommonInternalServiceClientConnectorFactory extends Object

Builds ClientHttpConnectors for internal service-to-service communication on top of the shared, observable connection pool (commonIntlSvcConnectionProvider) and the common broadleaf.common.ssl-verification.disabled policy.

Most Broadleaf services intentionally declare their own connector bean (ex: pricingClientHttpConnector, interlinkClientHttpConnector) rather than consuming the central commonIntlSvcClientConnector, so that each service remains individually overridable. That is a deliberate design decision, but it previously meant every one of those connectors ended up on Reactor Netty's anonymous global HttpResources pool, where connection saturation cannot be measured. This factory closes that gap without taking the per-service beans away: a service keeps its own bean and simply builds it from here.

 @Bean
 @ConditionalOnMissingBean(name = "pricingClientHttpConnector")
 public ClientHttpConnector pricingClientHttpConnector(
         CommonInternalServiceClientConnectorFactory connectorFactory) {
     return connectorFactory.createConnector();
 }
 

Services that need to customize the underlying client first (wiretap logging, response timeouts, proxy settings, and so on) can start from createHttpClient() and hand the result back to createConnector(HttpClient), which keeps them on the shared pool while still applying the common SSL policy.

Since:
MicroExtensionCommon 3.0.0
  • Constructor Details

    • CommonInternalServiceClientConnectorFactory

      public CommonInternalServiceClientConnectorFactory(CommonInternalServiceSSLVerificationProperties sslVerificationProperties, @Nullable reactor.netty.resources.ConnectionProvider connectionProvider)
  • Method Details

    • unpooled

      Creates a factory with no shared connection pool, applying only the common SSL policy.

      This exists so that a service's connector bean can depend on the commonIntlSvcClientConnectorFactory bean optionally. Sliced test contexts (@DataJpaTest and friends) import a service's configuration directly without MicroExtensionCommon's auto-configuration - and are usually not servlet web applications, which that auto-configuration requires - so the factory bean is simply absent there. Falling back to this keeps such contexts starting with exactly the pre-pool behavior instead of failing on an unsatisfied dependency:

       return connectorFactoryProvider
               .getIfAvailable(() -> CommonInternalServiceClientConnectorFactory
                       .unpooled(sslVerificationProperties))
               .createConnector();
       
      Parameters:
      sslVerificationProperties - the internal SSL verification configuration
      Returns:
      a factory that builds connectors on Reactor Netty's global pool
    • createHttpClient

      public reactor.netty.http.client.HttpClient createHttpClient()
      Creates an HttpClient bound to the shared internal connection pool, with no SSL policy applied yet. Use this when the client needs further customization before being turned into a connector via createConnector(HttpClient).
      Returns:
      an unconfigured client on the shared internal connection pool
    • createConnector

      @Nullable public org.springframework.http.client.reactive.ClientHttpConnector createConnector()
      Creates the connector for internal service-to-service communication: the shared connection pool plus the common SSL verification policy.
      Returns:
      the connector, or null when there is nothing to contribute over the WebClient builder's own default connector - that is, when the shared pool is disabled and SSL verification is left enabled. Callers should treat null as "let the WebClient builder initialize its default connector". Note that null means "no opinion", never "something failed"; a broken SSL configuration throws.
      Throws:
      IllegalStateException - if the insecure SslContext could not be built
    • createConnector

      public org.springframework.http.client.reactive.ClientHttpConnector createConnector(reactor.netty.http.client.HttpClient httpClient)

      Applies the common SSL verification policy to an already-customized HttpClient. The caller is responsible for having sourced that client from createHttpClient() if it should participate in the shared connection pool.

      Unlike createConnector(), this never returns null: the caller has handed over a configured client, and quietly discarding it (timeouts, wiretap, proxy settings and all) in favor of the WebClient builder's default connector would be worse than failing. An SslContext that cannot be built is a misconfiguration, not a degraded mode.

      Parameters:
      httpClient - the client to wrap
      Returns:
      the connector for the given client, never null
      Throws:
      IllegalStateException - if the insecure SslContext could not be built