使用 S/4HANA Cloud SDK 使用来自 S/4HANA Cloud 的数据源创建自定义 OData v2 服务:web.xml 错误
Create custom OData v2 service with data source from S/4HANA Cloud using S/4HANA Cloud SDK: web.xml error
我仍在尝试使用 S/4HANA Cloud SDK 在 java 中使用 S/4HANA 云数据源创建自定义 OData v2 服务。按照 3 月 26 日对 的回答中的建议进行了 web.xml 更改,但我在 web.xml 中收到错误(见下文)- 它说 servlet 中的 init-param 是无效内容.
此外,当我尝试通过浏览器使用 $metadata 访问服务元数据时,它显示 'service not found' 并且 Cloud Platform 'Default Trace' 日志具有以下内容:
com.sap.cloud.sdk.service.prov.v2.rt.cdx.CDXRuntimeDelegate anonymous
https-jsse-nio-8041-exec-7 na masssalesorders2application web ha*******
na#na#na#na#No Runtime Providers present for the URL and
languageCFMassSalesOrdersSrv
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="false">
<login-config>
<auth-method>FORM</auth-method>
</login-config>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
<security-role>
<role-name>Everyone</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>All SAP Cloud Platform users</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Everyone</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
<!-- Use CONFIDENTIAL as transport guarantee to ensure SSL connection (HTTPS) on public deployments
<transport-guarantee>CONFIDENTIAL</transport-guarantee> -->
</user-data-constraint>
</security-constraint>
<filter>
<filter-name>RestCsrfPreventionFilter</filter-name>
<filter-class>org.apache.catalina.filters.RestCsrfPreventionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RestCsrfPreventionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>HttpSecurityHeadersFilter</filter-name>
<filter-class>com.sap.cloud.sdk.cloudplatform.security.servlet.HttpSecurityHeadersFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HttpSecurityHeadersFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>HttpCachingHeaderFilter</filter-name>
<filter-class>com.sap.cloud.sdk.cloudplatform.security.servlet.HttpCachingHeaderFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HttpCachingHeaderFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>ODataServlet</servlet-name>
<servlet-class>org.apache.olingo.odata2.core.servlet.ODataServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>org.apache.olingo.odata2.service.factory</param-name>
<param-value>
com.sap.cloud.sdk.service.prov.v2.rt.core.CloudSDKODataServiceFactory
</param-value>
</init-param>
<init-param>
<param-name>org.apache.olingo.odata2.path.split</param-name>
<param-value>1</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ODataServlet</servlet-name>
<url-pattern>/odata/v2/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>package</param-name>
<param-value>com.********.s4sdk</param-value>
</context-param>
<listener>
<listener-class>
com.sap.cloud.sdk.service.prov.v2.rt.core.web.ServletListener
</listener-class>
</listener>
</web-app>
谢谢 - 当我将 load-on-startup 放在 init-param 条目后面时,IntelliJ 显示的 web.xml 中的错误消失了。
当我在 Chrome 中使用此 URL 时:https://masssalesorders2appli********.us3.hana.ondemand.com/masssalesorders2-application/odata/v2/CFMassSalesOrdersSrv/$metadata,浏览器 returns "Service not available".
云平台 'Default Trace' 日志有 3 行 - 每行的每条消息如下:
2019 04 02 14:01:46#+00#ERROR#com.sap.cloud.sdk.service.prov.v2.rt.cdx.CDXRuntimeDelegate##anonymous#https-jsse-nio-8041-exec-6#na#********#masssalesorders2application#web#********#na#na#na#na#No Runtime Providers present for the URL and languageCFMassSalesOrdersSrv
2019 04 02 14:01:46#+00#ERROR#com.sap.cloud.sdk.service.prov.v2.rt.cdx.CDXRuntimeDelegate##anonymous#https-jsse-nio-8041-exec-6#na#********#masssalesorders2application#web#********#na#na#na#na#No Runtime Providers present for the URL and languageCFMassSalesOrdersSrv
2019 04 02 14:01:46#+00#ERROR#com.sap.cloud.sdk.service.prov.v2.rt.core.CloudSDKODataErrorCallback##anonymous#https-jsse-nio-8041-exec-6#na#********#masssalesorders2application#web#********#na#na#na#na#Request URL: /masssalesorders2-application/odata/v2/CFMassSalesOrdersSrv/$metadata
StatusCode:500 org.apache.olingo.odata2.api.exception.ODataInternalServerErrorException: Service unavailable.
at org.apache.olingo.odata2.core.servlet.ODataServlet.createServiceUnavailableResponse(ODataServlet.java:373)
at org.apache.olingo.odata2.core.servlet.ODataServlet.handleRequest(ODataServlet.java:210)
at org.apache.olingo.odata2.core.servlet.ODataServlet.handle(ODataServlet.java:115)
at org.apache.olingo.odata2.core.servlet.ODataServlet.service(ODataServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:83)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
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 org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.sap.core.communication.server.CertValidatorFilter.doFilter(CertValidatorFilter.java:157)
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.RequestContextServletFilter.lambda$doFilter[=15=](RequestContextServletFilter.java:197)
at com.sap.cloud.sdk.cloudplatform.servlet.RequestContextCallable.call(RequestContextCallable.java:131)
at com.sap.cloud.sdk.cloudplatform.servlet.RequestContextServletFilter.doFilter(RequestContextServletFilter.java:209)
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:82)
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:42)
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:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at com.sap.core.connectivity.jco.session.ext.RequestTracker.invoke(RequestTracker.java:55)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610)
at com.sap.cloud.runtime.impl.bridge.security.AbstractAuthenticator.invoke(AbstractAuthenticator.java:206)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:182)
at com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:97)
at com.sap.js.statistics.tomcat.valve.RequestTracingValve.callNextValve(RequestTracingValve.java:113)
at com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:59)
at com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:27)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:836)
当我在 Postman 中使用与 'GET' 相同的 URL 时,'Default Trace' 中没有出现任何行,但 'HTTP Access Log' 中确实出现了一行 - 它 returns '200',但未返回元数据。由于这是我创建 OData v2 服务的第一个项目,该服务在后端访问 S/4HANA 云 API,因此我不确定我是否设置正确:
这里是 java 代码的开头:
@WebServlet("/salesordercreate")
public class MassSalesOrdersServlet extends HttpServlet
{
private static final Logger logger = CloudLoggerFactory.getLogger(MassSalesOrdersServlet.class);
@Create(serviceName = "CFMassSalesOrdersSrv", entity = "MassSalesOrderType")
public CreateResponse createMassSalesOrders(CreateRequest createRequest)
{
MassSalesOrdersEntityType massSalesOrderData = createRequest.getDataAs(MassSalesOrdersEntityType.class);
.
.
.
try {
SalesOrder salesOrderPosted = new SalesOrderCreateFluentHelper("", salesOrder).execute(new ErpConfigContext("S4_Sandbox_Sales_Orders"));
logger.error(salesOrderPosted.getSalesOrder());
MassSalesOrdersEntityType massSalesOrderCreated = new MassSalesOrdersEntityType();
massSalesOrderCreated.setSalesOrderNbrStart(salesOrderPosted.getSalesOrder());
.
.
.
return CreateResponse.setSuccess()
.setData(massSalesOrderCreated).response();
}
您想为使用 SAP Cloud Application Programming Model 定义的服务实现您自己的自定义处理程序。
这样的自定义处理程序必须在普通 Java class 中定义,而不是 servlet。编程模型带来了自己的 servlet,用于处理对 OData 服务的所有请求(如您在 web.xml 中定义的那样)。
请删除您的 class 定义中特定于 servlet 的部分(WebServlet 注释 + super class)。
假设 CDS 中的服务定义等其他一切都已正确设置,自定义处理程序的以下实现应该可以工作:
public class MassSalesOrdersServlet
{
@Create(serviceName = "CFMassSalesOrdersSrv", entity = "MassSalesOrderType")
public CreateResponse createMassSalesOrders(CreateRequest createRequest)
{
// your implementation goes here
}
}
help pages 详细介绍了 SAP 云应用程序编程模型中的自定义逻辑
关于您使用 SAP 的 OData 虚拟数据模型实现 S/4HANA Cloud SDK:请使用该服务发出创建请求,而不是直接实例化流畅的帮助程序:
new DefaultSalesOrderService().createSalesOrder(salesOrder).execute(...)
我仍在尝试使用 S/4HANA Cloud SDK 在 java 中使用 S/4HANA 云数据源创建自定义 OData v2 服务。按照 3 月 26 日对
此外,当我尝试通过浏览器使用 $metadata 访问服务元数据时,它显示 'service not found' 并且 Cloud Platform 'Default Trace' 日志具有以下内容:
com.sap.cloud.sdk.service.prov.v2.rt.cdx.CDXRuntimeDelegate anonymous
https-jsse-nio-8041-exec-7 na masssalesorders2application web ha*******
na#na#na#na#No Runtime Providers present for the URL and
languageCFMassSalesOrdersSrv
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="false">
<login-config>
<auth-method>FORM</auth-method>
</login-config>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
<security-role>
<role-name>Everyone</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>All SAP Cloud Platform users</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Everyone</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
<!-- Use CONFIDENTIAL as transport guarantee to ensure SSL connection (HTTPS) on public deployments
<transport-guarantee>CONFIDENTIAL</transport-guarantee> -->
</user-data-constraint>
</security-constraint>
<filter>
<filter-name>RestCsrfPreventionFilter</filter-name>
<filter-class>org.apache.catalina.filters.RestCsrfPreventionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RestCsrfPreventionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>HttpSecurityHeadersFilter</filter-name>
<filter-class>com.sap.cloud.sdk.cloudplatform.security.servlet.HttpSecurityHeadersFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HttpSecurityHeadersFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>HttpCachingHeaderFilter</filter-name>
<filter-class>com.sap.cloud.sdk.cloudplatform.security.servlet.HttpCachingHeaderFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HttpCachingHeaderFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>ODataServlet</servlet-name>
<servlet-class>org.apache.olingo.odata2.core.servlet.ODataServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>org.apache.olingo.odata2.service.factory</param-name>
<param-value>
com.sap.cloud.sdk.service.prov.v2.rt.core.CloudSDKODataServiceFactory
</param-value>
</init-param>
<init-param>
<param-name>org.apache.olingo.odata2.path.split</param-name>
<param-value>1</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ODataServlet</servlet-name>
<url-pattern>/odata/v2/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>package</param-name>
<param-value>com.********.s4sdk</param-value>
</context-param>
<listener>
<listener-class>
com.sap.cloud.sdk.service.prov.v2.rt.core.web.ServletListener
</listener-class>
</listener>
</web-app>
谢谢 - 当我将 load-on-startup 放在 init-param 条目后面时,IntelliJ 显示的 web.xml 中的错误消失了。
当我在 Chrome 中使用此 URL 时:https://masssalesorders2appli********.us3.hana.ondemand.com/masssalesorders2-application/odata/v2/CFMassSalesOrdersSrv/$metadata,浏览器 returns "Service not available".
云平台 'Default Trace' 日志有 3 行 - 每行的每条消息如下:
2019 04 02 14:01:46#+00#ERROR#com.sap.cloud.sdk.service.prov.v2.rt.cdx.CDXRuntimeDelegate##anonymous#https-jsse-nio-8041-exec-6#na#********#masssalesorders2application#web#********#na#na#na#na#No Runtime Providers present for the URL and languageCFMassSalesOrdersSrv
2019 04 02 14:01:46#+00#ERROR#com.sap.cloud.sdk.service.prov.v2.rt.cdx.CDXRuntimeDelegate##anonymous#https-jsse-nio-8041-exec-6#na#********#masssalesorders2application#web#********#na#na#na#na#No Runtime Providers present for the URL and languageCFMassSalesOrdersSrv
2019 04 02 14:01:46#+00#ERROR#com.sap.cloud.sdk.service.prov.v2.rt.core.CloudSDKODataErrorCallback##anonymous#https-jsse-nio-8041-exec-6#na#********#masssalesorders2application#web#********#na#na#na#na#Request URL: /masssalesorders2-application/odata/v2/CFMassSalesOrdersSrv/$metadata
StatusCode:500 org.apache.olingo.odata2.api.exception.ODataInternalServerErrorException: Service unavailable.
at org.apache.olingo.odata2.core.servlet.ODataServlet.createServiceUnavailableResponse(ODataServlet.java:373)
at org.apache.olingo.odata2.core.servlet.ODataServlet.handleRequest(ODataServlet.java:210)
at org.apache.olingo.odata2.core.servlet.ODataServlet.handle(ODataServlet.java:115)
at org.apache.olingo.odata2.core.servlet.ODataServlet.service(ODataServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:83)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
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 org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.sap.core.communication.server.CertValidatorFilter.doFilter(CertValidatorFilter.java:157)
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.RequestContextServletFilter.lambda$doFilter[=15=](RequestContextServletFilter.java:197)
at com.sap.cloud.sdk.cloudplatform.servlet.RequestContextCallable.call(RequestContextCallable.java:131)
at com.sap.cloud.sdk.cloudplatform.servlet.RequestContextServletFilter.doFilter(RequestContextServletFilter.java:209)
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:82)
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:42)
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:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at com.sap.core.connectivity.jco.session.ext.RequestTracker.invoke(RequestTracker.java:55)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610)
at com.sap.cloud.runtime.impl.bridge.security.AbstractAuthenticator.invoke(AbstractAuthenticator.java:206)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.tomee.catalina.OpenEJBSecurityListener$RequestCapturer.invoke(OpenEJBSecurityListener.java:97)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:182)
at com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:97)
at com.sap.js.statistics.tomcat.valve.RequestTracingValve.callNextValve(RequestTracingValve.java:113)
at com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:59)
at com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:27)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:836)
当我在 Postman 中使用与 'GET' 相同的 URL 时,'Default Trace' 中没有出现任何行,但 'HTTP Access Log' 中确实出现了一行 - 它 returns '200',但未返回元数据。由于这是我创建 OData v2 服务的第一个项目,该服务在后端访问 S/4HANA 云 API,因此我不确定我是否设置正确:
这里是 java 代码的开头:
@WebServlet("/salesordercreate")
public class MassSalesOrdersServlet extends HttpServlet
{
private static final Logger logger = CloudLoggerFactory.getLogger(MassSalesOrdersServlet.class);
@Create(serviceName = "CFMassSalesOrdersSrv", entity = "MassSalesOrderType")
public CreateResponse createMassSalesOrders(CreateRequest createRequest)
{
MassSalesOrdersEntityType massSalesOrderData = createRequest.getDataAs(MassSalesOrdersEntityType.class);
.
.
.
try {
SalesOrder salesOrderPosted = new SalesOrderCreateFluentHelper("", salesOrder).execute(new ErpConfigContext("S4_Sandbox_Sales_Orders"));
logger.error(salesOrderPosted.getSalesOrder());
MassSalesOrdersEntityType massSalesOrderCreated = new MassSalesOrdersEntityType();
massSalesOrderCreated.setSalesOrderNbrStart(salesOrderPosted.getSalesOrder());
.
.
.
return CreateResponse.setSuccess()
.setData(massSalesOrderCreated).response();
}
您想为使用 SAP Cloud Application Programming Model 定义的服务实现您自己的自定义处理程序。
这样的自定义处理程序必须在普通 Java class 中定义,而不是 servlet。编程模型带来了自己的 servlet,用于处理对 OData 服务的所有请求(如您在 web.xml 中定义的那样)。
请删除您的 class 定义中特定于 servlet 的部分(WebServlet 注释 + super class)。
假设 CDS 中的服务定义等其他一切都已正确设置,自定义处理程序的以下实现应该可以工作:
public class MassSalesOrdersServlet
{
@Create(serviceName = "CFMassSalesOrdersSrv", entity = "MassSalesOrderType")
public CreateResponse createMassSalesOrders(CreateRequest createRequest)
{
// your implementation goes here
}
}
help pages 详细介绍了 SAP 云应用程序编程模型中的自定义逻辑
关于您使用 SAP 的 OData 虚拟数据模型实现 S/4HANA Cloud SDK:请使用该服务发出创建请求,而不是直接实例化流畅的帮助程序:
new DefaultSalesOrderService().createSalesOrder(salesOrder).execute(...)