使用 SAP Cloud SDK 版本 3.0 从 Java 调用 BAPI

Calling BAPI from Java using SAP Cloud SDK version 3.0

我目前正在开发 POC,我需要使用 Java 从云应用程序内部调用 S/4HANA 内部部署的 BAPI。为此,我使用 SAP Cloud SDK。

对于初始设置,我遵循了以下步骤: https://developers.sap.com/tutorials/s4sdk-setup.html

我正在尝试从我的应用程序中调用 BAPI_COSTCENTER_GETLIST1。 这是代码片段:

final BapiRequestResult resultGetCostCenters = new BapiRequest("BAPI_COSTCENTER_GETLIST1")
 .withExporting("CONTROLLINGAREA", "BAPI0012_GEN-CO_AREA", "0001")
 .withTable("COSTCENTERLIST", "BAPI0012_CCLIST").end()
 .withTableAsReturn("BAPIRET2")
 .execute(destination);

这里是 destination 变量的声明:

Map<String, String> destinationProps = new HashMap<String, String>();
// Added a sample destination name. Solved NoSuchElementException error. 
destinationProps.put("Name", "SampleDestination");
destinationProps.put("URL", "<system_url>");
destinationProps.put("Type", "HTTP");
destinationProps.put("Password", "<system_password>");
destinationProps.put("Authentication", "BasicAuthentication");
destinationProps.put("User", "<system_user>");

final Destination destination= new DefaultDestination(destinationProps);

但是从 execute() 开始,抛出一个异常 java.util.NoSuchElementException: No value present。这是完整的堆栈跟踪

java.util.NoSuchElementException: No value present
    at io.vavr.control.Option$None.get(Option.java:526)
    at com.sap.cloud.sdk.s4hana.connectivity.rfc.SoapTransaction.before(SoapTransaction.java:56)
    at com.sap.cloud.sdk.s4hana.connectivity.rfc.RemoteFunctionRequestExecutor.execute(RemoteFunctionRequestExecutor.java:43)
    at com.sap.cloud.sdk.s4hana.connectivity.rfc.BapiRequest.execute(BapiRequest.java:78)
    at com.sap.csc.CostCenterCreationServlet.retrieveCostCenterList(CostCenterCreationServlet.java:73)
    at com.sap.csc.CostCenterCreationServlet.doGet(CostCenterCreationServlet.java:39)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.lambda$doFilter(RequestAccessorFilter.java:71)
    at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.lambda$execute[=13=](AbstractThreadContextExecutor.java:317)
    at com.sap.cloud.sdk.cloudplatform.thread.ThreadContextCallable.call(ThreadContextCallable.java:247)
    at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.execute(AbstractThreadContextExecutor.java:319)
    at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.doFilter(RequestAccessorFilter.java:71)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at com.sap.cloud.sdk.cloudplatform.security.servlet.HttpCachingHeaderFilter.doFilter(HttpCachingHeaderFilter.java:80)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at com.sap.cloud.sdk.cloudplatform.security.servlet.HttpSecurityHeadersFilter.doFilter(HttpSecurityHeadersFilter.java:41)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.filters.RestCsrfPreventionFilter.doFilter(RestCsrfPreventionFilter.java:113)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:835)

我想我遗漏了一些非常基本的东西。或者我可能做错了。我找不到关于这个主题的任何有据可查的教程。所以请纠正我哪里出错了。

提前致谢。

(SAP Cloud SDK 概述页面 - https://help.sap.com/doc/0786ec6134c04c9bbafec959b6b737de/1.0/en-US/index.html

Target host is not specified 异常的完整堆栈跟踪

com.sap.cloud.sdk.s4hana.connectivity.exception.RequestExecutionException: BapiRequest com.sap.csc.CostCenterCreationServlet.retrieveCostCenterList(CostCenterCreationServlet.java:69) failed [total: N/A, build payload: 0.243255s, execute request: N/A, parse response: N/A]
com.sap.cloud.sdk.s4hana.connectivity.rfc.exception.RemoteFunctionException: com.sap.cloud.sdk.s4hana.connectivity.exception.RequestExecutionException: BapiRequest com.sap.csc.CostCenterCreationServlet.retrieveCostCenterList(CostCenterCreationServlet.java:69) failed [total: N/A, build payload: 0.243255s, execute request: N/A, parse response: N/A]
    at com.sap.cloud.sdk.s4hana.connectivity.rfc.SoapTransaction.execute(SoapTransaction.java:70)
    at com.sap.cloud.sdk.s4hana.connectivity.rfc.RemoteFunctionRequestExecutor.execute(RemoteFunctionRequestExecutor.java:46)
    at com.sap.cloud.sdk.s4hana.connectivity.rfc.BapiRequest.execute(BapiRequest.java:78)
    at com.sap.csc.CostCenterCreationServlet.retrieveCostCenterList(CostCenterCreationServlet.java:73)
    at com.sap.csc.CostCenterCreationServlet.doGet(CostCenterCreationServlet.java:39)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.lambda$doFilter(RequestAccessorFilter.java:71)
    at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.lambda$execute[=14=](AbstractThreadContextExecutor.java:317)
    at com.sap.cloud.sdk.cloudplatform.thread.ThreadContextCallable.call(ThreadContextCallable.java:247)
    at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.execute(AbstractThreadContextExecutor.java:319)
    at com.sap.cloud.sdk.cloudplatform.servlet.RequestAccessorFilter.doFilter(RequestAccessorFilter.java:71)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at com.sap.cloud.sdk.cloudplatform.security.servlet.HttpCachingHeaderFilter.doFilter(HttpCachingHeaderFilter.java:80)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at com.sap.cloud.sdk.cloudplatform.security.servlet.HttpSecurityHeadersFilter.doFilter(HttpSecurityHeadersFilter.java:41)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.filters.RestCsrfPreventionFilter.doFilter(RestCsrfPreventionFilter.java:113)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: com.sap.cloud.sdk.s4hana.connectivity.exception.RequestExecutionException: BapiRequest com.sap.csc.CostCenterCreationServlet.retrieveCostCenterList(CostCenterCreationServlet.java:69) failed [total: N/A, build payload: 0.243255s, execute request: N/A, parse response: N/A]
    at com.sap.cloud.sdk.s4hana.connectivity.ErpHttpRequestExecutor.execute(ErpHttpRequestExecutor.java:662)
    at com.sap.cloud.sdk.s4hana.connectivity.ErpHttpRequestExecutor.execute(ErpHttpRequestExecutor.java:410)
    at com.sap.cloud.sdk.s4hana.connectivity.rfc.SoapTransaction.execute(SoapTransaction.java:65)
    ... 44 more
Caused by: org.apache.http.client.ClientProtocolException
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:187)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at com.sap.cloud.sdk.cloudplatform.connectivity.HttpClientWrapper.execute(HttpClientWrapper.java:94)
    at com.sap.cloud.sdk.s4hana.connectivity.ErpHttpRequestExecutor.execute(ErpHttpRequestExecutor.java:646)
    ... 46 more
Caused by: org.apache.http.ProtocolException: Target host is not specified
    at org.apache.http.impl.conn.DefaultRoutePlanner.determineRoute(DefaultRoutePlanner.java:71)
    at org.apache.http.impl.client.InternalHttpClient.determineRoute(InternalHttpClient.java:125)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)

请在您的目的地属性中提供 "Name" 条目,例如

destinationProps.put("Name", "<some_name>");