OOP-ResearchMake It Simpler by Object Oriented Programming

OOP ConfigPerHost API: Flexible configuration for each host header

Apache Tomcat behind the Apache web server (HTTP daemon) can accept the HTTP request for more than one host. And the initialization parameters must be defined for each host header.
For some set of initialization parameters, the different values should be set for each host, when the single instance of Tomcat accepts the HTTP requests to multiple hosts. But, as for another set of initialization parameters, you may want to set the same value for all the hosts. By this API, both of these types of initialization parameters can be defined in the single XML. In addition to the typical types of values, such as int or String, the XML can define the Set and arrays of them. And this API implements the methods to get the initialization parameters in the Set or arrays.

Related Pages:


Same Servlet for more than one host ...

When connect to Jakarta Apache Tomcat via mod_jk module, Apache web server can redirect the HTTP request to the Servlet on Tomcat. And the Servlet on Tomcat, that is listening the request at the local host, can accept the HTTP request to multiple hosts.
The configuration file (server.xml) for Tomcat 4 will look like this:



    <Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
               port="8009"
               address="127.0.0.1"
               minProcessors="5"
               maxProcessors="75"
               acceptCount="10"
               debug="0"/>

    <Engine name="Standalone" defaultHost="localhost" debug="0">

      <Host name="localhost" debug="0"
       appBase="/home/foo/webapps/example01"
       autoDeploy="false">


This feature is useful when you deploy the same web application for multiple hosts, because you can avoid th duplicate installation of the same web application that results in the unnecessary consumption.

Go Site Map

Initialization parameters per host by XML

Based on the host header in HTTP request, you may want to set the different values for the same initialization parameter. The XML in this case will look like this:



<config-per-host>

   <config>
      <host>foo.com</host>
         <string>
            <key>title4website</key>
            <value>Title for foo.com</value>
         </string>
         <int>
            <key>price</key>
            <value>50</value>
         </int>
         <double>
            <key>vat</key>
            <value>0.10</value>
         </double>
         <boolean>
            <key>debug</key>
            <value>true</value>
         </boolean>
   </config>

   <config>
      <host>bar.com</host>
         <string>
            <key>title4website</key>
            <value>Title for bar.com</value>
         </string>
         <int>
            <key>price</key>
            <value>100</value>
         </int>
         <double>
            <key>vat</key>
            <value>0.20</value>
         </double>
         <boolean>
            <key>debug</key>
            <value>false</value>
         </boolean>
   </config>

</config-per-host>


For some initialization parameters, you may want the same values to be shared among all the hosts. The following fragment shows how to define the initialization parameters for this case.



<config-per-host>

   <config>
      <host>.</host>
         <string>
            <key>copyright</key>
            <value>2005</value>
         </string>
   </config>

</config-per-host>


The initialization parameters can be defined across the multiple XML, i.e. you can prepare as many XML as you like. The series of file names should look like this:

  • WEB-INF/classes/config-per-host-0.xml
  • WEB-INF/classes/config-per-host-1.xml
  • WEB-INF/classes/config-per-host-2.xml

This feature enables you to allocate the single XML for each host.

Go Site Map

Initialization parameters in Set and arrays

In addition to String and the typical primitive types, XML can define the Set and arrays of them. For instance, you can get the Set for String by one of the methods listed below:

  • getStringSet(HttpServletRequest req,String key)
  • getStringSet(String host,String key)
  • getStringSetForAllHosts(String key)

Or, you can get the int array by one of:

  • getIntValueArray(HttpServletRequest req,String key)
  • getIntValueArray(String host,String key)
  • getIntValueArrayForAllHosts(String key)

Note that only getXyzValueArray(...) methods are available for the primitive types.

Go Site Map

Download

This API is now a part of Bento framework. There are the better documentations and source code examples on the web site for Bento framework. There, you will also find the link to download the entire framework or each API in it.

Caution!
All the APIs for Servlet/JSP introduced by this web site are now included in Bento framework:
  • Simpler than JSTL or Apache Struts
  • MVC framework by HTML
  • Input validation from CGI FORM
  • Easy user authentication
  • Easy localization (L10n)
To download the APIs and source code examples, please visit the web site of Bento framework.


JBuilder 2007


General Information

For Java Development

Java and all Java-based trademarks and logos are trademarks or registered of Sun Microsystems, Inc. in the United States and other countries.


ALL CONTENTS COPYRIGHT 1997-2007, OOP-Research Corporation. All rights reserved.