Helma Logo
main list history
previous version  overview  next version

Version 5 by tobi on 11. December 2008, 14:58

Besides configuring servlets and contexts in Jetty with an XML file conforming to a special syntax proprietary to Jetty the servlet API provides a more standard approach with so-called web applications and web.xml.

This approach provides further control of defining contexts and additional features like e.g. filters. AFAIK, it was developed for easier deployment and exchange of such web applications between different server/servlet engines; but as all of this was designed for the mystical realm of the so-called Java enterprise edition (J2EE) I am only an educated boy making educated guesses.

Following are the basic steps to define a web application with Jetty and Helma 1.x.

=== Prerequisites

* *Patched Helma|http://dev.helma.org/wiki/Configuring+Jetty+in+Helma+1.x/* for running Jetty with XML configuration
* <a href="http://jetty.cvs.sourceforge.net/viewvc/\*checkout\*/jetty/Jetty/ext/jasper-runtime.jar?revision=1.13">jasper-runtime.jar</a> and <a href="http://jetty.cvs.sourceforge.net/viewvc/\*checkout\*/jetty/Jetty/ext/jasper-compiler.jar?revision=1.13">jasper-compiler.jar</a>

Copy the two Jasper JAR files into the lib/ext directory of your Helma installation.

=== Setting up jetty.xml

Before starting up Helma we need to define the web application in jetty.xml. For a start we take the manage application as example:

    <Call name="addWebApplication">
      <Arg>
        /manage
      </Arg>
      <Arg>
         /path/to/helma/apps/manage./apps/manage
      </Arg>
  </Call>

You could simply add the snippet above to the *example jetty.xml|http://dev.helma.org/wiki/Configuring+Jetty+in+Helma+1.x/* but of course it also should work with only one listener and with different settings as well.

In fact, the main configuration of the application takes place in a another XML file called <code>web.xml</code> that needs to be stored in a special directory under in <code>./apps/nameOfHelmaApp</code> /apps/manage</code> (according to our example) – the infamous <code>WEB-INF</code> directory.

In the case of the manage application this is the full path would be <code>/path/to/helma/apps/manage/WEB-INF/web.xml</code>, although it works with any other path as well as long as it is correctly defined in the second argument of <code><Call name="addWebApplication"></code> (ie. without the <code>WEB-INF/web.xml</code> part which is appended automatically).

=== Setting up web.xml

As already mentioned, web applications and their XML configuration syntax span another whole new world which I find extraordinarily hard to get adequate documentation forfor (except one likes to take on *Sun's official DTD|http://java.sun.com/dtd/web-app_2_3.dtd*). Here is a quite good one, actually written as *web.xml reference guide for Tomcat|http://wiki.metawerx.net/wiki/Web.xml*.

For setting up a Helma application a the very reduced basic configuration looks like this:

  <?xml version="1.0" encoding="ISO-8859-1"?>
  <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
  <web-app>
      <display-name>
        test
      </display-name>
      <servlet>
        <servlet-name>
            manage
        </servlet-name>
        <servlet-class>
            helma.servlet.EmbeddedServletClientStandaloneServletClient
        </servlet-class>
        <init-param>
            <param-name>
              application
            </param-name>
            <param-value>
              manage
            </param-value>
        </init-param>
        <init-param>
            <param-name>
              appdir
            </param-name>
            <param-value>
              ./apps/manage
            </param-value>
        </init-param>
        <init-param>
            <param-name>
              dbdir
            </param-name>
            <param-value>
              ./db/manage
            </param-value>
        </init-param>
        <!-- init-param>
            <param-name>
              cookieDomain
            </param-name>
            <param-value>
              .domain.tld
            </param-value>
        </init-param -->
      </servlet>
      <servlet-mapping>
        <servlet-name>
            manage
        </servlet-name>
        <url-pattern>
            /*
        </url-pattern>
      </servlet-mapping>
  </web-app>

This defines the Helma manage application as a web application which will be displayed as "test" (e.g. in the list of available contexts) and which will be mounted under the context path defined in jetty.xml (<code>/manage</code>) considering the URL pattern <code>/*</code>.

Thus, everything located under <code>/manage/*</code> will be delegated to the manage application.

To get an idea how further servlet options are defined I included the setting of <code>cookieDomain</code> in comments. Anything, that can be set in the initialization of the <code>helma.servlet.EmbeddedServletClient</code> StandaloneServletClient</code> class can be defined accordingly.

=== Cave at

I noticed that everytime I start up Helma with a web application context I get an exception on shutdown:

  Exception in thread "Thread-3" java.lang.NullPointerException
at helma.util.Logging.closeAll(Logging.java:167)
at helma.util.Logging.shutdown(Logging.java:159)
at helma.main.Server.stop(Server.java:543)
at helma.main.HelmaShutdownHook.run(HelmaShutdownHook.java:36)

     removed
     added