Class TransparentProxy

java.lang.Object
com.sap.cloud.sdk.cloudplatform.connectivity.TransparentProxy
All Implemented Interfaces:
DestinationLoader

public class TransparentProxy extends Object implements DestinationLoader
A transparent proxy loader that enables routing traffic through a single registered gateway host.

This class provides a mechanism to register a proxy gateway that will handle all destination requests transparently. Once registered, all destination lookups will be routed through the configured gateway host and port.

Key Features:

  • Single gateway registration - only one proxy can be registered at a time
  • Host validation - ensures hosts don't contain paths and are reachable
  • Automatic scheme normalization - defaults to HTTP if no scheme provided
  • Network connectivity validation before registration

Usage Example:


 // Register with default port 80
 TransparentProxy.register("gateway.svc.cluster.local");

 // Register with custom port
 TransparentProxy.register("http://gateway.svc.cluster.local", 8080);
 

Thread Safety: This class uses static state and is not thread-safe. Registration should be performed during application initialization.

Since:
5.24.0
  • Constructor Details

    • TransparentProxy

      public TransparentProxy()
  • Method Details

    • register

      public static void register(@Nonnull String host)
      Registers a transparent proxy gateway using the default port 80.

      This method registers the specified host as a transparent proxy gateway that will handle all subsequent destination requests. The host will be validated for reachability and must not contain any path components.

      If no scheme is provided, HTTP will be used by default. The final URI will be constructed as: <normalized-host>:80

      Parameters:
      host - the gateway host to register (e.g., "gateway.svc.cluster.local") Must not contain paths or be null
      Throws:
      DestinationAccessException - if the proxy is already registered, the host contains a path, or the host is not reachable on port 80
      IllegalArgumentException - if host is null
      See Also:
    • register

      public static void register(@Nonnull String host, @Nonnull Integer port)
      Registers a transparent proxy gateway with a specified port.

      This method registers the specified host and port as a transparent proxy gateway that will handle all subsequent destination requests. The host will be validated for reachability on the specified port and must not contain any path components.

      If no scheme is provided, HTTP will be used by default. The final URI will be constructed as: <normalized-host>:<port>

      Parameters:
      host - the gateway host to register (e.g., "gateway" or "...") Must not contain paths or be null
      port - the port number to use for the gateway connection. Must not be null and should be a valid port number (1-65535)
      Throws:
      DestinationAccessException - if the proxy is already registered, the host contains a path, or the host is not reachable on the specified port
      IllegalArgumentException - if host or port is null
      See Also:
    • register

      public static void register(@Nonnull String host, @Nonnull Integer port, @Nonnull String providerTenantId)
      Registers a transparent proxy gateway with a specified port and provider tenant ID.

      This method registers the specified host and port as a transparent proxy gateway that will handle all subsequent destination requests. The host will be validated for reachability on the specified port and must not contain any path components. The provider tenant ID serves as a fallback when the current tenant cannot be accessed during destination preparation.

      If no scheme is provided, HTTP will be used by default. The final URI will be constructed as: <normalized-host>:<port>

      The provider tenant ID is particularly useful in scenarios where the transparent proxy needs to operate in contexts where tenant information is not readily available, providing a default tenant for authentication and authorization purposes.

      Parameters:
      host - the gateway host to register (e.g., "gateway" or "...") Must not contain paths or be null
      port - the port number to use for the gateway connection. Must not be null and should be a valid port number (1-65535)
      providerTenantId - the provider tenant ID to use as a fallback when the current tenant cannot be accessed. Must not be null
      Throws:
      DestinationAccessException - if the proxy is already registered, the host contains a path, or the host is not reachable on the specified port
      IllegalArgumentException - if host, port, or providerTenantId is null
      See Also:
    • register

      public static void register(@Nonnull String host, @Nonnull String providerTenantId)
      Registers a transparent proxy gateway using the default port 80 with a provider tenant ID.

      This method registers the specified host as a transparent proxy gateway that will handle all subsequent destination requests, using the default port 80. The host will be validated for reachability and must not contain any path components. The provider tenant ID serves as a fallback when the current tenant cannot be accessed during destination preparation.

      If no scheme is provided, HTTP will be used by default. The final URI will be constructed as: <normalized-host>:80

      The provider tenant ID is particularly useful in scenarios where the transparent proxy needs to operate in contexts where tenant information is not readily available, providing a default tenant for authentication and authorization purposes.

      Parameters:
      host - the gateway host to register (e.g., "gateway.svc.cluster.local") Must not contain paths or be null
      providerTenantId - the provider tenant ID to use as a fallback when the current tenant cannot be accessed. Must not be null
      Throws:
      DestinationAccessException - if the proxy is already registered, the host contains a path, or the host is not reachable on port 80
      IllegalArgumentException - if host or providerTenantId is null
      See Also:
    • tryGetDestination

      @Nonnull public io.vavr.control.Try<Destination> tryGetDestination(@Nonnull String destinationName)
      Description copied from interface: DestinationLoader
      Retrieves a destination for the given name.

      The returned Try object will contain a DestinationNotFoundException in case the destination could not be found or a DestinationAccessException with more details in case something else went wrong.

      If the returned Try object contains no Exception it will always contain a non-null Destination value.

      Specified by:
      tryGetDestination in interface DestinationLoader
      Parameters:
      destinationName - The name of the destination to obtain.
      Returns:
      A Try object containing either the non-null Destination value or an exception.
    • tryGetDestination

      @Nonnull public io.vavr.control.Try<Destination> tryGetDestination(@Nonnull String destinationName, @Nonnull DestinationOptions options)
      Description copied from interface: DestinationLoader
      Retrieves a destination for the given name and configuration options.

      The returned Try object will contain a DestinationNotFoundException in case the destination could not be found or a DestinationAccessException with more details in case something else went wrong.

      If the returned Try object contains no Exception it will always contain a non-null Destination value.

      Specified by:
      tryGetDestination in interface DestinationLoader
      Parameters:
      destinationName - The name of the destination to obtain.
      options - Additional settings to modify the behaviour of the destination loader.
      Returns:
      A Try object containing either the non-null Destination value or an exception.