Integrating IBM MobileFirst on Bluemix Containers with Bluemix Services

IBM MobileFirst Platform Foundation v7.1 is enabled to run on IBM Bluemix using the IBM Containers.

For more information on this feature, refer to the links mentioned in the references below. This feature also allows integration of MobileFirst Platform Foundation Server with IBM Bluemix services. This article discusses the integration using the IBM Bluemix SQLDB Service while we can use the same approach to integrate with other services too. The MobileFirst adapters can be used to expose secure and monitored mobile friendly endpoints to mobile applications which can then be accessed via the MobileFirst Client SDK API. These adapters can be used to expose Bluemix services like Data management services, Watson services as MobileFirst endpoints for easy consumption by mobile clients.

missing_alt

As illustrated in the above diagram, we use the MobileFirst Java adapter to access the SQLDB service. This involves the following steps:

  1. Create a Bluemix application and add the SQLDB Service to the Bluemix application.The application created here is just a holder to be able to interact with the SQLDB service. Instructions here
  2. Use the SQLDB console to generate the DB Schema and tables as per your requirements
  3. Bind the Bluemix application to the IBM MobileFirst Platform Foundation Container before starting the container
  4. Build the adapter to access the SQLDB, deploy to the IBM MobileFirst Platform Server on IBM Containers

Building the adapter: VCAP_SERVICES to the rescue

The VCAP_SERVICES environment variable provides the adapter with the information of the SQLDB service bound to the IBM MobileFirst Platform Foundation Container running on Bluemix. The following code illustrates parsing the VCAP_SERVICES environment variable to retrieve the details of the SQLDB service bound to the container.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
String user = null;
String password = null;
String jdbcurl = null;
String VCAP_SERVICES = System.getenv("VCAP_SERVICES");
if (VCAP_SERVICES != null) {
    JSONObject vcapServices = (JSONObject) JSON.parse(VCAP_SERVICES);
    String sqlDbKey = null;
    Set<String> keys = vcapServices.keySet();
    for (String key : keys) {
        if (sqlDbKey == null && key.toUpperCase().contains("SQLDB")) {
            sqlDbKey = key;
        }
    }
    if (sqlDbKey != null) {
        JSONArray list = (JSONArray) obj.get(sqlDbKey);
        JSONObject sqlDbService = (JSONObject) list.get(0);
        sqlDbService = (JSONObject) sqlDbService.get("credentials");
        jdbcurl = (String) sqlDbService.get("jdbcurl");
        user = (String) sqlDbService.get("username");
        password = (String) sqlDbService.get("password");
    }
}

Now we can use the standard JDBC programming model to connect to the SQLDB instance and perform SQL operations

1
2
3
4
Class.forName("com.ibm.db2.jcc.DB2Driver");
Connection conn = DriverManager.getConnection(jdbcurl, user, password);
Statement stmt = db.createStatement();
ResultSet rs = stmt.executeQuery(....);

Authors:

Srinivasan Nanduri, Developer, IBM MobileFirst Platform
Srikanth K Murali, Developer, IBM MobileFirst Platform

References:

IBM MobileFirst Platform Foundation on IBM Bluemix
Getting Started Tutorials - IBM MobileFirst Platform Foundation on IBM Bluemix

Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on May 01, 2016