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.
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 Configure adapter properties with MobileFirst Operations Console in this page.
There are two levels of properties that can be modified on-the-fly:
- In both SQL and HTTP JavaScript adapters, we can configure the predefined properties that relate to the connection policy. For a full description of all these properties, see HTTP adapter connectionPolicy element and SQL adapter connectionPolicy element.
- In all adapters, we can also configure user-defined properties. For more information about creating user-defined properties, see Create user-defined adapter properties in this page.
Parent topic: Develop the server side of a MobileFirst application
Create user-defined adapter properties
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
- Open the adapter-descriptor (adapter.xml) file for our adapter in an editor.
- 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.
- Save the adapter.xml file.
- 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:
- For JavaScript: MFP.Server.getPropertyValue (propertyName)
- For Java: ConfigurationAPI.getPropertyValue (propertyName)
See Using user-defined property values in adapter code in this page.
Configure adapter properties with MobileFirst Operations Console
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
Administrators can modify the values that are shown and save. The changes take effect immediately, without redeploying the adapter.
Sharing adapter configurations
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
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.
- In Java, use the ConfigurationAPI class. Inside your Java class, add the following at the class level:
@Context ConfigurationAPI configurationAPI ;Then we can use the configurationAPI instance to get properties:
configurationAPI.getPropertyValue ("DB_url");
When the adapter configuration is modified from the MobileFirst Operations console, the JAX-RS application class is reloaded and its init method is called again.
Note: The getServerJNDIProperty method can also be used to retrieve a JNDI property from your server configuration.
In JavaScript, use the MFP.Server.getPropertyValue(propertyName) function to retrieve properties: MFP.Server.getPropertyValue("name");