Developer

Initializing an Online Store

Initialize an online OData store for online OData access.

Prerequisites

Define the back-end OData connections required by the application in the administration cockpit for either SAP Mobile Platform Server or SAP Cloud Platform mobile service for development and operations. For detailed information see Defining Back-End Connections (for SAP Mobile Platform Server) or Defining Connectivity (for SAP Cloud Platform mobile service for development and operations).

Context

The ODataStore library interacts extensively with the OData service. One ODataStore instance interacts with one OData source: If a SAP Mobile Platform Server-hosted application is defined with two or more back-end URLs (whitelisted connections), a separate ODataStore instance is required for each. Pass in the URL as a java.net.URL, which must be the baseURL of the OData service. The HttpConversationManager is the network layer, which handles the authentication challenges, and can be configured manually or by using the MAFLogonManager. The OnlineODataStore hides many of the complexities of interacting with the OData source, and internally uses an OData parser.

Procedure

  1. Opening an Online Store requires HttpConversationManager, which you configure with the MAF Logon configurator:
    IManagerConfigurator configurator = LogonUIFacade.getInstance().getLogonConfigurator(context);
    HttpConversationManager manager = new HttpConversationManager(context);
    configurator.configure(manager);
    
  2. Open an OnlineODataStore. There are two methods to open the OnlineODataStore (one for synchronous and one for asynchronous):
    //synchronous
    public static OnlineODataStore open(Context context, URL url, HttpConversationManager conversationManager,
    	OnlineStoreOptions options) throws ODataException 
    
    
    //asynchronous
    public static ODataStoreOpenExecution open(Context context, URL url, HttpConversationManager conversationManager,
    	OpenListener openListener, OnlineStoreOptions options) throws ODataException 
    
    Using the JSON format greatly reduces network traffic:
    //Use options to configure the store to send the request payload in JSON format
    OnlineStoreOptions options = new OnlineStoreOptions(PayloadFormatEnum.JSON);
    OnlineODataStore.open(context, baseURL, manager, openListener, options);