DConfig 
SourceForge.net Logo PHP Logo

Dynamic Configuration Toolkit

Web Server Setup

This page lists some examples to web server set up , DConfig-lib library set up, DConfig data access, etc.
1. Prerequisites
2. Configure Web Server to use Dynamic Configuration Toolkit
3. Launch DConfig GUI editor

1. Prerequisites      

Download dconfig-1.x-src.zip or dconfig-1.x-bin.zip, unzip them to a local folder.
If you download source code, first create a distribution by running the following commands on a terminal:

  cd dconfig-1.x-src
  ant

2. Configure Web Server to use Dynamic Configuration Toolkit      

Ant user
Copy dconfig-1.x-src/dist/dconfig-lib/*.jar or dconfig-1.x-bin/dconfig-lib/*.jar, see list below, to WEB-INF/lib.

commons-dbutils-1.0.jar
commons-lang.jar
commons-logging.jar
commons-logging-api.jar
dconfig-lib.jar
log4j-1.2.8.jar
servlet.jar
spring-beans.jar
spring-core.jar
spring-dao.jar
spring-jdbc.jar

where dconfig-lib.jar is the DConfig server side library, others are supporting libraries.

Maven user
Download the following files to a local directory:
dconfig-lib-1_2_1.jar
dconfig-lib-1_2_1.pom
install-libs.sh
install-libs.bat

Now do the following to install dconfig-lib-1_2_1.jar and dconfig-lib-1_2_1.pom to your local Maven repository:

linux-cmd $ cd /path/to/download/folder
linux-cmd $ chmod u+x install-libs.sh
linux-cmd $ ./install-libs.sh

or

windows-cmd > cd <drive:>\path\to\download\folder
windows-cmd > install-libs.bat

In your maven project, add the following dependency to project pom.xml file:

  <dependencies>
    <dependency>
        <groupId>org.moonwave.dconfig</groupId>
        <artifactId>dconfig</artifactId>
        <version>1.2.1</version>
    </dependency>
  </dependencies>

Both Ant and Maven users
Place the following lines into WEB-INF/web.xml file

Source 2-1. Place the following lines into web.xml file
<servlet>
    <servlet-name>DConfigInitServlet</servlet-name>
    <servlet-class>org.moonwave.dconfig.servlet.InitServlet</servlet-class>
    <load-on-startup>5</load-on-startup>
</servlet>

Copy the JDBC drivers for the database you're using to WEB-INF/lib according the following table:

Database or Driver Type JDBC Driver Download URL Sample JDBC Driver Jar File Name
MySQLhttp://dev.mysql.com/downloads/connector/j/5.0.htmlmysql-connector-java-3.1.13-bin.jar
mysql-connector-java-5.0.2-beta-bin.jar
Postgreshttp://jdbc.postgresql.org/download.htmlpg74.216.jdbc3.jar
postgresql-8.1-407.jdbc3.jar
postgresql-8.2-504.jdbc3.jar
Derby serverhttp://db.apache.org/derby/derby_downloads.htmlderbyclient.jar
Hsqldb serverhttp://sourceforge.net/project/showfiles.php?group_id=23316hsqldb.jar
H2 Databasehttp://www.h2database.com/h2.jar
Oracle Thin/OCIhttp://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.htmlojdbc14.jar
SQL Server 2000 (jTDS)http://jtds.sourceforge.net/jtds-1.2.jar
SQL Server 2000, 2005(Microsoft)http://msdn.microsoft.com/data/ref/jdbc/sqljdbc.jar

For example, for Derby database, copy derbyclient.jar to WEB-INF/lib; for Hsqldb server, copy hsqldb.jar to WEB-INF/lib.
You can also copy other JDBC drivers to WEB-INF/lib not listed in the above table.

Copy dconfig-1.x-src/dist/dconfig-lib/conf/dconfig_lib.properties, log4j.properties or
dconfig-1.x-bin/dconfig-lib/conf/dconfig_lib.properties, log4j.properties to WEB-INF/classes.
Merge conf/log4j.properties contents to your log4j.properties if log4j.properties file already exists.

Set up active database connection information, active.connection.prefix, and related driverClassName, url, user name, password, etc., by changing values in dconfig-lib.properties file.

For example, if set mysql as the active connection:
active.connection.prefix=mysql

then the following must be set as well:
mysql.driverClassName=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://<host>:<port3306>/<database>
mysql.username=
mysql.password=

For example, if set myDbServer as the active connection:
active.connection.prefix=myDbServer

then the following must be set as well:
myDbServer.driverClassName=
myDbServer.url=
myDbServer.username=
myDbServer.password=

Sample dconfig-lib.properties content

Source 2-2. Sample docnfig-lib.properties content
# ------------------------------------------------------------------------------
# set connection lookup key prefix.
#
# For example, if you want to use mysql as the active connection, set
# active.connection.prefix=mysql
#
# DConfig Library will use active.connection.prefix value as the leading lookup key, i.e,
# DConfig uses mysql.driverClassName to look up active driverClassName,
# DConfig uses mysql.url to look up active db url
active.connection.prefix=mysql

# ------------------------------------------------------------------------------
# Indicates whether InitServlet starts loading DConfig data from database into
# memory on start. Default true.
dconfig.InitServlet.loadOnStartup=true

# ------------------------------------------------------------------------------
# next cache loader execeution period in minutes. default is 5  minutes.
# A value of <= 0 turns off the automatical cache loading feature.
dconfig.cacheloader.taskperiod=5

##########################################
# Derby server
# JdbcDriver - http://db.apache.org/derby/derby_downloads.html
#
derbyServer.driverClassName=org.apache.derby.jdbc.ClientDriver
derbyServer.url=jdbc:derby://localhost:1527/dcfgdemo;create=true
derbyServer.username=app
derbyServer.password=app

##########################################
# MySQL
# JdbcDriver - http://dev.mysql.com/downloads/connector/j/5.0.html
#
mysql.driverClassName=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://<host>:<port3306>/<database>
mysql.username=
mysql.password=

Sample log4j.properties content

Source 2-3. Sample log4j.properties content
log4j.rootLogger=INFO, dconfig

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%d] (%F:%L) - %m%n

log4j.appender.dconfig=org.apache.log4j.RollingFileAppender

log4j.appender.dconfig.File=dconfig.log

log4j.appender.dconfig.Threshold=DEBUG
log4j.appender.dconfig.Append = true
log4j.appender.dconfig.layout = org.apache.log4j.PatternLayout
log4j.appender.dconfig.MaxFileSize=500KB
# Keep three backup files
log4j.appender.dconfig.MaxBackupIndex=3

#log4j.appender.dconfig.layout.ConversionPattern = %d{HH:mm:ss.SSS} [%t] %-5p %-30.30c{2} %x - %m %n
log4j.appender.dconfig.layout.ConversionPattern = %d %-5p %-30.30c{2} %x - %m %n

Source 2-4. How org.moonwave.dconfig.servlet.InitServlet works
package org.moonwave.dconfig.servlet;

public class InitServlet extends HttpServlet {
    
    public void init() {

        try {
            ServletContext sc = getServletContext();

            String filePath = sc.getRealPath("/WEB-INF/classes/log4j.properties");
            if (filePath != null)
                LoggerUtil.load(filePath);
            else {
                java.net.URL fileURL = sc.getResource("log4j.properties");
                if (fileURL != null)
                    LoggerUtil.load(fileURL);
            }
        } catch (Throwable e) {
            System.err.println("Log4j initialization error: " + e);
        }
        String loadOnStartup = LibProperties.getInstance().getProperty("dconfig.InitServlet.loadOnStartup");
        if (loadOnStartup.equalsIgnoreCase("true")) {
            try {
                LibInitializer.initialize(); // initialize DConfig library
                CacheManager.load(); // load DConfig data into memory
                DConfigTimerTask.start(); // config and start DConfig timer task
            } catch (Throwable e) {
                System.err.println("InitServlet error: " + e);
            }
        }
    }

    public void destroy() {
        CacheManager.unload(); // release DConfig resource
    }
}

3. Launch DConfig GUI editor      

Deploy dconfig-1.x-src/dist/dconfig-ui-jnlp/dconfig-ui-jnlp.war or dconfig-1.x-bin/dconfig-ui-jnlp/dconfig-ui-jnlp.war to your web server.

For Apache Tomcat 5.* web servers, copy dconfig-ui-jnlp.war to /path/to/tomcat-home/webapps. If you're using a web server other than Tomcat, please consult related document to see how to deploy a war file to your web server.

Apache Tomcat can be obtained from http://tomcat.apache.org/.

Source 3. JSP code to launch DConfig GUI Editor
Use the following code:

<a href="/dconfig-ui-jnlp/dconfig.jnlp"><img border=0 src="webstart_small.gif">Launch DConfig Editor</a>

if Web Server host dconfig-ui-jnlp.war on the same machine. 
Or 

<a href="http://<host>:<port>/dconfig-ui-jnlp/dconfig.jnlp"><img border=0 src="webstart_small.gif">Launch DConfig Editor</a>

if dconfig-ui-jnlp.war is hosted in a different machine