Does Your App Need Storage Options? Integrate BEMS Docs Service into Your Application

Android Development

Does your application open or save files? Maybe it does both.  Does it support saving files to Box?  What about SharePoint, a corporate file share or any other CMIS-based (Content Management Interoperability Services)?  It may seem like supporting all of these options would mean a lot of work.  Supporting them all individually would be just that; unless you make use of the BEMS (BlackBerry Enterprise Mobility Server) Docs Service.

The BEMS Docs Service supports all the storage options mentioned above. It exposes them using a common REST interface that you can easily access in any BlackBerry Dynamics application.  I’m going to cover a few features in this blog post, but for a full list of the BEMS Docs Service APIs, refer to the Docs REST API Documentation.

To jump straight to sample applications you can try, we have an Android sample and iOS Sample available.  Let’s walk through the Android sample called BEMSDocsServiceSample.

Discovering the Docs Service

BEMS is discoverable by BlackBerry Dynamics applications using the BlackBerry Dynamics service discovery. This isn’t specific to BEMS, but is a method any local or remote service can advertise itself.  UEM administrators have the capability to enable and disable these services for UEM users.  The first few steps use service discovery to determine if the user’s BlackBerry Dynamics environment has an active BEMS Docs service that they are entitled to use.  We query for this using the getServiceProvidersFor method.

private static final String DOCS_SERVICE = 
   "com.good.gdservice.enterprise.docs";
…

Vector<GDServiceProvider> providers = 
        GDAndroid.getInstance().getServiceProvidersFor(
            "com.good.gdservice.enterprise.docs",
            "1.0.0.0", GDServiceProviderType.GDSERVICEPROVIDERSERVER);

Constructing the Header

BEMS identifies and authenticates the user using a BD Authentication Token. The application requests a token using the destination BEMS server address.  When the BEMS server receives the requests, it connects to the BlackBerry Control server to verify the token is valid.  The token is requested using the GDUtility.getGDAuthToken(final String challenge, final String serverName, final GDAuthTokenCallback callback) method.  The sample application makes this request in its onGetAuthToken method of the DocsList class.

The BD Authentication Token is received by the application in the onGDAuthTokenSuccess callback method of the DocsList class in the sample app.  Now that it has the token, the app can add it to the HTTP requests made to the BEMS servers like this:

ArrayList<BasicHeader> headers = new ArrayList<>();
headers.add(new BasicHeader("X-Good-GD-AuthToken", gdAuthToken));

Working with the Docs Service

After receiving the BD Authentication Token, the sample application makes a REST call to BEMS to obtain a list of repositories. After adding the headers, the REST call is a pretty simple one:

https://serverName/docs/1

The BEMSDocsServiceSample keeps track of the current directory the user is viewing. This allows for easy navigation into and back out of directories in a storage system.  To view the files and folders in a storage system it appends those values to the base URL.

//Creates the request to list files in a specified directory.
private void listFiles(String path)
{
    //Check if we are going into a new directory or back a level
    if (path.contentEquals(".."))
    {
        //Going up a directory.
        //Strip off the last directory.
        pathCrumbs = pathCrumbs.substring(0, pathCrumbs.lastIndexOf('/'));
    }
    else if (path.length() > 0)
    {
        //Going into a new directory.
        //Append the requested repo/directory to the end of the current path.
        pathCrumbs += "/" + Uri.encode(path);
    }

    //Add the current path to the end of the request URL.
    String url = "/docs/1" + pathCrumbs;

    //Load the URL.
    loadUrl(url);
}

JSON is returned that lists available storage systems, or files and directories if a path is added to the end of the requested URL. BEMSDocsServiceSample parses this in the parseList method and triggers display of the result in a list shown to the user.

These basic steps should get you started with integrating the BESM Docs Service into your application. Have a look at the Docs REST API Documentation and explore the other features of these samples.

 

Join the conversation

Show comments Hide comments
+ -
blog comments powered by Disqus