Initializing Configuration using Property Bundles
To initialize the configuration using property files, you have to import the ConfigurationManager of Canvas and invoke the initializeFromBundle API to initialize it from the bundle.
Step 1: Import the Configuration Manager class
import com.intellectdesign.canvas.config.ConfigurationException; import com.intellectdesign.canvas.config.ConfigurationManager;
Step 2: Trigger the initialize method
ConfigurationManager configMgr = ConfigurationManager.getInstance(); configMgr.initializeFromBundle("<PROPERTIES_FILE_NAME>");
Assuming that your CT configuration file name is MyImplementation.properties, the syntax to instantiate the bundle is as follows:
ConfigurationManager configMgr = ConfigurationManager.getInstance(); configMgr.initializeFromBundle("MyImplementation");
That is it! This initializes the Canvas system with the configuration as provided in the bundle MyImplementation.properties loaded from the class path
Initialization of Canvas Configuration must be done before any user or system requests reach the Canvas application. Hence, it is suggested to include the initialization of the Canvas Configuration as a start up listener or start up Servlet of the application.
This initialization sequence throws a ConfigurationException if there are any errors while loading the configuration. This can be typically handled to throw an exception to stop your application from loading. The following is a sample code snippet for the exception:
try { config= ConfigurationManager.getInstance(); config.initializeFromBundle("MyImplementation"); } catch(ConfigurationException e) { LOGGER.error("Configuration system not initialized properly. Cannot service request.", e); throw new ServletException("Error while initializing configuration",e); }