Creating ErpConfigContext threw exception

吃可爱长大的小学妹 提交于 2019-12-01 18:40:13

问题


I am trying to use the S/4HANA SDK to call the CompanyCode OData VDM service but if I do this in the Cloud Foundry environment I'm getting the attached error. I have been using the SDK before but this did not happened. Can you please help me here?

Code:

public List<CompanyCode> findAll() {
    try {
        return compCodeService.getAllCompanyCode().execute(erp())
                .stream()
                .map(this::toCompCode)
                .collect(Collectors.toList());
    } catch (ODataException e) {
        throw SapException.create(e.getMessage());
    }
}

private ErpConfigContext erp(){
    return new ErpConfigContext(REPLICATE_WORKFORCE);
}

 public static final String REPLICATE_WORKFORCE = "REPLICATE_WORKFORCE";

Error:

 [Request processing failed; nested exception is com.sap.cloud.sdk.cloudplatform.tenant.exception.TenantAccessException: Failed to get current tenant: no RequestContext available. Have you correctly configured a RequestContextServletFilter or have you wrapped your logic in a RequestContextExecutor when executing background tasks that are not triggered by a request?] with root cause
    com.sap.cloud.sdk.cloudplatform.tenant.exception.TenantAccessException: Failed to get current tenant: no RequestContext available. Have you correctly configured a RequestContextServletFilter or have you wrapped your logic in a RequestContextExecutor when executing background tasks that are not triggered by a request?
   at com.sap.cloud.sdk.cloudplatform.tenant.AbstractTenantFacade.getCurrentTenantIfAvailable(AbstractTenantFacade.java:85) ~[tenant-2.5.0.jar!/:na]

   at com.sap.cloud.sdk.cloudplatform.tenant.TenantAccessor.getCurrentTenantIfAvailable(TenantAccessor.java:109) ~[tenant-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationFacade.getCacheKey(ScpCfDestinationFacade.java:132) ~[connectivity-scp-cf-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationFacade.getGenericDestinationsByName(ScpCfDestinationFacade.java:178) ~[connectivity-scp-cf-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.cloudplatform.connectivity.AbstractDestinationFacade.getGenericDestination(AbstractDestinationFacade.java:173) ~[com.sap.cloud.s4hana.cloudplatform-connectivity-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor.getGenericDestination(DestinationAccessor.java:176) ~[com.sap.cloud.s4hana.cloudplatform-connectivity-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.s4hana.connectivity.ErpConfigContext.(ErpConfigContext.java:218) ~[com.sap.cloud.s4hana-connectivity-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.s4hana.connectivity.ErpConfigContext.(ErpConfigContext.java:367) ~[com.sap.cloud.s4hana-connectivity-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.s4hana.connectivity.ErpConfigContext.(ErpConfigContext.java:442) ~[com.sap.cloud.s4hana-connectivity-2.5.0.jar!/:na]
   at com.sap.csc.employeecreationbe.repository.SdkCompanyCodeRepository.erp(SdkCompanyCodeRepository.java:74) ~[classes/:na]
   at com.sap.csc.employeecreationbe.repository.SdkCompanyCodeRepository.findAll(SdkCompanyCodeRepository.java:64) ~[classes/:na]
   at com.sap.csc.employeecreationbe.repository.SdkCompanyCodeRepository$$FastClassBySpringCGLIB$$f89ad4b4.invoke() ~[classes/:na]
   at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at com.sap.csc.employeecreationbe.repository.SdkCompanyCodeRepository$$EnhancerBySpringCGLIB$$4dd15cde.findAll() ~[classes/:na]
   at com.sap.csc.employeecreationbe.controller.EmployeeController.companyCodes(EmployeeController.java:216) ~[classes/:na]
   at com.sap.csc.employeecreationbe.controller.EmployeeController$$FastClassBySpringCGLIB$$543220b2.invoke() ~[classes/:na]
   at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE] and so on

回答1:


Can you try to make sure that the RequestContextServletFilter is picked up in your application? The RequestContextServletFilter uses the @WebFilter annotation by default.

Example for Spring Boot:

@SpringBootApplication
@ServletComponentScan( "com.sap.cloud.sdk" )
public class Application extends SpringBootServletInitializer
{
    ...
}

See also: https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/web/servlet/ServletComponentScan.html

EDIT: Note that when running your code in a background job (not triggered by a request), you have to wrap your code with RequestContextExecutor::execute.



来源:https://stackoverflow.com/questions/53004203/creating-erpconfigcontext-threw-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!