You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by carsten nichte <ca...@t-systems.com> on 2002/11/22 12:02:28 UTC

loadConfiguration() is called twice by tomcat -> exception

Hi,
During startup tomcat 3.2.4 (velocity 1.2 )  the Method 
loadConfiguration()  is called once.
All stuff  initialized very well.

Wenn i try to call the servlet with

http://localhost:8080/zerf

the loadConfiguration() is called a second time, with a Nullpointer-Exc 
in Line

String propsFile =  config.getInitParameter(INIT_PROPS_KEY); 

(The whole code-sniplet is at the bottom of this Mail)

Whats going wrong????

My Module is located in: tomcat_home/webapps/zerf/...
The class is located in:  
tomcat_home/webapps/zerf/WEB-INF/classes/zerf/znSignController.class

My web.xml:

<web-app>
    <servlet>
        <servlet-name>zerf</servlet-name>
        <servlet-class>zerf.ZnSignController</servlet-class>
      <init-param>
        <param-name>properties</param-name>
        <param-value>conf\zerf_config.properties</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
    </servlet>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
    <welcome-file>
            index.jsp
        </welcome-file>
    <welcome-file>
            index.html
        </welcome-file>
    <welcome-file>
            index.htm
        </welcome-file>
    </welcome-file-list>
</web-app>   

The loadConfiguaration Method:

    protected Properties loadConfiguration(ServletConfig config)
    throws IOException, FileNotFoundException {
       
        System.out.println("---------- Load ZERF Konfiguration: ");
       
        // web.xml auslesen:
        String propsFile =  config.getInitParameter(INIT_PROPS_KEY);
        System.out.println("Reading Path from Propertie-File from 
web.xml: " + propsFile);
      
        /* now convert to an absolute path relative to the webapp root
         * This will work in a decently implemented servlet 2.2
         * container like Tomcat.
         */
        if (propsFile != null){
            String realPath = getServletContext().getRealPath(propsFile);
            if (realPath != null) propsFile = realPath;
        }
       
        Properties p = new Properties();

        try{
            System.out.println("Load Properties from: " + propsFile);
            p.load(new java.io.FileInputStream(propsFile));
        }catch (Exception e){
            handleException(e, "Error while loading Properties");
        }

       /* now, lets get the two elements we care about, the
        * template path and the log, and fix those from relative
        * to the webapp root, to absolute on the filesystem, which is
        * what velocity needs
        */
       String path = p.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH);
 
       if (path!=null){
           path = getServletContext().getRealPath(path);
           p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
       }
 
       path = p.getProperty("runtime.log");
 
       if (path != null){
           path = getServletContext().getRealPath(path);
           p.setProperty("runtime.log", path);
       }
       
       System.out.println("Path to Templates: " + 
p.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH));
       System.out.println("Path to Log-File: " + 
p.getProperty("runtime.log"));
       System.out.println("-----------------------------------");
       return p;
       
    }