Bluemix application development using the bluemixContext object

To aid in the development of XPages applications running on Bluemix, a bluemixContext global object is provided.

Overview of the bluemixContext object

The bluemixContext object provides methods to retrieve information from the XPages runtime as well as connection information from any bound XPages NoSQL Database service. It does this by parsing the Bluemix VCAP_SERVICES environment variable provided by the bound service.

VCAP_SERVICES explained

You can use your Bluemix VCAP_SERVICES environment variable to retrieve the information and credentials you need to access the XPages NoSQL Database service with various Bluemix runtimes.

After you bind an XPages NoSQL Database service instance to an XPages Bluemix application, the following configuration code is added to your VCAP_SERVICES environment variable. You can see this information on your application overview page in the Bluemix user interface by clicking the tile for your runtime. You can also click "Show Credentials" on the XPages NoSQL Database tile.

{
   "XPagesData": [
      {
         "name": "myXPagesDB-XPagesData",
         "label": "XPagesData",
         "plan": "xpages-data-free",
         "credentials": {
            "apppath": "bluemix/xxxxxx/data1.nsf",
            "username": "xxxxxx”,
            "host": "169.53.5.242",
            "rootDir": "bluemix/xxxxxx/dev/",
            "servername": "CN=server_name/O=Bluemix",
            "password": "xxxxxx",
            "url":"http://xxxxxx:xxxxxx@9.39.221.87/reg/BmUsrMgr.nsf/bmUserDashboard.xsp	?
									documentId=123456&action=openDocument"
          }
       }
    ]
}

Using the bluemixContext object

As mentioned, the bluemixContext object was developed to provide methods to retrieve information from the Bluemix XPages runtime as well as connection information from any bound XPages NoSQL Database service. You can also retrieve information about hybrid applications (applications where the application data resides outside of Bluemix).

This object is available in both SSJS (Server-side JavaScript) and Java.

Available methods for this object include the following:

atHybridDbName(dbPath) : String
For use with hybrid applications. Returns a Vector value that contains the address of your private Domino server as the first element and the path to your database in the second element. This is the equivalent of using @DbName in an on-premises application, or using the atDbName method from the Bluemix Context class for an XPages application on Bluemix bound to the experimental XPages NoSQL DB service.
findHybridDatabaseName(dbPath) : String
For use with hybrid applications. Returns a String value that can be passed to the databaseName property of XPages data sources. This value will be properly formatted to point a data source to a data NSF on the private Domino server of your hybrid environment.
getAPP_HOME_URL() : String
Returns the Home URL for the application.
getAPP_INCLUDE_XPAGES_TOOLBOX() : String
Returns "true" if the Bluemix application includes the XPages Toolbox.
getAPP_JVM_HEAPSIZE() : String
Returns the heapsize of the JVM running this application.
getAPP_PRELOAD_DB() : String Returns the preload db environment variable.
Returns the preload db environment variable.
getAPP_VERBOSE_STAGING() : String
Returns the verbose staging environment variable.
getBuildPackVersion() : String
Returns the XPages buildpack version number.
getDataService() : DataService
Returns a DataService object representing a bound XPages NoSQL Database service.
getDataServiceByName(String) : DataService
Returns a named DataService object representing a bound XPages NoSQL Database service.
isDataServiceByNameExists(String) : boolean
Returns true if this application is bound to a named XPages NoSQL Database Service.
isDataServiceExists() : boolean
Returns true if this application is bound to any XPages NoSQL Database Service.
isHybridApplication() : boolean
For use with hybrid applications. Returns true if this application has been configured as a hybrid Bluemix application.
isRunningOnBluemix() : boolean
Returns true if this XPages application is running in the Bluemix environment.

The bluemixContext object also has the following methods - each of which corresponds to a Cloud Foundry environment variable. Environment variables are the means by which the Cloud Foundry runtime communicates with a deployed application about its environment.

  • GetHOME() : String
  • getMEMORY_LIMIT() : String
  • getPORT() : String
  • getPWD() : String
  • getTMPDIR() : String
  • getUSER() : String
  • getVCAP_APP_HOST() : String
  • getVCAP_APP_PORT() : String
  • getVCAP_APPLICATION() : String
  • getVCAP_SERVICES() : String

Retrieving information about the DataService object

The bluemixContext methods getDataService and getDataServiceByName return a DataService object. This object also provides methods to retrieve information about the bound XPages NoSQL Database Service from the VCAP_SERVICES environment variables mentioned before.

Available methods include the following:

  • findDatabaseName() : String
  • atDbName() : Vector<String>
  • getAppPath() : String
  • getCredentialsValue(String) : String
  • getHost() : String getLabel() : String
  • getPlan() : String
  • getRootDir() : String
  • getServerName() : String
  • getUserName() : String
  • getValue(String) : String

For more complete information on the methods and objects mentioned in this topic, refer to the IBM® Domino® Designer XPages Reference that is installed as part of the product documentation when you install Domino® Designer.