Class EnvVarDestinationLoader

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

public class EnvVarDestinationLoader extends Object implements 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 Details

    • EnvVarDestinationLoader

      public EnvVarDestinationLoader()
      Creates a new instance of EnvVarDestinationLoader reading the destinations 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 of EnvVarDestinationLoader reading variable with the provided name from the provided function.
      Parameters:
      environmentVariableAccessor - A function returning the environment variable for a given name parameter. If null is passed, this will fall back to System.getenv(String).
      destinationJsonParser - A function returning the DefaultDestination after parsing the JSON. If null is passed, a default implementation is used.
      variableName - The name of the environment variable to read. If null is passed this will fall back to destinations.
    • EnvVarDestinationLoader

      public EnvVarDestinationLoader(@Nullable Function<String,String> environmentVariableAccessor, @Nullable String variableName)
      Creates a new instance of EnvVarDestinationLoader reading variable with the provided name from the provided function.
      Parameters:
      environmentVariableAccessor - A function returning the environment variable for a given name parameter. If null is passed this will fall back to System.getenv(String).
      variableName - The name of the environment variable to read. If null is passed this will fall back to destinations.
  • 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 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.
    • tryGetAllDestinations

      @Nonnull public io.vavr.control.Try<Iterable<Destination>> tryGetAllDestinations()
      Fetches all destinations from the environment variable.
      Returns:
      A Try list of destinations.