Class TenantAccessor
java.lang.Object
com.sap.cloud.sdk.cloudplatform.tenant.TenantAccessor
Accessor for retrieving the current
Tenant.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidexecuteWithFallbackTenant(Supplier<Tenant> fallbackTenant, Executable executable) Execute the givenExecutable, using the given tenant as fallback if there is no other tenant available.static <T> TexecuteWithFallbackTenant(Supplier<Tenant> fallbackTenant, Callable<T> callable) Execute the givenCallable, using the given tenant as fallback if there is no other tenant available.static voidexecuteWithTenant(Tenant tenant, Executable executable) Execute the givenExecutableon behalf of a given tenant.static <T> TexecuteWithTenant(Tenant tenant, Callable<T> callable) Execute the givenCallableon behalf of a given tenant.static TenantReturns the currentTenant.Global fallbackTenant.static TenantFacadeReturns theTenantFacadeinstance.static voidsetFallbackTenant(Supplier<Tenant> fallbackTenant) Global fallbackTenant.static voidsetTenantFacade(TenantFacade tenantFacade) Replaces the defaultTenantFacadeinstance.static io.vavr.control.Try<Tenant>static io.vavr.control.Try<TenantFacade>Returns aTryof theTenantFacadeinstance.
-
Method Details
-
getTenantFacade
Returns theTenantFacadeinstance.- Returns:
- The
TenantFacadeinstance, ornull.
-
tryGetTenantFacade
Returns aTryof theTenantFacadeinstance.- Returns:
- A
Tryof theTenantFacadeinstance.
-
setTenantFacade
Replaces the defaultTenantFacadeinstance.- Parameters:
tenantFacade- An instance ofTenantFacade. Usenullto reset the facade.
-
getCurrentTenant
Returns the currentTenant.- Returns:
- The current
Tenant. - Throws:
TenantAccessException- If there is an issue while accessing theTenant.
-
tryGetCurrentTenant
Returns aTryof the currentTenant, or, if theTryis 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
Tryof the currentTenant.
-
executeWithTenant
@Nullable public static <T> T executeWithTenant(@Nonnull Tenant tenant, @Nonnull Callable<T> callable) throws ThreadContextExecutionException Execute the givenCallableon 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 givenExecutableon 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.
-