Class TransparentProxy
- All Implemented Interfaces:
DestinationLoader
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidRegisters a transparent proxy gateway using the default port 80.static voidRegisters a transparent proxy gateway with a specified port.static voidRegisters a transparent proxy gateway with a specified port and provider tenant ID.static voidRegisters a transparent proxy gateway using the default port 80 with a provider tenant ID.io.vavr.control.Try<Destination>tryGetDestination(String destinationName) Retrieves a destination for the given name.io.vavr.control.Try<Destination>tryGetDestination(String destinationName, DestinationOptions options) Retrieves a destination for the given name and configuration options.
-
Constructor Details
-
TransparentProxy
public TransparentProxy()
-
-
Method Details
-
register
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 80IllegalArgumentException- if host is null- See Also:
-
register
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 nullport- 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 portIllegalArgumentException- 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 nullport- 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 portIllegalArgumentException- if host, port, or providerTenantId is null- See Also:
-
register
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>:80The 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 nullproviderTenantId- 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 80IllegalArgumentException- if host or providerTenantId is null- See Also:
-
tryGetDestination
Description copied from interface:DestinationLoaderRetrieves a destination for the given name.The returned
Tryobject will contain aDestinationNotFoundExceptionin case the destination could not be found or aDestinationAccessExceptionwith more details in case something else went wrong.If the returned
Tryobject contains no Exception it will always contain a non-nullDestinationvalue.- Specified by:
tryGetDestinationin interfaceDestinationLoader- Parameters:
destinationName- The name of the destination to obtain.- Returns:
- A
Tryobject containing either the non-nullDestinationvalue or an exception.
-
tryGetDestination
@Nonnull public io.vavr.control.Try<Destination> tryGetDestination(@Nonnull String destinationName, @Nonnull DestinationOptions options) Description copied from interface:DestinationLoaderRetrieves a destination for the given name and configuration options.The returned
Tryobject will contain aDestinationNotFoundExceptionin case the destination could not be found or aDestinationAccessExceptionwith more details in case something else went wrong.If the returned
Tryobject contains no Exception it will always contain a non-nullDestinationvalue.- Specified by:
tryGetDestinationin interfaceDestinationLoader- Parameters:
destinationName- The name of the destination to obtain.options- Additional settings to modify the behaviour of the destination loader.- Returns:
- A
Tryobject containing either the non-nullDestinationvalue or an exception.
-