Chapter 2. Installation

Table of Contents

1. Requirements
2. Directories
3. Creating database
3.1. Derby
3.2. PostgreSQL
4. Tomcat configuration
5. RegistryOffice configuration
5.1. Data sources
5.2. Attribute mapping
5.3. Logging configuration
5.4. Access restriction configuration (Access filter)
5.5. Creating RegistryOffice.war file
5.6. Deploying RegistryOffice.war

1. Requirements

RegistryOffice is Java based application, which is usually deployed as a servlet inside the Tomcat or other compatible container. Data are stored in a relational database. For testing purposes or smaller installations embedded Derby database can be used. Application is optimized to use Postgresql as a back-end. It is possible to add support for other databases as well - appropriate database schema can be generated using Hibernate.

Table 2.1. Requirements

ComponentDescription
Tomcatrecommended minimal version is 5.5.x
Database (Derby, PostgreSQL)appropriate relational database, application can used any database compatible with hibernate 3.x


2. Directories

Application is distributed as one zip-file. To install application zip-file have to be unpack to the temporary directory.

Table 2.2. Directories

DirectoryDescription
docDocumentation
source-warSource RegistryOffice.war - without context.xml
sqlSQL scripts, database schema
tomcatConfiguration files for Tomcat
utilsUtility files: derby, generator, zip

3. Creating database

Next step is to create database structure. At this point we expect that there is existing Tomcat installation. If you did not install Tomcat, please do it.

SQL scripts are stored in the directory sql. There are two subdirectories for Derby and Postgresql database. Each directory contains script schema.xml which defines database structure. This script is database specific. There are two common scripts admin.sql (creates first user is database - administrator) and data.sql (example of values for various code lists)

3.1. Derby

There are scripts create (for Linux/Unix) and create.bat (for Win32) to create and initialize database. It is possible to accommodate these scripts as needed. Database script schema.sql will create database structure and admin.sql will first user.

Database drivers have to be accessible from the Tomcat installation. Please copy them to the directory [tomcat]/common/lib. Required files: derby.jar, derbytools.jar. It is possible to user the latest Derby distribution or files from the directory utils/derby.

3.2. PostgreSQL

New database can be created using command line tools or visual tools as pgadmin3. After creating database please add schema from postgresql/schema.sql and first user as shown in the file admin.sql.

Database driver have to be accessible from the Tomcat installation. Please copy file postgresql-jdbc3.jar from the postgresql installation to the directory [tomcat]/common/lib.

4. Tomcat configuration

There have to be defined data source in the Tomcat which will be used by application. This can be done manualy or using administration tool. Example of data source configuration is in the file tomcat/server.xml.resource for manual configuration.

Data source configuration should be placed insided tag <GlobalNamingResources>

Note

If you want to use Derby in embedded mode it have to be started before any database connection is created. Copy files from tomcat/derbyLoader to the directory [tomcat]/server/classes and add following line to the [tomcat]/conf/server.xml

<Listener className="LightComp.Derby.CatalinaLoader"
          cacheSize="10000"/>

Example 2.1. Resource configuration for Derby

    <Resource
      auth="Container"
      description="Registry office"
      name="jdbc/RegistryOfficeDB"
      type="javax.sql.DataSource"
      driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
      maxIdle="2"
      maxWait="20000"
      url="jdbc:derby:C:/karel/registryofficerepository/db;create=true"
      maxActive="10"/>

Example 2.2. Resource configuration for PostgreSQL

    <Resource
      auth="Container"
      description="Registry office"
      name="jdbc/RegistryOfficeDB"
      type="javax.sql.DataSource"
      password="rx12qw"
      driverClassName="org.postgresql.Driver"
      maxIdle="2"
      maxWait="20000"
      username="registryoffice"
      url="jdbc:postgresql://127.0.0.1:5432/ro"
      maxActive="10"/>

5. RegistryOffice configuration

RegistryOffice requires to configure several items:

  • data source

    attribute mapping

    logging file

First two configurations are stored in the file context.xml. Template of this file is in the directory doc.

<Context path="/RegistryOffice" reloadable="true">
  <ResourceLink
    global="jdbc/RegistryOfficeDB"
    name="jdbc/RegistryOfficeDB"
    type="javax.sql.DataSource"/>
  
  <Resource
      auth="Container"
      description="Golem"
      name="jdbc/GolemDB"
      type="javax.sql.DataSource"
      password="golem"
      driverClassName="org.postgresql.Driver"
      maxIdle="2"
      maxWait="20000"
      username="golem"
      url="jdbc:postgresql://10.2.0.3:5432/GolemSimulation"
      maxActive="10"/>


    <Parameter name="DocumentIdAttribute" value="CJ"/>
    <Parameter name="BatchIdAttribute" value="Scan.BatchId"/>
    <Parameter name="AgencyIdAttribute" value="Scan.Agency"/>

</Context>

5.1. Data sources

There are two data sources.

RegistryOffice data source is configured as link to the globaly defined resource. Name of resource must be jdbc/RegistryOfficeDB. Change value of attribute global to point to the global resource defined in the [tomcat]/config/server.xml.

Golem data source is connection to database of Golem system. Name of resource must be jdbc/GolemDB. Change value of attributes url,username,password to point to Golem database. JDBC dirvers for Golem database must be on classpath.

5.2. Attribute mapping

Three attributes have to be defined for each document entering RegistryOffice:

Table 2.3. Attributes

DocumentIdAttributeUnique identificator of each document
BatchIdAttributeIdentificator of batch. This is used to group documents together. If you does not need this value it can be set to same value for all documents.
AgencyIdAttributeIdentificator of source agency.

Mapping of these attributes depends on the master information system and used values. Documents without these attributes will be revoked.

5.3. Logging configuration

Logging configuration is stored in file logging.properties. Template of this file is in directory doc.

handlers = 1registryoffice.org.apache.juli.FileHandler

1registryoffice.org.apache.juli.FileHandler.level = FINE
1registryoffice.org.apache.juli.FileHandler.directory = c:/registryoffice/logs
1registryoffice.org.apache.juli.FileHandler.prefix = damis

com.lightcomp.registryoffice.handlers = 1registryoffice.org.apache.juli.FileHandler

Value of the 1registryoffice.org.apache.juli.FileHandler.directory property must be set to full logging directory path.

5.4. Access restriction configuration (Access filter)

Registry office can receive requests to store new document or delete document from external system. These requests are accepted via http protocol. From security reasons it is feasible to restrict access to this functionality. Access can be restricted only to some computers by using access filter. Access filter reject requests not comming from listed ip adresses. To use access filter add following sections to web.xml file.

<filter>
    <filter-name>Access filter</filter-name>
    <filter-class>com.lightcomp.registryoffice.authentication.AccessFilter</filter-class>
        <init-param>
            <param-name>addresses</param-name>
            <param-value>10.2.0.6/255.255.255.255,127.0.0.1/255.255.255.255</param-value>
        </init-param>
</filter>


<filter-mapping>
    <filter-name>Access filter</filter-name>
    <url-pattern>/upload</url-pattern>
</filter-mapping>

Parameter adresses can contain coma separated list of ip addresses of computers in fomat IP/MASK.

5.5. Creating RegistryOffice.war file

Last step before deploying new application is to create file RegistryOffice.war. There are two scripts to create this file:

  • generate-war - Linux, Unix

  • generate-war.bat - Windows

generate-war <context.xml> <logging.properties> <hibernate.cfg.xml>

Script expects path to the properly configured context.xml, logging.properties and hibernate.cfg.xml. These files will be added to the RegistryOffice.war.

hibernate.cfg.xml is database specific file. Preconfigured files are in the distribution for Derby and PostgreSql.

5.6. Deploying RegistryOffice.war

To deploy new application to the server log as a manager to the Tomcat. Select RegistryOffice.war and choose Deploy.

Running application can be access using url: http://127.0.0.1:8080/RegistryOffice