2
votes

I am following the tutorial below to use the SAP Cloud SDK in CAP Java project to invoke OData API of S/4HANA on-premise system. There is no much difference to use VDM in CAP Java project compared to Cloud SDK Spring archetype project.

https://developers.sap.com/tutorials/cloudsdk-integrate-cap.html

Here is the some code snippet in CAP Java Project.

HttpDestination httpDestination = DestinationAccessor.getDestination("s4x011").asHttp();

        List<BusinessPartner> businesspartners = null;
        try {
            businesspartners = new DefaultBusinessPartnerService().getAllBusinessPartner().execute(httpDestination);
        } catch (ODataException e) {
            e.printStackTrace();
        }

The problem I have is to provide destination "s4x011" in Business Application Studio to do local testing. As it is going to connect on-premise OData API via cloud connector, I need to provide destination name which is defined in SAP Cloud Foundry environment.

There is a solution that is described in the following blog. I am required to provide "destinations" in .env1 file. For example,

destinations=[{"name":"s4x011", "proxyHost":"http://127.0.0.1", "proxyPort":"8887", "url":"http://s4x011.dest"}]

https://blogs.sap.com/2020/06/02/how-to-reach-on-premise-odata-from-the-business-application-studio/

The destination "s4x011" is defined in sap cloud platform. This is the blog to define destinations in SAP Cloud Platform. https://help.sap.com/viewer/9d1db9835307451daa8c930fbd9ab264/Cloud/en-US/e72930c96b664e3ea4ce5288eb84075f.html

Here is my destination "s4x011" configration in subaccount level.

enter image description here

After everthing is ready, I started up my application with mvn command. It still could not find the destination "s4x011".

mvn sping-boot:run

This is the error stack.

2020-10-29 09:38:38.586  INFO 1229 --- [nio-8080-exec-3] c.s.c.a.o.v4.processors.CdsProcessor     : Exception marked the ChangeSet 4 as cancelled: Failed to get destination with name 's4x011'. (service 'CatalogService', event 'READ', entity 'CatalogService.CapBusinessPartner')
2020-10-29 09:38:38.596 ERROR 1229 --- [nio-8080-exec-3] c.s.c.a.o.v4.processors.CdsProcessor     : Failed to get destination with name 's4x011'. (service 'CatalogService', event 'READ', entity 'CatalogService.CapBusinessPartner')

com.sap.cds.services.impl.ContextualizedServiceException: Failed to get destination with name 's4x011'. (service 'CatalogService', event 'READ', entity 'CatalogService.CapBusinessPartner')
        at com.sap.cds.services.impl.ServiceImpl.dispatch(ServiceImpl.java:203) ~[cds-services-impl-1.8.1.jar:na]
        at com.sap.cds.services.impl.ServiceImpl.emit(ServiceImpl.java:131) ~[cds-services-impl-1.8.1.jar:na]
        at com.sap.cds.services.ServiceDelegator.emit(ServiceDelegator.java:34) ~[cds-services-api-1.8.1.jar:na]
        at com.sap.cds.services.impl.cds.CdsServiceBaseImpl.run(CdsServiceBaseImpl.java:51) ~[cds-services-impl-1.8.1.jar:na]
        at com.sap.cds.adapter.odata.v4.processors.CdsProcessor.get(CdsProcessor.java:202) ~[cds-adapter-odata-v4-1.8.1.jar:na]
        at com.sap.cds.adapter.odata.v4.processors.CdsProcessor.delegateRequest(CdsProcessor.java:145) ~[cds-adapter-odata-v4-1.8.1.jar:na]
        at com.sap.cds.adapter.odata.v4.processors.CdsProcessor.lambda$processRequest$1(CdsProcessor.java:106) ~[cds-adapter-odata-v4-1.8.1.jar:na]
        at com.sap.cds.services.impl.runtime.RequestContextRunnerImpl.lambda$run$0(RequestContextRunnerImpl.java:113) ~[cds-services-impl-1.8.1.jar:na]
        at com.sap.cds.services.impl.runtime.RequestContextRunnerImpl.run(RequestContextRunnerImpl.java:138) ~[cds-services-impl-1.8.1.jar:na]
        at com.sap.cds.services.impl.runtime.RequestContextRunnerImpl.run(RequestContextRunnerImpl.java:112) ~[cds-services-impl-1.8.1.jar:na]
        at com.sap.cds.adapter.odata.v4.processors.CdsProcessor.processRequest(CdsProcessor.java:102) ~[cds-adapter-odata-v4-1.8.1.jar:na]
        at com.sap.cds.adapter.odata.v4.processors.CdsProcessor.lambda$processRequest$0(CdsProcessor.java:93) ~[cds-adapter-odata-v4-1.8.1.jar:na]
        at com.sap.cds.services.impl.runtime.ChangeSetContextRunnerImpl.run(ChangeSetContextRunnerImpl.java:22) ~[cds-services-impl-1.8.1.jar:na]
        at com.sap.cds.adapter.odata.v4.processors.CdsProcessor.processRequest(CdsProcessor.java:92) ~[cds-adapter-odata-v4-1.8.1.jar:na]
        at com.sap.cds.adapter.odata.v4.processors.ODataProcessor.processRequest(ODataProcessor.java:327) ~[cds-adapter-odata-v4-1.8.1.jar:na]
        at com.sap.cds.adapter.odata.v4.processors.ODataProcessor.processCollectionEntityRequest(ODataProcessor.java:135) ~[cds-adapter-odata-v4-1.8.1.jar:na]
        at com.sap.cds.adapter.odata.v4.processors.OlingoProcessor.readEntityCollection(OlingoProcessor.java:94) ~[cds-adapter-odata-v4-1.8.1.jar:na]
        at org.apache.olingo.server.core.ODataDispatcher.handleEntityCollectionDispatching(ODataDispatcher.java:539) ~[odata-v4-lib-1.8.1.jar:na]
        at org.apache.olingo.server.core.ODataDispatcher.handleEntityDispatching(ODataDispatcher.java:521) ~[odata-v4-lib-1.8.1.jar:na]
        at org.apache.olingo.server.core.ODataDispatcher.handleResourceDispatching(ODataDispatcher.java:153) ~[odata-v4-lib-1.8.1.jar:na]
        at org.apache.olingo.server.core.ODataDispatcher.dispatch(ODataDispatcher.java:119) ~[odata-v4-lib-1.8.1.jar:na]
        at org.apache.olingo.server.core.ODataHandlerImpl.processInternal(ODataHandlerImpl.java:170) ~[odata-v4-lib-1.8.1.jar:na]
        at org.apache.olingo.server.core.ODataHandlerImpl.process(ODataHandlerImpl.java:86) ~[odata-v4-lib-1.8.1.jar:na]
        at org.apache.olingo.server.core.ODataHttpHandlerImpl.process(ODataHttpHandlerImpl.java:75) ~[odata-v4-lib-1.8.1.jar:na]
        at org.apache.olingo.server.core.ODataHttpHandlerImpl.process(ODataHttpHandlerImpl.java:89) ~[odata-v4-lib-1.8.1.jar:na]
        at com.sap.cds.adapter.odata.v4.CdsODataV4Servlet.service(CdsODataV4Servlet.java:121) ~[cds-adapter-odata-v4-1.8.1.jar:na]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.37.jar:4.0.FR]
        at com.sap.cds.framework.spring.config.adapter.ServletAdapterRestController.handleRequest(ServletAdapterRestController.java:30) ~[cds-framework-spring-boot-1.8.1.jar:na]
        at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:52) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:626) ~[tomcat-embed-core-9.0.37.jar:4.0.FR]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.37.jar:4.0.FR]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:126) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:81) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:105) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:149) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:149) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:110) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:80) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183) ~[spring-security-web-5.4.0.jar:5.4.0]
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:747) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
        at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException: Failed to get destination with name 's4x011'.
        at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor.lambda$getDestination$1(DestinationAccessor.java:120) ~[cloudplatform-connectivity-3.30.0.jar:na]
        at io.vavr.control.Try.getOrElseThrow(Try.java:748) ~[vavr-0.10.2.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor.getDestination(DestinationAccessor.java:116) ~[cloudplatform-connectivity-3.30.0.jar:na]
        at com.bosch.businessservice.handlers.CatalogServiceHandler.onRead(CatalogServiceHandler.java:48) ~[classes/:na]
        at com.sap.cds.services.impl.handlerregistry.HandlerRegistryTools$DescribedHandler.process(HandlerRegistryTools.java:160) ~[cds-services-impl-1.8.1.jar:na]
        at com.sap.cds.services.impl.ServiceImpl.dispatch(ServiceImpl.java:181) ~[cds-services-impl-1.8.1.jar:na]
        ... 107 common frames omitted
Caused by: com.sap.cloud.sdk.cloudplatform.cache.CacheRuntimeException: com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException: Failed to get destination.
        at com.sap.cloud.sdk.cloudplatform.cache.CacheUtil.lambda$wrapCallableAsFunction$0(CacheUtil.java:45) ~[caching-3.30.0.jar:na]
        at com.github.benmanes.caffeine.cache.BoundedLocalCache.lambda$doComputeIfAbsent$14(BoundedLocalCache.java:2344) ~[caffeine-2.8.5.jar:na]
        at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1908) ~[na:na]
        at com.github.benmanes.caffeine.cache.BoundedLocalCache.doComputeIfAbsent(BoundedLocalCache.java:2342) ~[caffeine-2.8.5.jar:na]
        at com.github.benmanes.caffeine.cache.BoundedLocalCache.computeIfAbsent(BoundedLocalCache.java:2325) ~[caffeine-2.8.5.jar:na]
        at com.github.benmanes.caffeine.cache.LocalCache.computeIfAbsent(LocalCache.java:108) ~[caffeine-2.8.5.jar:na]
        at com.github.benmanes.caffeine.cache.LocalManualCache.get(LocalManualCache.java:62) ~[caffeine-2.8.5.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationLoader.lambda$tryGetDestination$2ec57ad6$1(ScpCfDestinationLoader.java:96) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at io.vavr.control.Try.of(Try.java:75) ~[vavr-0.10.2.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationLoader.tryGetDestination(ScpCfDestinationLoader.java:95) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationLoaderChain.tryGetDestination(DestinationLoaderChain.java:84) ~[cloudplatform-connectivity-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationLoader.tryGetDestination(DestinationLoader.java:36) ~[cloudplatform-connectivity-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor.tryGetDestination(DestinationAccessor.java:138) ~[cloudplatform-connectivity-3.30.0.jar:na]
        ... 111 common frames omitted
Caused by: com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException: Failed to get destination.
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationServiceAdapter.getDestinationConfigurationAsJson(ScpCfDestinationServiceAdapter.java:202) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationLoader.getDestinationConfigurationFromDestinationService(ScpCfDestinationLoader.java:214) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationLoader.getDestinationConfigurationByTenant(ScpCfDestinationLoader.java:158) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationLoader.getDestinationConfigurationByRetrievalStrategy(ScpCfDestinationLoader.java:131) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationLoader.loadAndParseDestination(ScpCfDestinationLoader.java:108) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationLoader.lambda$null$0(ScpCfDestinationLoader.java:98) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.cache.CacheUtil.lambda$wrapCallableAsFunction$0(CacheUtil.java:42) ~[caching-3.30.0.jar:na]
        ... 123 common frames omitted
Caused by: com.sap.cloud.sdk.cloudplatform.resilience.ResilienceRuntimeException: com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException: com.sap.cloud.sdk.cloudplatform.security.exception.TokenRequestFailedException: com.sap.cloud.sdk.cloudplatform.exception.CloudPlatformException: Environment variable 'VCAP_SERVICES' is not defined.
        at com.sap.cloud.sdk.frameworks.resilience4j.Resilience4jDecorationStrategy.lambda$null$2(Resilience4jDecorationStrategy.java:181) ~[resilience4j-3.30.0.jar:na]
        at io.vavr.control.Try.onFailure(Try.java:659) ~[vavr-0.10.2.jar:na]
        at com.sap.cloud.sdk.frameworks.resilience4j.Resilience4jDecorationStrategy.lambda$decorateCallable$3(Resilience4jDecorationStrategy.java:180) ~[resilience4j-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.resilience.ResilienceDecorationStrategy.executeCallable(ResilienceDecorationStrategy.java:210) ~[resilience-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.resilience.ResilienceDecorator.executeCallable(ResilienceDecorator.java:197) ~[resilience-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationServiceAdapter.getDestinationConfigurationAsJson(ScpCfDestinationServiceAdapter.java:189) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        ... 129 common frames omitted
Caused by: com.sap.cloud.sdk.cloudplatform.thread.exception.ThreadContextExecutionException: com.sap.cloud.sdk.cloudplatform.security.exception.TokenRequestFailedException: com.sap.cloud.sdk.cloudplatform.exception.CloudPlatformException: Environment variable 'VCAP_SERVICES' is not defined.
        at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.execute(AbstractThreadContextExecutor.java:299) ~[cloudplatform-core-3.30.0.jar:na]
        at com.sap.cloud.sdk.frameworks.resilience4j.DefaultThreadContextProvider.lambda$decorateCallable$0(DefaultThreadContextProvider.java:26) ~[resilience4j-3.30.0.jar:na]
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
        ... 1 common frames omitted
Caused by: com.sap.cloud.sdk.cloudplatform.security.exception.TokenRequestFailedException: com.sap.cloud.sdk.cloudplatform.exception.CloudPlatformException: Environment variable 'VCAP_SERVICES' is not defined.
        at com.sap.cloud.sdk.cloudplatform.connectivity.ServiceCredentialsRetriever.getClientCredentials(ServiceCredentialsRetriever.java:35) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationServiceAdapter.getAccessTokenForDestinationService(ScpCfDestinationServiceAdapter.java:212) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationServiceAdapter.lambda$getDestinationConfigurationAsJson$0(ScpCfDestinationServiceAdapter.java:191) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.frameworks.resilience4j.Resilience4jDecorationStrategy.lambda$decorateCallable$1(Resilience4jDecorationStrategy.java:160) ~[resilience4j-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.thread.ThreadContextCallable.call(ThreadContextCallable.java:225) ~[cloudplatform-core-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.execute(AbstractThreadContextExecutor.java:293) ~[cloudplatform-core-3.30.0.jar:na]
        ... 5 common frames omitted
Caused by: com.sap.cloud.sdk.cloudplatform.exception.CloudPlatformException: Environment variable 'VCAP_SERVICES' is not defined.
        at com.sap.cloud.sdk.cloudplatform.ScpCfCloudPlatform.lambda$parseVcapServices$1(ScpCfCloudPlatform.java:174) ~[cloudplatform-core-scp-cf-3.30.0.jar:na]
        at io.vavr.control.Option.getOrElseThrow(Option.java:351) ~[vavr-0.10.2.jar:na]
        at com.sap.cloud.sdk.cloudplatform.ScpCfCloudPlatform.parseVcapServices(ScpCfCloudPlatform.java:173) ~[cloudplatform-core-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.ScpCfCloudPlatform.getVcapServices(ScpCfCloudPlatform.java:210) ~[cloudplatform-core-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.ScpCfCloudPlatform.getServiceCredentials(ScpCfCloudPlatform.java:363) ~[cloudplatform-core-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.ScpCfCloudPlatform.getServiceCredentials(ScpCfCloudPlatform.java:332) ~[cloudplatform-core-scp-cf-3.30.0.jar:na]
        at com.sap.cloud.sdk.cloudplatform.connectivity.ServiceCredentialsRetriever.getClientCredentials(ServiceCredentialsRetriever.java:32) ~[cloudplatform-connectivity-scp-cf-3.30.0.jar:na]
        ... 10 common frames omitted

=============update==============

I created an default-env.json in root folder of CAP Java project with destination. Then I could not start my application.

{
  "destinations": [
    {
      "name": "s4x011",
      "proxyHost": "http://127.0.0.1",
      "proxyPort": "8887",
      "url": "http://s4x011.dest"
    }
  ]
}

Then I added "VCAP_SERVICES" in the default-env.json. The application can be started but the destination was still not found.

{
  "destinations": [
    {
      "name": "s4x011",
      "proxyHost": "http://127.0.0.1",
      "proxyPort": "8887",
      "url": "http://s4x011.dest"
    }
  ],
  "VCAP_SERVICES": {
      
  }
}
   
2
Maybe there's a parsing problem. What does the following call return for you..? new EnvVarDestinationLoader().tryGetDestination("s4x011").get();Alexander Dümont
I tried with the code along with destinations defined in default-env.json. The application still could not find the destinations. The error now is "Could not find environment variable for name 'destinations'".Jerry Zhang

2 Answers

3
votes

We have enhanced our documentation on configuring destination retrieval when deploying your app to localhost on your own machine. The same configuration procedure can be applied when launching your app on localhost from within the SAP Business Application Studio as the technical circumstances are comparable.

Check out the latest documentation, it should outline the necessary steps.

0
votes

As far as I know, there is no connection between remote Destination Service of SCP Cloud Foundry and your local application runtime in BAS. This is why you need to specify the destinations locally in an environment variable.

On your local PC you would set the environment variable destinations with command line. But on BAS this is not working, here you need to specify / reuse the file default-env.json. It would look something like this:

{
  "destinations": [
    {
      "name": "s4x011",
      "proxyHost": "http://127.0.0.1",
      "proxyPort": "8887",
      "url": "http://s4x011.dest"
    }
  ]
}

I'm not exactly sure where .env1 of related blog post is coming from. For colleagues the default-env.json always seemed to work just fine. I hope it does for you as well.