Вызов BAPI из Java с использованием SAP Cloud SDK версии 3.0 - PullRequest
2 голосов
/ 17 января 2020

В настоящее время я работаю над PO C, где мне нужно вызвать BAPI внутри S / 4HANA On-Premise из облачного приложения, используя Java. Для этого я использую 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$1(RequestAccessorFilter.java:71)
    at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.lambda$execute$0(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)

Я предполагаю, что я пропускаю что-то очень базовое c в нем. Или, возможно, я делаю это совершенно неправильно. Я не смог найти ни одного хорошо документированного руководства по этой теме c. Поэтому, пожалуйста, поправьте меня, где я иду не так.

Заранее спасибо.

(Страница обзора 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$1(RequestAccessorFilter.java:71)
    at com.sap.cloud.sdk.cloudplatform.thread.AbstractThreadContextExecutor.lambda$execute$0(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)

1 Ответ

1 голос
/ 17 января 2020

Пожалуйста, укажите "Name" запись в свойствах вашего пункта назначения, например

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