Using Afaria to Provision Configuration Data

You can use Afaria to provision configuration data for a SAP Mobile Platform application, including the SAP Mobile Server server name, port number, and other parameters.

To use these APIs you must provide the application to the device through an Afaria application policy. When setting up such an application policy, the Afaria administration interface provides an option to add configuration data to the policy as text or binary.

The following is an an example of the Afaria administration screen for an application policy that provides an application named "CertsOnBoard" to an enrolled device. The "Configuration" tab shows the configuration data provided to the application.

In this case, the configuration information is added using the administration user interface, but it can also be provided as a text or binary file. The example shows plain text, but you can also provide the information as XML or JSON text for easier parsing by the application.


Afaria admin console

You can obtain configuration data for your application using Afaria by calling the following API from the com.sybase.afaria.SeedDataAPI class (in AfariaSSL.jar).

String com.sybase.afaria.SeedDataAPI.retrieveSeedData(SeedDataCredentials arg0) throws SeedDataAPIException

To access this data, the application provides SeedDataCredentials to the retrieveSeedData API. If the device is correctly enrolled to Afaria, the API returns a string which contains the full path to a file in the application's sandbox with the seed data.

SeedDataCredentials sdc = new SeedDataCredentials(“supadmin”,”xnetqa”,”abc”);
String result = SeedDataAPI.retrieveSeedData(sdc);
resultText.append(“the seed data file: ” + result);
BufferedReader reader = null;
Map<String, String> keyValues = null;
try
{
  reader = new BufferedReader(new FileReader(result));
  String line = null;
  keyValues = new java.util.HashMap<String, String>();
  while ((line = reader.readLine()) != null)
  {
    resultText.append(line + "\r\n");
    String[] strs = line.split(":");
    if(strs.length == 2)
    {
      keyValues.put(strs[0], strs[1]);
    }
  }
    			
}

catch(Exception ex)
{
  throw new RuntimeException(ex);
}
finally
{
  if(reader != null)
  {
    reader.close();
  }
}
    		
//set the download configuration to application connectionProperties
Application app = Application.getInstance();
ConnectionProperties appConnections = app.getConnectionProperties();
appConnections.setServerName(keyValues.get("server"));
appConnections.setPortNumber(Integer.parseInt(keyValues.get("port")));
appConnections.setUrlSuffix(keyValues.get("URL Suffix"));
appConnections.setFarmId(keyValues.get("Farm ID"));

resultText.append("server name is set to: " + appConnections.getServerName() + "\r\n");
resultText.append("server port is set to: " + appConnections.getPortNumber() + "\r\n");
resultText.append("url suffix is set to: " + appConnections.getUrlSuffix() + "\r\n");
resultText.append("farm id is set to: " + appConnections.getFarmId() + "\r\n");

The Textview output is:

the seed data file: data/data/com.app/files/seedData/SUPOnboardingSeedData.txt
server: relayserver.sybase.com
port: 80
URL Suffix: /ias_relay_server/client/rs_client.dl
Farm ID: example.exampleMBS
server name is set to: relayserver.sybase.com
server port is set to: 80
url suffix is set to: /ias_relay_server/client/rs_client.dl
farm id is set to: example.exampleMBS

For more information on the Afaria APIs and the meanings of return codes, see the Afaria documentation.