Android OData application with REST SDK SUP 2.2 SP 03
From SUP 2.2 onwards we have an option to develop the OData applications with REST services. Just making the request to some REST services which are available in the SUP we can develop the pure HTTP applications. For android and iOS SAP has provided the REST SDK libraries to develop the OData applications.
Configuring the Android develop environment
Step: 1 Library needs to add.
We need to add the following libraries into our OData application project
Step: 2 Configuring request manager
In OData application everything is based on the request manager, we need to set-up the request manager for our application all the request to the server should go through that request manager. Following code snippet shows the request manager definition for REST SDK OData applications.
In that definition we are setting up the logger, preferences and params for our application. Since this REST SDK based OData application we are setting the connectivity handler as SDMConstants.SDM_HTTP_HANDLER_CLASS if we are developing normal OData application no need to mention this handler preferences by default it will take the OData handler class name.
We are passing username and password in param object. We are passing our preferences, logger and params to the super class SDMRequestManager.
Note:- For the best development use NoSec configuration in SCC for our application, and pass the Gateway username and password in the reqmanager so one user will create automatically with this username in SCC.
Step: 3 Registration of the User.
In the registration part we can use two scenario one with relay server and without relay server.
Below code snippet shows the registration part using REST SDK API.
Need to initialize the request manager method which we defined already along with application context.
Need to create ClientConnection object with application context, app ID, domain, security config and request manager which we initialized earlier.
For registration we need to setup the connection Profile. We can set the connection profile by calling the setConnectionProfile method which is available ClientConnection class.
We can make registration in two ways one with relay server and one without relay server. While using relay server we need to mention the relay server URL as server name, URL template and URL farm ID. While using without relay server we need to mention our SUP server and HTTP port of our server, by that time we can pass URL template and farm ID as null.
Registration can be done in two ways,
We can set the synchronous or asynchronous mode of registration using the following method
False: Asynchronous registration.
True: Synchronous registration.
For asynchronous registration we need to implement the following call back method to handle the flow.
Step: 4 Making HTTP request
For making HTTP request we need to use SDMRequestManager class.
The entire request from this class is basically an asynchronous call. In the code implementation we need to handle all the calls.
Below code snippet shows the code for making the request to the backend.
The flow of the HTTP request is like service document, meta-data document and data. Above code shows the request for service document. Since all the requests are in asynchronous mode we need to handle this is by using synchronized object wait and notify method of the object.
Step: 5 Request Handler
We need to implement the interface ISDMNetListener in our class to handle the response from the server. These methods will trigger when we receive a positive or negative response from server. We have two methods in this interface those are.
public void onSuccess (ISDMRequest aRequest, ISDMResponse aResponse)
Above method will trigger when we are getting positive response and below one will trigger when we are received negative response.
public void onError(ISDMRequest arg0, ISDMResponse arg1,ISDMRequestStateElement arg2)
Following code snippet shows the implementation of above two methods.
Configuration in SCC:
For this approach in SCC we need to create the application and Proxy connection in connections template. The URL what is in application should match exact with the proxy connections. If it’s not the same we will get whitelisting error.
REST URL’s for Pure HTTP based application (Other than Android and iOS)
For creating connections/Registration:
Forwarding the request to backend using SUP in-built forwarding
After the registration use the same request manger make a request the following URL