Skip to Content

Using the ODP APIs to connect to the Gateway and retrieve a service document, requires the implementing application to set credentials like host, port, company id etc. It is cumbersome for the users to keep track of these credentials all the time and deteriorates the overall  user experience. In order to overcome this Afaria server was implemented.

                                                                                          

Each app uploaded onto the Afaria server is associated with a seed file, which contains key value pairs of individual parameters delimited by a “;”. (The default delimiter used in ODP is ; but any delimiter could be use).

 

The seed file can be used to mainly store parameters like  host, port, company id , but can also be used be used to store secondary parameters like security configuration etc.  An application can access the contents of the seed file by making a call to the Afaria server through the Afaria client installed on the mobile device.

 

The API getSettingsFromAfariaWithURL was provided with the aim of retrieving the settings which are stored in the seed file for further use by the app.

 

Also, we have introduced getters to retrieve values for retrieving Farm ID, Port, Server and also a method to check if the server’s public key is provisioned.

 

1.   Method Signatures

1.1.                     iOS

1.1.1.      (NSMutableDictionary *) getSettingsFromAfariaWithUrl: (NSURL *) configurationUrl    UrlScheme๐Ÿ™NSString *)urlScheme

 

The API getSettingsFromAfariaWithURL is part of the LiteSUPUserManager in iOS takes two parameters

1)      Configuation URL

The configuration URL that is called to get the settings that were stored.

2)      URL Scheme

URL scheme of the calling application.

 

This API returns a NSMutableDictionary containing all the contents stored in the seed file as key-value pairs.

 

Code Snippet:

The calls to the Afaria server need to be made twice in application.

First, at anypoint in the application. This calls the Afaria server in which the seed file is located

Secondly, in the AppDelegate once the url is received from the Afaria client.

The first call can be made anywhere in the program.

LiteSUPUserManager* manager = [LiteSUPUserManager getInstance: :@”NewFlight”];

[manager setDelegate:self];

NSMutableDictionary *settings = [manager getSettingsFromAfariaWithUrl:nil UrlScheme:@”BASEAPP”];

 

In the AppDelegate once we receive the url from the AfariaClient, the second call is made:–  (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

                LiteSUPUserManager* userManager = [LiteSUPUserManager getInstance:@”NewFlight”];

NSMutableDictionary *map;

                @try{

                                //call the API again passing the URL this time

map = [userManager getSettingsFromAfariaWithUrl:url UrlScheme:@”BASEAPP”];

                                for(id key in map) {

                                //read the settings got from Afaria

                                id value = [map objectForKey:key];

                                }

                }@catch (NSException *exception) {

                                NSLog(@”%@ “,[[exception userInfo] objectForKey:@”ErrorCode”]);

                }

                return YES;

}

               

 

1.1.2.      (NSString *) getServer

getServer is part of the LiteSUPAppSettings class. This returns an NSString which contains the server IP.

Code Snippet:

// This method returns the SUP server host name.

 NSString *server =  [LiteSUPAppSettings getServer];

 

 

1.1.3.      (int) getPortNumber

getPortNumber is part of the LiteSUPAppSettings class. This returns an int which contains the port on the SUP server to which the client should connect.

Code Snippet:

// This method returns the port number on the SUP server to which the client should connect.

 int portNO = [LiteSUPAppSettings getPortNumber];

 

 

1.1.4.      (NSString *) getFarmId

getFarmId is part of the LiteSUPAppSettings class. This returns an NSString which contains the server IP.

 

Code Snippet:

// This method returns the Farm ID of the SUP server.

NSString *farmID = [LiteSUPAppSettings getFarmId];

 

 

1.1.5.      (BOOL) isSUPKeyProvisioned

isSUPKeyProvisioned is part of the LiteSUPAppSettings class. This returns a BOOL which can be used to check if the SUP server’s public key has been provisioned and returns ‘true’ if the key is provisioned, else returns ‘false’.

Code Snippet:

// This method can be used to check if the SUP server’s public key has been provisioned. returns ‘true’ if the key is //provisioned, else returns ‘false’.

 BOOL isKeyProvisioned = [LiteSUPAppSettings isSUPKeyProvisioned];

1.2.                     Android

1.2.1.      public static Hashtable getSettingsFromAfaria() throws SeedDataAPIException, IOException

 The API getSettingsFromAfariaWithURL() is part of the LiteSUPUserManager in Android.

The API returns a hashtable containing the key-value pairs which were stored in the seed file.

 

In Android, the method getSettingsFromAfaria() is available statically and hence can be called using the Class name.

Code Snippet:

Hashtable settings_table =  LiteUserManager.getSettingsFromAfaria();

 // Get all values

   for (Enumeration e = settings_table.keys(); e.hasMoreElements();)

    {

                //logging the fetched information

                System.out.println(“Afaria”,”Afaria values”+settings_table.get(e.nextElement()));

    }

 

1.2.2.       public static String getServer() throws MessagingClientException

The API getServer() is part of the LiteAppSettings in Android. This returns an String which contains the server IP.

Code Snippet:  

 // This method returns the SUP server host name.

String server = LiteAppSettings.getServer();

 

1.2.3.      public static int getPortNumber() throws MessagingClientException

The API getPortNumber() is part of the LiteAppSettings in Android. This returns an int which contains the port on the SUP   server to which the client should connect.

Code Snippet:

// This method returns the port number on the SUP server to which the client should connect.

Int portNo = LiteAppSettings.getPortNumber();

 

1.2.4.      public static String getFarmID() throws MessagingClientException

The API getFarmID() is part of the LiteAppSettings in Android. This returns a String which gives the Farm ID of the SUP server.

Code Snippet:

// This method returns the Farm ID of the SUP server.

String farmID = LiteAppSettings.getFarmID();

 

 

1.2.5.      public static boolean IsSUPKeyProvisioned() throws MessagingClientException

The API IsSUPKeyProvisioned() is part of the LiteAppSettings in Android. isSUPKeyProvisioned is part of the AppSettings class. This returns a boolean which can be used to check if the SUP server’s public key has been provisioned and returns ‘true’ if the key is provisioned, else returns ‘false’.

Code Snippet:

// This method can be used to check if the SUP server’s public key has been provisioned. returns ‘true’ if the key is //provisioned, else returns ‘false’.

boolean isKeyProvisioned = LiteAppSettings.IsSUPKeyProvisioned();

1.3.                     Blackberry

1.3.1.      public static Hashtable getSettingsFromAfaria() throws SeedDataAPIException, IOException

The API getSettingsFromAfariaWithURL() is part of the LiteSUPUserManager in Android. The API returns a  hashtable containing the key-value pairs which were stored in the seed file.

 

In Blackberry, the method getSettingsFromAfaria() is available statically and hence can be called using the Class name.

Code Snippet:

Hashtable settings = UserManager.getSettingsFromAfaria();

Enumeration it = settings.keys();

// Get all values

while (it.hasMoreElements())

{

               String key = (String)it.nextElement();

System.out.println (“key, value “+ “:” + key +”,” + (String)settings.get(key));

 }

 

 

1.3.2.      public static String getServer() throws MessagingClientException

  The API getServer() is part of the AppSettings in Android. This returns an String which contains the server IP.

 

Code Snippet:

// This method returns the Farm ID of the SUP server.

String farmID = AppSettings.getServer();

 

 

1.3.3.      public static int getPortNumber() throws MessagingClientException

  The API getPortNumber() is part of the AppSettings in Android. This returns an int which contains the port on the SUP   server to which the client should connect.

Code Snippet:

// This method returns the port number on the SUP server to which the client should connect.

int portNo = AppSettings.getPortNumber();

 

1.3.4.      public static String getFarmID() throws MessagingClientException

 The API getFarmID () is part of the AppSettings in Android. This returns a String which gives the Farm ID of the SUP server.

 

Code Snippet:

// This method returns the Farm ID of the SUP server.

String farmID = AppSettings.getFarmID();

 

 

1.3.5.      public static boolean IsSUPKeyProvisioned() throws MessagingClientException

The API IsSUPKeyProvisioned() is part of the AppSettings in Android. isSUPKeyProvisioned is part of the AppSettings class. This returns a boolean which can be used to check if the SUP server’s public key has been provisioned and returns ‘true’ if the key is provisioned, else returns ‘false’.

 

Code Snippet:

// This method can be used to check if the SUP server’s public key has been provisioned. returns ‘true’ if the key is //provisioned, else returns ‘false’.

boolean isKeyProvisioned =  AppSettings.IsSUPKeyProvisioned();

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. suresh babu

    Hi Sujith Prathap

    Nice document..

    i Have small doubt

    when i am using below code

    Hashtable settings_table =  LiteUserManager.getSettingsFromAfaria();

    i am getting “LiteUserManager cannot resolved” syntax error in android project.

    which import having LiteUserManager class?

    Thanks in advance

    suresh

    (0) 

Leave a Reply