Jerry Zhang
Jerry Zhang

Reputation: 181

Define SCP destination for S4HANA BAPI call with Cloud SDK

I am looking for a way to call S4HANA on-premise BAPI locally and on SAP Cloud Platform with Cloud SDK. The problem is how to define RFC destinations just like HTTP ones.

I also encountered JCo class not found exception and could not find a suitable workaround.

Locally

In HTTP destination, I can provide environment variables like the following:

set destinations=[{name: "destName", url: "URL", username: "username", password: "password"}]

But it is not clear how to define RFC destination, which properties are mandatory like jco properties.

SCP Cloud Foundry

I created a RFC destination on SAP Cloud Platform. enter image description here But I could not find a way to decorate this destination to involve additional properties in Cloud SDK just like HTTP destination.

Destination destination = DestinationAccessor.getDestination(destName);
destination.asHttp().decorate(DefaultErpHttpDestination::new);  

Please note that when I do bapi call, the RfcDestination is not acceptable only type Destination is required. RfcDestination is not an implementation class of interface Destination.

enter image description here

JCO Class Not found exception

java.lang.NoClassDefFoundError: com/sap/conn/jco/JCo

There is a known issue when using SAP Java Build Pack with Spring boot. I added the jar file sapjco3.jar manually to project classpath. But it still did not work.

https://answers.sap.com/questions/12935437/call-op-bapi-using-cloud-sdk.html

Update

JCO Class Not Found exception at run time

  1. You are right. I deployed app on SCP and then call rest APIs I provided to invoke BAPI of S4HANA On-premise system. Then I got this exception at run time.
  2. I am using a Spring Boot application.
  3. The Spring boot project is generated by SAP Cloud SDK spring archetype.
  4. Please see error stack trace below.
  5. Right click my project -> build path -> Configure build path -> Choose libraries tab -> add external jars
  6. I deployed my app as Jar file.

Exception stack trace

2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.lambda$doFilter$1(RequestAccessorFilter.java:71)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.lambda$execute$0(AbstractThreadContextExecutor.java:317)
2020-04-09T01:55:46.220+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.thread.ThreadContextCallable.call(ThreadContextCallable.java:247)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.execute(AbstractThreadContextExecutor.java:319)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.doFilter(RequestAccessorFilter.java:71)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
2020-04-09T01:55:46.221+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:747)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at java.lang.Thread.run(Thread.java:836)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR Caused by: java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoException
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.s4hana.connectivity.rfc.BapiTransactionFactory.createJCoTransaction(BapiTransactionFactory.java:33)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.s4hana.connectivity.rfc.AbstractTransactionFactory.createTransaction(AbstractTransactionFactory.java:39)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.s4hana.connectivity.rfc.RemoteFunctionRequestExecutor.execute(RemoteFunctionRequestExecutor.java:41)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.s4hana.connectivity.rfc.BapiRequest.execute(BapiRequest.java:79)
2020-04-09T01:55:46.222+0000 [APP/PROC/WEB/0] ERR   at com.bosch.test.service.CostCenterBapiService.getCostCenters(CostCenterBapiService.java:48)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at com.bosch.test.controllers.CostCenterBapiController.getCostCenterBapi(CostCenterBapiController.java:23)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at java.lang.reflect.Method.invoke(Method.java:498)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   ... 47 more
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR Caused by: java.lang.ClassNotFoundException: com.sap.conn.jco.JCoException
2020-04-09T01:55:46.223+0000 [APP/PROC/WEB/0] ERR   at java.net.URLClassLoader.findClass(URLClassLoader.java:444)
2020-04-09T01:55:46.224+0000 [APP/PROC/WEB/0] ERR   at java.lang.ClassLoader.loadClass(ClassLoader.java:480)
2020-04-09T01:55:46.224+0000 [APP/PROC/WEB/0] ERR   at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:92)
2020-04-09T01:55:46.224+0000 [APP/PROC/WEB/0] ERR   at java.lang.ClassLoader.loadClass(ClassLoader.java:413)
2020-04-09T01:55:46.224+0000 [APP/PROC/WEB/0] ERR   ... 64 more

One thing I want to highlight is an official documentation provided by SAP says "It is not possible to use the SAP Java Connector with Spring Boot applications".

https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/3cee866c27ec4492b789b10c5d52d94b.html

SAP Java Connector with non spring boot application

I created a new project based on SAP Cloud SDK archetypes scp-cf-tomee and tried to call bapi. JCo issue is gone I think but I got a new excetion "User Information is not set" when invoking Bapi. Someone has the similar issue but seems no solution yet.

https://answers.sap.com/questions/12969692/getting-access-to-the-sap-java-connector-in-cloud.html

2020-04-09T02:25:37.146+0000 [APP/PROC/WEB/0] ERR java.lang.IllegalStateException: User information is not set.
2020-04-09T02:25:37.146+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.security.UserInfoHolder.getUserInfo(UserInfoHolder.java:48)
2020-04-09T02:25:37.146+0000 [APP/PROC/WEB/0] ERR   at com.sap.core.connectivity.jco.kotyo.cf.auth.CFTenantProvider.getCurrentTenant(CFTenantProvider.java:21)
2020-04-09T02:25:37.146+0000 [APP/PROC/WEB/0] ERR   at com.sap.conn.jco.rt.TenantContextManager.getTenantContext(TenantContextManager.java:36)
2020-04-09T02:25:37.146+0000 [APP/PROC/WEB/0] ERR   at com.sap.conn.jco.rt.DefaultDestinationManager.searchDestination(DefaultDestinationManager.java:376)
2020-04-09T02:25:37.146+0000 [APP/PROC/WEB/0] ERR   at com.sap.conn.jco.rt.DefaultDestinationManager.getDestinationInstance(DefaultDestinationManager.java:109)
2020-04-09T02:25:37.146+0000 [APP/PROC/WEB/0] ERR   at com.sap.conn.jco.JCoDestinationManager.getDestination(JCoDestinationManager.java:56)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.s4hana.connectivity.rfc.JCoTransaction.<init>(JCoTransaction.java:99)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.s4hana.connectivity.rfc.BapiTransactionFactory.createJCoTransaction(BapiTransactionFactory.java:33)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.s4hana.connectivity.rfc.AbstractTransactionFactory.createTransaction(AbstractTransactionFactory.java:39)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.s4hana.connectivity.rfc.RemoteFunctionRequestExecutor.execute(RemoteFunctionRequestExecutor.java:41)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.s4hana.connectivity.rfc.BapiRequest.execute(BapiRequest.java:79)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.bosch.bapi.service.CostCenterBapiService.getCostCenters(CostCenterBapiService.java:44)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.bosch.bapi.CostCenterBapiServlet.doGet(CostCenterBapiServlet.java:30)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.lambda$doFilter$1(RequestAccessorFilter.java:71)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.lambda$execute$0(AbstractThreadContextExecutor.java:317)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.thread.ThreadContextCallable.call(ThreadContextCallable.java:247)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.execute(AbstractThreadContextExecutor.java:319)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.doFilter(RequestAccessorFilter.java:71)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.security.servlet.HttpCachingHeaderFilter.doFilter(HttpCachingHeaderFilter.java:83)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at com.sap.cloud.sdk.cloudplatform.security.servlet.HttpSecurityHeadersFilter.doFilter(HttpSecurityHeadersFilter.java:41)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.filters.RestCsrfPreventionFilter.doFilter(RestCsrfPreventionFilter.java:125)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
2020-04-09T02:25:37.147+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.java.valves.ErrorReportValve.invoke(ErrorReportValve.java:66)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:256)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.security.TenantIdValve.invoke(TenantIdValve.java:33)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.security.UserInfoValve.invoke(UserInfoValve.java:19)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:43)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at com.sap.xs.logging.catalina.RuntimeInfoValve.invoke(RuntimeInfoValve.java:40)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:747)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:609)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
2020-04-09T02:25:37.148+0000 [APP/PROC/WEB/0] ERR   at java.lang.Thread.run(Thread.java:836)

Decorate destination

I agree with what you explained. Maybe it is not required to do it as Http destination. But I was stuck due to SAP Java Connector issue.

Local RFC Destination definition

Actually I did not know what properties are required for RFC destination. If I just use the HTTP one, I would get http status 404 and service not found exception.

Upvotes: 1

Views: 828

Answers (2)

Emdee
Emdee

Reputation: 1693

Update: Check out the latest SAP Cloud SDK documentation on BAPI calls.

Thanks for the update. Answering based on your updated information inside the original question. Again going over each individual headline.

JCO Class Not Found exception at run time

The usage of the Java Connector is only usable when using the "traditional deployment" of Spring which involves building and deploying a war file instead of a jar file.

SAP Java Connector with non spring boot application

The usage of the Java Connector requires to have a protected backend and an app router. I assume you do not use that, that is indicated by the error message User Information is not set.

Decorate destination

Answered

Local RFC Destination definition

As per my knowledge using the Java Connector from a local deployment is not foreseen. You have to deploy your app to the SAP Cloud Platform for this purpose. Concerning the question which properties to set on the RFC destination, you can refer to the Javadoc of the Java class DestinationDataProvider which you can extract from the JCo archive after downloading it from https://support.sap.com/jco

Upvotes: 2

Emdee
Emdee

Reputation: 1693

Thanks for raising this question here. I can identify different aspects in your question, hence touching upon them individually in the following.

JCO Class Not found exception

Please provide more information on the following questions:

  • I understand that you receive a java.lang.NoClassDefFoundError: com/sap/conn/jco/JCo at runtime after app deployment to the SCP. Is my understanding correct?
  • I understand that you use a Spring Boot application, correct?
  • Have you used the SAP Cloud SDK archetype?
  • Please attach the application log here for further reference.
  • Can you also elaborate on how exactly you added sapjco3.jar to the project classpath?
  • Do you deploy you app as jar or as war?

Create RFC destination via environment variable

I understand that you struggle understanding how to specify the RFC destination in your environment variable. May I ask what you already tried respectively which concrete problems (error messages, etc.) you are facing?

RFC Destination cannot be decorated to involve additional properties

You are pointing out correctly that the SAP Cloud SDK is able to enrich the request headers considering the additional properties on an HTTP destination. Therefore, you need to decorate your HttpDestination instance like so:

Destination destination = DestinationAccessor.getDestination(destName);
destination.asHttp().decorate(DefaultErpHttpDestination::new);  

I understand your question how the same works for RFC destinations. As far as I can judge, the Java Connector (JCO) library provided by SAP looks into the destination properties anyway. Hence, I do not see the necessity for such a thing in the realm of RFC destinations. Asking you to outline your requirement more precisely in case you disagree.

BapiRequest accepts Destination, not RfcDestination

I understand your question that you are surprised that BapiRequest::execute does expect a Destination, not an RfcDestination. That is indeed surprising at first glance, however, this is intended as the SAP Cloud SDK also supports to invoke BAPIs wrapped as SOAP APIs. This works via an HttpDestination. For your concrete use case, it suffices that you use DestinationAccessor.getDestination("xyz") and pass that return value into the execute method. You do not need to worry about anything else.

Upvotes: 2

Related Questions