Trying to create custom OData v2 service with data

2020-05-09 07:12发布

问题:

I am trying to create a custom OData v2 service in java with an S/4HANA Cloud data source using S/4HANA Cloud SDK. I tried to follow section 8.3 of the SAP Press book "Extending SAP S/HANA: Side-by-Side Extensions with the SAP S/HANA Cloud SDK", except I attempted to substitute OData version 2 for version 4 in the dependency on page 285. When I execute mvn clean install, it errors out telling me it can't find odatav2 in com.sap.cloud.servicesdk.prov. (I get a clean install when I use odatav4 instead.) The reason I want OData v2 is version 4 doesn't appear to be well-supported for SAPUI5 apps.

回答1:

The setup for OData V2 provisioning looks a bit different. So remove all modifications you did to use OData V4 provisioning. Then add the following:

  1. Add the following dependencies (instead of the odata-v4 one) to your application/pom.xml file:

    <dependency>
        <groupId>com.sap.cloud.servicesdk.prov</groupId>
        <artifactId>odata2.web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.sap.cloud.servicesdk.prov</groupId>
        <artifactId>odata2.xsa</artifactId>
    </dependency>
    <dependency>
        <groupId>com.sap.cloud.servicesdk.prov</groupId>
        <artifactId>odatav2-hybrid</artifactId>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.sap.cloud.servicesdk.prov</groupId>
        <artifactId>odatav2-prov</artifactId>
    </dependency>
    
  2. Add the following entries to your application/src/main/webapp/WEB-INF/web.xml file, replacing YOUR.PACKAGE with a package to search for your OData endpoints:

    <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>YOUR.PACKAGE</param-value>
    </context-param>
    <listener>
        <listener-class>
            com.sap.cloud.sdk.service.prov.v2.rt.core.web.ServletListener
        </listener-class>
    </listener>
    
  3. Add an OData V2 edmx file to the application/src/main/resources/edmx directory.

These steps should get your OData V2 Provisioning service up and running.



标签: s4sdk