Skip to content

SMP Client - Using the ODataOnlineCore Library to Connect to an SMP Server

In order to efficiently exercise the SMP Server OData service, you first need to generate a set of OData proxy classes.

The purpose of this library is to make registration, de-registration, and handling application settings easier for application developers. Before a client application starts to use a service configured in an SMP server, the application must be registered to that server. The SMP server provides an OData service where a new Connection entity must be created, or deleted, in order to register or de-register the client. This library contains proxy classes for this service.

Note that this library also compatible with SAP BTP Platform.

Generating SMPClient Proxy Classes

SMP SDK comes with pre-generated OData proxy classes, which comprise a convenience framework. It contains only generated code. In spite of our best efforts to update this library as often as possible, you may need to regenerate the content for your application.

Collecting $Metadata XML from the SMP Server

In order to generate the OData proxy classes, you will need to download the $Metadata XML document from the SMP server.

$ curl -o Applications.xml http://<hostname_of_your_smp_server>:8080/odata/applications/v4/<APPLICATION_ID>/$metadata

You may need to provide credentials to access this document.

Generating XS Script from $Metadata

In order to generate the XS script from the $Metadata, you need to use the xscript proxy-generator-mobile utility that comes with the SMP SDK package.

$ sh xs-proxy.sh Applications.xml Applications.xs -service "Applications" -generic -pretty -java com.example.myapp.smpclient

This will create an XS file.

Generating Java Proxy Classes from an XS Script File

In order to use the Proxy Classes in an Android project, you will need to compile the XS file using the xs compiler.

$ sh xsc.sh Applications.xs -java -smp3 -d output

This generates the set of Java files that you need to add to your Android project.

Registration

  1. Clients must create an HTTPConversationManager object and configure it according to the authentication method of the server. The example in this document uses basic authentication. See the HttpConversation Developer Guide for details about other authentication options, such as SAML2 or OAuth2.

    final UsernamePasswordToken token = new UsernamePasswordToken("userName","password");
    HttpConversationManager conversationManager = new CommonAuthFlowsConfigurator(getContext()).
    supportBasicAuthUsing(new UsernamePasswordProvider() {
        @Override
        public Object onCredentialsNeededUpfront(ISendEvent event) { return token; }
        @Override
        public Object onCredentialsNeededForChallenge(IReceiveEvent event) { return token; }
    }
    }).configure(new HttpConversationManager(getContext()));
    
  2. Create the SmpClient object and configure it to use the conversation manager created in the first step. By default the URL of this registration service looks like this: "https://serverHost:serverPort/odata/applications/v4/yourApplicationID"

    SDKHttpHandler sdkHttpHandler = new SDKHttpHandler(getContext(), conversationManager);
    AndroidSystem.setContext(getContext());
    OnlineODataProvider registrationProvider = new OnlineODataProvider("SmpClient",
    "https://serverHost:serverPort/odata/applications/v4/yourApplicationID");
    registrationProvider.getNetworkOptions().setHttpHandler(sdkHttpHandler);
    registrationProvider.getServiceOptions().setCheckVersion(false);
    SmpClient smpClient = new SmpClient(registrationProvider);
    
  3. Use SmpClient to create a new connection. When creating connections, only one property is relevant: the DeviceType must be set to “Android”.

    Connection newConnection = new Connection();
    newConnection.setDeviceType("Android");
    smpClient.createEntity(newConnection);
    

Application Settings

After a Connection is successfully created, the server responds with application settings configured in the server and the Connection object will contain application settings relevant for the application. Please refer to the SMP documentation for information regarding the different settings.

Boolean passwordPolicyEnabled = newConnection.getPasswordPolicyEnabled();
Boolean passwordPolicyDefaultPasswordAllowed = newConnection.getPasswordPolicyDefaultPasswordAllowed();
Boolean passwordPolicyFingerprintEnabled = newConnection.getPasswordPolicyFingerprintEnabled();
String androidGcmSenderId = newConnection.getAndroidGcmSenderId();

Use the Application Service

In order to use a service, the client must use its own generated proxy classes. Please note when configuring the proxy service, the same HttpConversationManager MUST be used in order to reach the service. By default, the URL of the application service looks like this: "https://serverHost:serverPort/yourApplicationID".

SDKHttpHandler sdkHttpHandler = new SDKHttpHandler(getContext(), conversationManager);
OnlineODataProvider serviceProvider = new OnlineODataProvider("flightService","https://serverHost:serverPort/yourApplicationID");
serviceProvider.getNetworkOptions().setHttpHandler(sdkHttpHandler);
FlightService flightService = new FlightService(serviceProvider);
flightService.getTravelagencyCollection();

Deregistration

Use SmpClient to delete a Connection

    smpClient.deleteEntity(newConnection);