我正在 SAP SCP Neo 上开发一个 Java 应用程序,它使用 S/4 SDK 进行平台抽象。我正在努力创建一个租户感知的后台任务。这意味着,当使用 com.sap.cloud.sdk.cloudplatform.tenant.TenantAccessor 或 DestinationAccessor 等 S/4SDK 平台抽象方法来访问租户信息或检索目的地时,这些方法应返回租户特定信息,就像可以从典型的租户特定 Web 请求中调用它们。
在调用 S/4SDK 访问器方法时,我用一个可调用对象包装它们并使用 RequestContextExecutor 执行它。这很好用,但由于我看不到任何提供租户的方法,我不清楚如何解决我的问题。我看到在 S/4 SDK 中使用了默认侦听器,因此我假设它在提供程序帐户的上下文中运行。请在下面查找示例以检索目的地。
Destination getDestination(String destinationName) {
// Request Context is present when action is triggered by a web request
if (RequestContextAccessor.getCurrentRequest().isPresent()){
return DestinationAccessor.getDestination(destinatioName);
}
// Use RequestContextExecutor if we are called from a background task
Callable<Destination> callable = new Callable<Destination>() {
@Override
public Destination call() {
return DestinationAccessor.getDestination(destinatioName);
}
};
// TODO this defaults the contexts to the provider account.
return new RequestContextExecutor().execute(callable);
}
动机:
- 我们喜欢编写一些逻辑,如果它是由针对 Java 应用程序的 Web 请求调用或由后台 Java 任务触发的,它应该独立工作。