Class TenantAccessor
java.lang.Object
com.sap.cloud.sdk.cloudplatform.tenant.TenantAccessor
Accessor for retrieving the current
Tenant
.-
Method Summary
Modifier and TypeMethodDescriptionstatic void
executeWithFallbackTenant
(Supplier<Tenant> fallbackTenant, Executable executable) Execute the givenExecutable
, using the given tenant as fallback if there is no other tenant available.static <T> T
executeWithFallbackTenant
(Supplier<Tenant> fallbackTenant, Callable<T> callable) Execute the givenCallable
, using the given tenant as fallback if there is no other tenant available.static void
executeWithTenant
(Tenant tenant, Executable executable) Execute the givenExecutable
on behalf of a given tenant.static <T> T
executeWithTenant
(Tenant tenant, Callable<T> callable) Execute the givenCallable
on behalf of a given tenant.static Tenant
Returns the currentTenant
.Global fallbackTenant
.static TenantFacade
Returns theTenantFacade
instance.static void
setFallbackTenant
(Supplier<Tenant> fallbackTenant) Global fallbackTenant
.static void
setTenantFacade
(TenantFacade tenantFacade) Replaces the defaultTenantFacade
instance.static io.vavr.control.Try<Tenant>
static io.vavr.control.Try<TenantFacade>
Returns aTry
of theTenantFacade
instance.
-
Method Details
-
getTenantFacade
Returns theTenantFacade
instance.- Returns:
- The
TenantFacade
instance, ornull
.
-
tryGetTenantFacade
Returns aTry
of theTenantFacade
instance.- Returns:
- A
Try
of theTenantFacade
instance.
-
setTenantFacade
Replaces the defaultTenantFacade
instance.- Parameters:
tenantFacade
- An instance ofTenantFacade
. Usenull
to reset the facade.
-
getCurrentTenant
Returns the currentTenant
.- Returns:
- The current
Tenant
. - Throws:
TenantAccessException
- If there is an issue while accessing theTenant
.
-
tryGetCurrentTenant
Returns aTry
of the currentTenant
, or, if theTry
is a failure, the global fallback.On SAP Business Technology Platform, the availability of a tenant is defined as follows:
Tenant available Tenant not available SAP Business Technology Platform Cloud Foundry A request is present with an "Authorization" header that contains a valid JWT bearer with field "app_tid", "zid", or "zone_uuid" (legacy).
As a fallback a JWT will be retrieved from a bound XSUAA instance.A request is not available, no "Authorization" header is present in the current request, the JWT bearer does not hold a field "app_tid", "zid", or "zone_uuid" (legacy), or there is no XSUAA service bound to this application. - Returns:
- A
Try
of the currentTenant
.
-
executeWithTenant
@Nullable public static <T> T executeWithTenant(@Nonnull Tenant tenant, @Nonnull Callable<T> callable) throws ThreadContextExecutionException Execute the givenCallable
on behalf of a given tenant.- Type Parameters:
T
- The type of the callable.- Parameters:
tenant
- The tenant to execute on behalf of.callable
- The callable to execute.- Returns:
- The value computed by the callable.
- Throws:
ThreadContextExecutionException
- If there is an issue while running the code on behalf of the tenant.
-
executeWithTenant
public static void executeWithTenant(@Nonnull Tenant tenant, @Nonnull Executable executable) throws ThreadContextExecutionException Execute the givenExecutable
on behalf of a given tenant.- Parameters:
tenant
- The tenant to execute on behalf of.executable
- The operation to execute.- Throws:
ThreadContextExecutionException
- If there is an issue while running the code on behalf of the tenant.
-
executeWithFallbackTenant
@Nullable public static <T> T executeWithFallbackTenant(@Nonnull Supplier<Tenant> fallbackTenant, @Nonnull Callable<T> callable) throws ThreadContextExecutionException Execute the givenCallable
, using the given tenant as fallback if there is no other tenant available.- Type Parameters:
T
- The type of the callable.- Parameters:
fallbackTenant
- The tenant to fall back to.callable
- The callable to execute.- Returns:
- The value computed by the callable.
- Throws:
ThreadContextExecutionException
- If there is an issue while running the code on behalf of the tenant.
-
executeWithFallbackTenant
public static void executeWithFallbackTenant(@Nonnull Supplier<Tenant> fallbackTenant, @Nonnull Executable executable) throws ThreadContextExecutionException Execute the givenExecutable
, using the given tenant as fallback if there is no other tenant available.- Parameters:
fallbackTenant
- The tenant to fall back to.executable
- The operation to execute.- Throws:
ThreadContextExecutionException
- If there is an issue while running the code on behalf of the tenant.
-
getFallbackTenant
Global fallbackTenant
. By default, no fallback is used, i.e., the fallback isnull
. A global fallback can be useful to ensure a safe fallback or to ease testing with a mocked tenant. -
setFallbackTenant
Global fallbackTenant
. By default, no fallback is used, i.e., the fallback isnull
. A global fallback can be useful to ensure a safe fallback or to ease testing with a mocked tenant.
-