For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.


Configure adapters

Learn how we can override properties during run time, without having to redeploy adapters.


Overview

Starting with V8.0.0 of MobileFirst Server, administrators can use the MobileFirst Operations Console to modify the behavior of an adapter that has been deployed. After configuration has been modified, the changes take effect in the server immediately, without the need to redeploy the adapter, or restart the server. For more information, see Configuring adapter properties with MobileFirst Operations Console in this page.

There are two levels of properties that can be modified on-the-fly:

Parent topic: Developing the server side of a MobileFirst application


Creating user-defined adapter properties


Overview

We use a property element for each user-defined property we want to add. For more information on the property element, see property element of the JavaScript adapter XML file, or property element of the Java™ adapter XML file.


Procedure

  1. Open the adapter-descriptor (adapter.xml) file for our adapter in an editor.
  2. For each new property, add a property element to the file, as follows:

    <property name="unique-name" description="value" defaultValue="value" type="value" />

    Note: If the adapter.xml file of a JavaScript adapter contains procedure elements, the property elements must always appear below them.

  3. Save the adapter.xml file.
  4. To apply your changes and make your custom properties available in the MobileFirst Server, build your adapter and deploy it to an instance of the server.


Results

After you successfully deploy an adapter with custom properties to the server, you make the value of the properties available to the adapter code with a call to the appropriate API:

See Using user-defined property values in adapter code in this page.


Configuring adapter properties with MobileFirst Operations Console


Overview

Both the built-in connection policy properties as well as the user-defined properties can be overridden in the MobileFirst Operations Console.


Example

Assume that you have deployed a JavaScript adapter JavaSQL to MobileFirst Server. Assume that the adapter.xml descriptor file contains three user-defined properties, as follows:

<mfp:adapter name="JavaSQL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mfp="http://www.ibm.com/mfp/integration" xmlns:sql="http://www.ibm.com/mfp/integration/sql"> <displayName>JavaSQL</displayName> <description>JavaSQL</description> <connectivity> <connectionPolicy xsi:type="sql:SQLConnectionPolicy"> <dataSourceDefinition> <driverClass>com.mysql.jdbc.Driver</driverClass> <url>jdbc:mysql://localhost:3306/mydb</url> <user>myUsername</user> <password>myPassword</password> </dataSourceDefinition> </connectionPolicy> </connectivity> <!-- Procedures --> <procedure name="procedure1"/> <!-- Custom properties --> <property name="DB_url" displayName="Database URL" defaultValue="jdbc:mysql://127.0.0.1:3306/mobilefirst_training" /> <property name="DB_username" displayName="Database username" defaultValue="mobilefirst" /> <property name="DB_password" displayName="Database password" defaultValue="mobilefirst" /> </mfp:adapter> We can view the configuration settings by clicking the Configurations tab under mfp Runtime > adapter_name. The predefined connection policy parameters are displayed under Connectivity. Beneath them, under Parameters, are the user-defined properties settings. In this example, Database URL, Database username, and Database password.

Figure 1. User-defined adapter properties in the MobileFirst Operations Console

This figure shows how user-defined properties are shown in the Console.

Administrators can modify the values that are shown and save. The changes take effect immediately, without redeploying the adapter.


Sharing adapter configurations


Overview

Customized adapter properties appear in the modified adapter configuration file in the Configuration files tab of MobileFirst Operations Console. Use the configpull and configpush goals to share the custom configuration. See Maven adapter plug-in.


Using user-defined property values in adapter code


Overview

There are both Java and JavaScript server-side APIs that enable you to retrieve properties defined in the adapter.xml file or in MobileFirst Operations Console.