Skip to Content

The new version of the SAP S/4HANA Cloud SDK Java libraries is available since last week. You can update your dependencies to version 2.4.1 and consume the new version from Maven Central.
In this blog post, we will walk you through the highlights of the release. For a complete overview, visit our release notes for the Java libraries. The release notes also include the change log of all our releases so far.
At the end of the article, you will find a set of instructions on how to update to the new version.


SAP TechEd 2018 is approaching quickly! The conference in Las Vegas is only two weeks away, and Barcelona and Bangalore will follow soon after. The SAP S/4HANA Cloud SDK will be well-represented at all three locations with numerous sessions, including hands-on workshops and CodeJams.

Check out the agenda for SDK-related sessions in Las Vegas and Barcelona. Especially make sure to register for hands-on sessions now, as capacity is limited.

Stay tuned for a blog post with more details on the SDK sessions!


Java Libraries: Release Highlights

Consume SOAP APIs Conveniently

The SAP S/4HANA Cloud SDK strives to make consuming APIs of SAP S/4HANA Cloud easy and delightful, most importantly with the Java Virtual Data Model (VDM) for OData services. In addition to OData services, some APIs of SAP S/4HANA Cloud are exposed as SOAP services. There are already open source libraries for consuming SOAP services from Java available. What was missing so far is an easy integration of SOAP service consumption with the capabilities of the SDK, which transparently handles low-level tasks such as retrieving destination configuration for the SAP S/4HANA system to connect to, establishing the connection, possibly via a Cloud Connector to the on-premise network, applying required authentication, and many more.

With version 2.4.1, the SAP S/4HANA Cloud SDK simplifies consuming a SOAP service when using the Apache Axis2 framework. To this end, we introduce the SoapQuery class. With this, you can easily generate a Java representation for the SOAP service in question using Axis2 and couple it with the SAP S/4HANA Cloud SDK to handle the infrastructure tasks of destination retrieval, connectivity, and authentication. That is, your code to call an operation of a SOAP service can be as simple as follows (using Java 8 lambda expressions) and benefit from the capabilities of the SAP S/4HANA Cloud SDK:

new SoapQuery<>(YourAxis2SoapServiceStub.class)
    .execute(soapService -> soapService.callOperation(...))

We have published a separate deep dive on the convenient consumption of SOAP APIs that explains end-to-end the use of the new feature in more detail. Make sure to check out this blog post if you want to consume SOAP APIs of SAP S/4HANA Cloud in your application on SAP Cloud Platform.

Create New OData Entity as Child of Another Entity

The Java VDM for OData services makes it easy, besides other features, to create new entities via OData requests. Some OData services may require that you create an entity as a child of another entity via a navigation property of the parent entity. In other cases, it may be more natural to create an entity by addressing the naviation property of a parententity, for example, when adding an address to an existing business partner.

The Java VDM now allows creating an OData entity as the child of another entity. To leverage this feature, first call the method of the service with the entity to create, then use the method asChildOf on the corresponding fluent helper for the create request. You need to supply the parent entity to asChildOf, as well as the navigation property of the parent entity type to specify the relationship between parent entity and the child entity to be created.

As an example, consider the following code which will create an address as a child of a business partner via the TO_BUSINESS_PARTNER_ADDRESS navigation property of the business partner:

new DefaultBusinessPartnerService()
    .createBusinessPartnerAddress(addressToCreate)
    .asChildOf(parentBusinessPartner, BusinessPartner.TO_BUSINESS_PARTNER_ADDRESS)
    .execute();

As usual with the Java VDM, this approach is type-safe thanks to the Java representation of the OData service. It requires that the OData service in question supports creating the child entity via the navigation property of another entity.

Retrieve Destinations from Subscriber and/or Provider Account

The SAP S/4HANA Cloud SDK relieves developers from menial tasks otherwise required to retrieve the configuration of destinations. You can define destinations that point to downstream services or systems using the SAP Cloud Platform cockpit and easily reference them by name from your code. The SAP S/4HANA Cloud SDK takes care of everything else, from retrieving the configuration to executing necessary authentication flows as defined by the configuration.

In a multi-tenant software-as-a-service (SaaS) application, there may be different kinds of downstream destinations, some of which are tenant-specific and defined by customers subscribed to the application, and others defined by the application provider. For example, each customer will define his own destination configuration to connect to his SAP S/4HANA system, while a microservice may use the destination service to define a common destination to connect to another microservice. In the latter case, it may be highly undesired if customers could overwrite the application-internal destination, while this is necessary in the first case.

With version 2.4.1, the SDK gives consumers more fine-granular control over where to look for destinations. One differentiates between the provider account, which hosts the application, and subscriber accounts for each tenant (customer) of the application. The SDK now allows developers to specify per destination whether the configuration shall be retrieved always and exclusively from the provider account or from the subscriber account. It is also possible to choose to fallback to the provider in case the current subscriber tenant does not define (that is, overrides) the destination.

To this end, we have enhanced the DestinationAccessor class by the static method setRetrievalStrategy. For a given destination name, you can set the strategy for loading the destination to any of the above mentioned strategies, which are reflected by DestinationRetrievalStrategy. For example, to prevent subscribers from overriding a destination you would set its strategy to DestinationRetrievalStrategy.ALWAYS_PROVIDER.

The strategy is not being persisted. You need to ensure that you set the strategy prior to any attempt to resolve the destination, for example, during application startup. If no specific strategy has been defined for a destination, the default of the current environment of SAP Cloud Platform will be used. On the Neo environment, this means subscriber then provider (fallback), and on Cloud Foundry always subscriber. Use getRetrievalStrategy to determine the currently defined strategy for a destination.

Further Improvements

The Java VDM for OData services now handles optimistic concurrency control also for delete requests and queries. Previously (since version 1.10.0), the ETag version identifier used for concurrency control in OData services was handled automatically only in case of retrieving an entity by key and during update requests. Now, when retrieving many entities with a OData query request that returns the ETag value for each entity, the version identifier will be stored for all retrieved entities. Delete requests will automatically include the ETag value from the entity to be deleted, if available, in the If-Match header of the request.

Version 2.4.1 introduces the DestinationHeaderProvider interface that allows to pass additional Header objects to any call of the respective destination. Interface implementations are automatically discovered by the Java service loader.

We have enhanced all Cloud Foundry archetypes to use the timeout attribute in manifest.yml. The default values for newly generated projects is a deployment timeout of 5 minutes in order to avoid issues with larger deployments that may take longer starting, especially if available CPU is restricted.

Several further improvements are listed in the full release notes.

How to Update the Java Libraries

To update the version of the SAP S/4HANA Cloud SDK Java libraries used in an existing project, proceed as follows:

  • Open the pom.xml file in the root folder of your project.
  • Locate the dependency management section and therein the sdk-bom dependency.
  • Update the version of that dependency to 2.4.1.

With this, you are already done thanks to the “bill of material” (BOM) approach. Your dependency should look like this:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.sap.cloud.s4hana</groupId>
            <artifactId>sdk-bom</artifactId>
            <version>2.4.1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
    <!-- possibly further managed dependencies ... -->
</dependencyManagement>

You can now recompile your project (be aware of the compatibility notes, though) and leverage the new features of the SAP S/4HANA Cloud SDK in version 2.4.1.

Of course, you can also generate a new project that uses version 2.4.1 from the start by running the Maven archetypes for Neo or Cloud Foundry with -DarchetypeVersion=2.4.1 (or RELEASE).

To report this post you need to login first.

6 Comments

You must be Logged on to comment or reply to a post.

  1. Tri Minh Le

    Hi Henning Heitkoetter,

    I’m using SAP WebIDE Full stack to develop Application programming model.

    I was using 2.1.2 and I upgrade to 2.4.1 for testing. When I build it, it generates the error:

    [ERROR] Failed to execute goal on project srv: Could not resolve dependencies for project sap:srv:war:1.0-SNAPSHOT: The following artifacts could not be resolved: com.sap.gw.rt:core.api:jar:1.35.17, com.sap.gw.rt:core.runtime:jar:1.35.17, org.apache.olingo:olingo-odata2-api:jar:2.0.10-sap-04, org.apache.olingo:olingo-odata2-core:jar:2.0.10-sap-04: Failure to find com.sap.gw.rt:core.api:jar:1.35.17 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project srv: Could not resolve dependencies for project sap:srv:war:1.0-SNAPSHOT: The following artifacts could not be resolved: com.sap.gw.rt:core.api:jar:1.35.17, com.sap.gw.rt:core.runtime:jar:1.35.17, org.apache.olingo:olingo-odata2-api:jar:2.0.10-sap-04, org.apache.olingo:olingo-odata2-core:jar:2.0.10-sap-04: Failure to find com.sap.gw.rt:core.api:jar:1.35.17 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced	
    at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:221)	
    at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies(LifecycleDependencyResolver.java:127)	
    at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved(MojoExecutor.java:245)	
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:199)	
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)	
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)	
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)	
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)	
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)	
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)	
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)	
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)	
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)	
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)	
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)	
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)	
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)	
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)	
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)	
    at java.lang.reflect.Method.invoke(Method.java:498)	
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)	
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)	
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)	
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
    Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project sap:srv:war:1.0-SNAPSHOT: The following artifacts could not be resolved: com.sap.gw.rt:core.api:jar:1.35.17, com.sap.gw.rt:core.runtime:jar:1.35.17, org.apache.olingo:olingo-odata2-api:jar:2.0.10-sap-04, org.apache.olingo:olingo-odata2-core:jar:2.0.10-sap-04: Failure to find com.sap.gw.rt:core.api:jar:1.35.17 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced	
    at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:211)	
    at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:195)	
    ... 23 more
    Caused by: org.eclipse.aether.resolution.DependencyResolutionException: The following artifacts could not be resolved: com.sap.gw.rt:core.api:jar:1.35.17, com.sap.gw.rt:core.runtime:jar:1.35.17, org.apache.olingo:olingo-odata2-api:jar:2.0.10-sap-04, org.apache.olingo:olingo-odata2-core:jar:2.0.10-sap-04: Failure to find com.sap.gw.rt:core.api:jar:1.35.17 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced	
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:384)	
    at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:205)	
    ... 24 more
    Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: The following artifacts could not be resolved: com.sap.gw.rt:core.api:jar:1.35.17, com.sap.gw.rt:core.runtime:jar:1.35.17, org.apache.olingo:olingo-odata2-api:jar:2.0.10-sap-04, org.apache.olingo:olingo-odata2-core:jar:2.0.10-sap-04: Failure to find com.sap.gw.rt:core.api:jar:1.35.17 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced	
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)	
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)	
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:367)	
    ... 25 more
    Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Failure to find com.sap.gw.rt:core.api:jar:1.35.17 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced	
    at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.newException(DefaultUpdateCheckManager.java:231)	
    at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.checkArtifact(DefaultUpdateCheckManager.java:206)	
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.gatherDownloads(DefaultArtifactResolver.java:585)	
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:503)	
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:421)	
    ... 27 more[ERROR] 

    However, if I switch back to 2.1.2, it’s ok.

    What is the best practice if upgrading Java library on SAP WebIDE Full stack because I find it quite complex than Eclipse.

    Regards,

    Tri

    (0) 
      1. Tri Minh Le

        Hi Sander,

        I didn’t add this dependency and only replaced the version of sdk-bom with 2.4.1. I’m trying to do APM exposing odata v2.

        Regards,

        Tri

         

         

        (0) 
        1. Daniel Foehr

          Hi,

          I successfully build the project in the SAP WebIDE without dependency issues with the following configuration:

          Parent pom:

          <parent>
          <groupId>com.sap.cloud.servicesdk.prov</groupId>
          <artifactId>projects-parent-odatav2</artifactId>
          <version>1.21.1</version>
          </parent>

          S/4HANA Cloud SDK:

          <dependencyManagement>
          <dependencies>
          <dependency>
          <groupId>com.sap.cloud.s4hana</groupId>
          <artifactId>sdk-bom</artifactId>
          <version>2.4.1</version>
          <type>pom</type>
          <scope>import</scope>
          </dependency>
          </dependencies>
          </dependencyManagement>

          The Cloud SDK for Service Development version 1.21.1 includes the version 2.1.2 of the sdk-bom of the S/4HANA Cloud SDK. This overrides the sdk-bom version from the parent pom to be the newest version:  2.4.1.

           

          Hope that helps.

          Best Regards,

          Daniel

          (2) 
          1. Tri Minh Le

            Hi Daniel,

            Thank you for your help but it doesn’t work.

            I created an APM project from scratch and configured the POM.xml file as you said but the project couldn’t be built. It still shows the error.

            [ERROR] Failed to execute goal on project abcd-srv: Could not resolve dependencies for project sap:abcd-srv:war:1.0-SNAPSHOT: The following artifacts could not be resolved: com.sap.gw.rt:core.api:jar:1.35.17, com.sap.gw.rt:core.runtime:jar:1.35.17, org.apache.olingo:olingo-odata2-api:jar:2.0.10-sap-04, org.apache.olingo:olingo-odata2-core:jar:2.0.10-sap-04: Could not find artifact com.sap.gw.rt:core.api:jar:1.35.17 in central (https://repo.maven.apache.org/maven2) -> [Help 1]

            Regards,

            Tri

            (0) 
            1. Daniel Foehr

              Hi,

               

              I think your best option would be to open a customer incident in the categorie “CA-WDE-BLD” –> WEB IDE Build. Unfortunately I cannot reproduce the issue.

              Additionally you might want to share the project on Github with me personally  that I have the very same setup like you have.

               

              Thank you for your understanding.

               

              Best Regards,

              Daniel

              (1) 

Leave a Reply