Class EnvVarDestinationLoader
java.lang.Object
com.sap.cloud.sdk.cloudplatform.connectivity.EnvVarDestinationLoader
- All Implemented Interfaces:
DestinationLoader
DestinationLoader implementation reading the destination from an environment variable.
The environment variable is expected to be a JSON array of JSON object containing a field called name. All
other fields of the JSON object will be converted to String and put into the created Destination
object.
Valid example:
destinations='[{"name"="destinationName", "url"="www.sap.de"}, {"name"="destinationName2", "url"="www.sap.com"}]'
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance ofEnvVarDestinationLoaderreading thedestinationsvariable from the system environment variables.EnvVarDestinationLoader(Function<String, String> environmentVariableAccessor, String variableName) Creates a new instance ofEnvVarDestinationLoaderreading variable with the provided name from the provided function.EnvVarDestinationLoader(Function<String, String> environmentVariableAccessor, Function<String, Destination> destinationJsonParser, String variableName) Creates a new instance ofEnvVarDestinationLoaderreading variable with the provided name from the provided function. -
Method Summary
Modifier and TypeMethodDescriptionio.vavr.control.Try<Iterable<Destination>>Fetches all destinations from the environment variable.io.vavr.control.Try<Destination>tryGetDestination(String destinationName, DestinationOptions options) Retrieves a destination for the given name and configuration options.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.sap.cloud.sdk.cloudplatform.connectivity.DestinationLoader
tryGetDestination
-
Constructor Details
-
EnvVarDestinationLoader
public EnvVarDestinationLoader()Creates a new instance ofEnvVarDestinationLoaderreading thedestinationsvariable from the system environment variables. -
EnvVarDestinationLoader
public EnvVarDestinationLoader(@Nullable Function<String, String> environmentVariableAccessor, @Nullable Function<String, Destination> destinationJsonParser, @Nullable String variableName) Creates a new instance ofEnvVarDestinationLoaderreading variable with the provided name from the provided function.- Parameters:
environmentVariableAccessor- A function returning the environment variable for a given name parameter. Ifnullis passed, this will fall back toSystem.getenv(String).destinationJsonParser- A function returning theDefaultDestinationafter parsing the JSON. Ifnullis passed, a default implementation is used.variableName- The name of the environment variable to read. Ifnullis passed this will fall back todestinations.
-
EnvVarDestinationLoader
public EnvVarDestinationLoader(@Nullable Function<String, String> environmentVariableAccessor, @Nullable String variableName) Creates a new instance ofEnvVarDestinationLoaderreading variable with the provided name from the provided function.- Parameters:
environmentVariableAccessor- A function returning the environment variable for a given name parameter. Ifnullis passed this will fall back toSystem.getenv(String).variableName- The name of the environment variable to read. Ifnullis passed this will fall back todestinations.
-
-
Method Details
-
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.
-
tryGetAllDestinations
Fetches all destinations from the environment variable.- Returns:
- A Try list of destinations.
-