Skip to content

Getting Started

Integrate the library

Builds of the library are provided as a Maven module in Maven Central. You can use them the following way:

Maven

Add the following dependency to your pom.xml

<dependency>
    <groupId>com.sap.cloud.platform.mobile.services</groupId>
    <artifactId>java-integration</artifactId>
    <version>1.3.0</version>
</dependency>

Gradle

Add the following dependencies to your project configuration/build.gradle

dependencies {

    implementation 'com.sap.cloud.platform.mobile.services:java-integration:1.3.0'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testCompileOnly 'org.projectlombok:lombok'
    testAnnotationProcessor 'org.projectlombok:lombok'

}

Connect via SAP Mobile Services settings file

To connect to SAP Mobile Services you need to provide a settings file to the client library. The settings file contains the service endpoints and service keys for each mobile application. See SAP Mobile Services Documentation: Service Keys how to manage service keys.

Example of a settings file:

{
  "server": "https://any.mobile.application.url.com",
  "platform": "CF",
  "applicationId": "applicationId",
  "services": [
    {
      "name": "push",
      "serviceKeys": [
        {
          "alias": "myAlias",
          "url": "https://service.key.url.com/2787d5ea-17cb-4c71-85ca-a9600d4b97c9",
          "apiKey": "apiKey"
        }
      ]
    }
  ]
}

Properties of Settings File

Property Name Description Example Value
server This is the mobile app URL, see SAP Mobile Services Cockpit > Mobile Applications > Native/MDK > Your Application > APIs https://any.mobile.application.url.com
platform Which platform runs the mobile services. As of now, only Cloud Foundry is supported CF
applicationId The Mobile Application Id, see SAP Mobile Services Cockpit > Mobile Applications > Native/MDK > Your Application > Info applicationId
services List of service specific configurations see next paragraph ]

Service Setting

Each service setting is represented as an entry in the services list and identified by the name.

Property Name Description Example Value
name This specifies the service push
serviceKeys You can configure a list of service keys, but the first one is used always.

Service Keys

The service key is managed in the SAP Mobile Services Cockpit and assigned to roles. The roles controls access to the service API. alias and url are mandatory. Provide either the apiKey for API or uaa configuration from the X509 service key details.

Property Name Description Example Value
alias The service key alias name myAlias
url The service key URL pointing to the service instance https://service.key.url.com/2787d5ea-17cb-4c71-85ca-a9600d4b97c9
apiKey The service key API key. This key is generated by Mobile Services apiKey
uaa The uaa configuration from the X509 service key details

Troubleshooting XSUAA Client JSON Class Path Issues

Please see Troubleshooting JSON classpath issues.

Connect via Cloud Foundry Binding

If your application runs on a Cloud Foundry runtime in SAP BTP, it's easy to bind it to an SAP Mobile Services Cloud Foundry service instance. To bind the service instance, you can use the cf bind-service command. See Cloud Foundry CLI Reference Guide: bind-service how to manage service bindings.

Once your application is bound to the service instance, you can retrieve it in your application:

MobileServicesBinding mobileServicesBinding = MobileServicesBinding.fromVCAPVariables()
    .orElseThrow(() -> new IllegalStateException("No mobile-services binding found"));

Also see Cloud Foundry Binding Sample for a sample application that uses a service binding.