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
ConstructorDescriptionCreates a new instance ofEnvVarDestinationLoader
reading thedestinations
variable from the system environment variables.EnvVarDestinationLoader
(Function<String, String> environmentVariableAccessor, String variableName) Creates a new instance ofEnvVarDestinationLoader
reading variable with the provided name from the provided function.EnvVarDestinationLoader
(Function<String, String> environmentVariableAccessor, Function<String, Destination> destinationJsonParser, String variableName) Creates a new instance ofEnvVarDestinationLoader
reading 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, wait
Methods inherited from interface com.sap.cloud.sdk.cloudplatform.connectivity.DestinationLoader
tryGetDestination
-
Constructor Details
-
EnvVarDestinationLoader
public EnvVarDestinationLoader()Creates a new instance ofEnvVarDestinationLoader
reading thedestinations
variable 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 ofEnvVarDestinationLoader
reading variable with the provided name from the provided function.- Parameters:
environmentVariableAccessor
- A function returning the environment variable for a given name parameter. Ifnull
is passed, this will fall back toSystem.getenv(String)
.destinationJsonParser
- A function returning theDefaultDestination
after parsing the JSON. Ifnull
is passed, a default implementation is used.variableName
- The name of the environment variable to read. Ifnull
is passed this will fall back todestinations
.
-
EnvVarDestinationLoader
public EnvVarDestinationLoader(@Nullable Function<String, String> environmentVariableAccessor, @Nullable String variableName) Creates a new instance ofEnvVarDestinationLoader
reading variable with the provided name from the provided function.- Parameters:
environmentVariableAccessor
- A function returning the environment variable for a given name parameter. Ifnull
is passed this will fall back toSystem.getenv(String)
.variableName
- The name of the environment variable to read. Ifnull
is 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:DestinationLoader
Retrieves a destination for the given name and configuration options.The returned
Try
object will contain aDestinationNotFoundException
in case the destination could not be found or aDestinationAccessException
with more details in case something else went wrong.If the returned
Try
object contains no Exception it will always contain a non-nullDestination
value.- Specified by:
tryGetDestination
in interfaceDestinationLoader
- 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-nullDestination
value or an exception.
-
tryGetAllDestinations
Fetches all destinations from the environment variable.- Returns:
- A Try list of destinations.
-