使用S / 4HANA Cloud SDK使用来自S / 4HANA Cloud的数据源创建自定义OData v2服务:web.xml错误

时间:2019-04-01 23:56:30

标签: s4sdk

我仍在尝试使用S / 4HANA Cloud SDK在Java中使用S / 4HANA Cloud数据源创建自定义OData v2服务。按照3月26日对this question的回答中的建议对web.xml进行了更改,但是我在web.xml中遇到错误(请参阅下文)-它说servlet中的init-param是无效内容。

此外,当我尝试通过带有$ metadata的浏览器访问服务元数据时,它说“找不到服务”,并且Cloud Platform“默认跟踪”日志包含以下内容:

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.cfindustries.s4sdk</param-value>
    </context-param>
    <listener>
        <listener-class>
        com.sap.cloud.sdk.service.prov.v2.rt.core.web.ServletListener
        </listener-class>
    </listener>

</web-app>

谢谢-当我将启动加载程序放在init-param条目后面时,IntelliJ显示的web.xml错误消失了。

当我在Chrome中使用以下URL:https://masssalesorders2appliha87384d3.us3.hana.ondemand.com/masssalesorders2-application/odata/v2/CFMassSalesOrdersSrv/ $ metadata时,浏览器将返回“服务不可用”。

Cloud Platform“默认跟踪”日志有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#ha87384d3#masssalesorders2application#web#ha87384d3#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#ha87384d3#masssalesorders2application#web#ha87384d3#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#ha87384d3#masssalesorders2application#web#ha87384d3#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$0(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)

当我在邮递员中使用带有“ GET”的相同URL时,“默认跟踪”中没有出现任何行,但是“ HTTP访问日志”中却出现了行-它返回“ 200”,但未返回元数据。由于这是我创建用于访问后端S / 4HANA Cloud API的OData v2服务的第一个项目,因此我不确定是否正确设置了此设置:

这是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();

        }

1 个答案:

答案 0 :(得分:2)

您要为使用SAP Cloud Application Programming Model定义的服务实现自己的自定义处理程序。

这样的自定义处理程序必须在普通的Java类中定义,而不是在servlet中定义。编程模型带来了自己的servlet,该servlet处理对OData服务的所有请求(如您在web.xml中定义的那样)。

请删除您的类定义中特定于servlet的部分(WebServlet批注+超类)。

假设CDS中的其他所有内容(如服务定义)均已正确设置,则自定义处理程序的以下实现应该可以正常工作:

public class MassSalesOrdersServlet
{
    @Create(serviceName = "CFMassSalesOrdersSrv", entity = "MassSalesOrderType")
    public CreateResponse createMassSalesOrders(CreateRequest createRequest)
    {
        // your implementation goes here
    }
}

help pages提供了有关SAP Cloud Application Programming Model中的自定义逻辑的更多详细信息

关于使用SAP S / 4HANA Cloud SDK的OData虚拟数据模型的实现:请使用该服务发出创建请求,而不是直接实例化fluent帮助器:

new DefaultSalesOrderService().createSalesOrder(salesOrder).execute(...)