| Geronimo_MoinMoin_wiki > Tomcat |
Contents
The Tomcat integration is made up of a set of GBeans that represent the different Tomcat components (i.e. Container, Connectors, Engine, Host, Valves, etc). The top level and managing component, the org.apache.geronimo.tomcat.TomcatContainer class is the Tomcat GBean (aka service) of Apache Geronimo. The integration includes its own Tomcat deployer which allows custom configuration of Tomcat.
The GBean implementation provides for true integration with Geronimo, allowing Tomcat to fully utilize Geronimo security (JACC/JAAS), transactions, initial contexts, webservices, and JNDI. The Tomcat integration currently supports the just mentioned Geronimo functions, but also leverages Tomcat facilities, such as virtual hosts and SSL.
There is one major difference in the Geronimo/Tomcat integration that should be noted. There are no server.xml or context.xml files. These have been replaced by the j2ee-server-tomcat-plan.xml and geronimo-tomcat.xml files. The j2ee-server-tomcat-plan.xml is the equivalent of the server.xml file and contains many of the components that its Tomcat cousin offers, albeit in a different format. The geronnimo-tomcat.xml file is the equivalent of the context.xml and is used in the web application for runtime deployment and configuration of the web application.
The j2ee-server-tomcat-plan.xml is essentially the equivalent of the server.xml. In Tomcat, the server.xml file is used to describe the Tomcat container configuration for deployment of web applications. It allows you to configure the Engine, the Hosts (for virtual hosting), Valves, Realms, etc. The file is a hierarchical representation of these items in XML format. The following is an example server.xml file:
<Server port="8005" shutdown="SHUTDOWN">
<Service name="Geronimo">
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
<Engine name="Geronimo" defaultHost="localhost">
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="localhost" appBase="webapps"/>
</Engine>
</Server>
</Server>
The j2ee-server-tomcat-plan.xml file is similar in structure (i.e. hierarchical dependency) as the server.xml, but uses GBeans and reference dependencies instead. Here is an example snippet from the j2ee-server-tomcat-plan.xml file:
<gbean name="TomcatWebContainer" class="org.apache.geronimo.tomcat.TomcatContainer">
<attribute name="catalinaHome">var/catalina</attribute>
<reference name="engineGBean">
<name>TomcatEngine</name>
</reference>
<reference name="ServerInfo">
<module>org/apache/geronimo/System</module>
<name>ServerInfo</name>
</reference>
</gbean>
<gbean name="TomcatWebConnector" class="org.apache.geronimo.tomcat.ConnectorGBean">
<attribute name="initParams">
port=8090
</attribute>
<reference name="TomcatContainer">
<name>TomcatWebContainer</name>
</reference>
</gbean>
<!-- Engine -->
<gbean name="TomcatEngine" class="org.apache.geronimo.tomcat.EngineGBean">
<attribute name="className">org.apache.geronimo.tomcat.TomcatEngine</attribute>
<attribute name="initParams">
name=Geronimo
defaultHost=localhost
</attribute>
<reference name="realmGBean">
<name>TomcatJAASRealm</name>
</reference>
<reference name="TomcatValveChain">
<name>FirstValve</name>
</reference>
</gbean>
<!-- Valve Chain For The Engine -->
<gbean name="FirstValve" class="org.apache.geronimo.tomcat.ValveGBean">
<attribute name="className">org.apache.catalina.authenticator.SingleSignOn</attribute>
<reference name="NextValve"><moduleType>J2EEModule</moduleType><name>SecondValve</name></reference>
</gbean>
<gbean name="SecondValve" class="org.apache.geronimo.tomcat.ValveGBean">
<attribute name="className">org.apache.catalina.valves.AccessLogValve</attribute>
<attribute name="initParams">
prefix=localhost_access_log.
suffix=.txt
pattern=common
</attribute>
</gbean>
<!-- Realm For The Engine -->
<gbean name="TomcatJAASRealm" class="org.apache.geronimo.tomcat.RealmGBean">
<attribute name="className">org.apache.geronimo.tomcat.realm.TomcatJAASRealm</attribute>
<attribute name="initParams">
userClassNames=org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal
roleClassNames=org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal
</attribute>
</gbean>
<!-- Host -->
<gbean name="TomcatHost" class="org.apache.geronimo.tomcat.HostGBean">
<attribute name="className">org.apache.catalina.core.StandardHost</attribute>
<attribute name="initParams">
name=localhost
appBase=
workDir=work
</attribute>
<reference name="engineGBean">
<name>TomcatEngine</name>
</reference>
</gbean>
The dependencies are based on references to other GBeans. For example, notice the TomcatEngine GBean contains references to the TomcatJAASRealm and the FirstValve. The Valve chain works in a similar manner. The Host is also dependent on the Engine, so it contains a reference to the Engine GBean.
As you can see, the server.xml and j2ee-server-tomcat-plan.xml are similar from a Tomcat object and dependency structure perspective, but they do look different. Where the server.xml dependencies are based on encapsulating XML objects, the j2ee-server-tomcat-plan.xml uses references to other GBeans. However, migrating from server.xml to j2ee-server-tomcat-plan.xml should be very simple.
One area to keep in mind is that there is a main difference between these files, and this is that there is no Context pre-declaration for Geronimo (such as the Contex xml configuration in server.xml). This is because Geronimo does not support the concept of Stand Alone Tomcat web applications. This means that all web applications need to be deployed through the deployer, and there is no concept of a "webapps" directory that allows you to pre-declare an application.
Each of the GBean objects are basically wrappers to the actual Tomcat objects. This means you may use the Tomcat objects as you have in the past, along with the parameters that were used in the original server.xml file. Most of the Tomcat GBeans have 2 important attributes that should be noted, className and initParams. The className attribute allows you to declare the Tomcat object class, such as org.apache.catalina.valves.AccessLogValve. For a majority of the Tomcat GBeans, this attribute is generally required (there are one or two exceptions that will be described in detail later in this document). The initParams attribute, which is optional, allows you declare the parameters that are required for the class declared in the className attribute. These are name value pairs, and each pair is shown alone on its own line. To see the similarities between the class declaration and parameter use, lets look at the AccessLogValve declaration in the server.xml and j2ee-server-tomcat-plan.xml:
server.xml:
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
j2ee-server-tomcat-plan.xml
<gbean name="SecondValve" class="org.apache.geronimo.tomcat.ValveGBean">
<attribute name="className">org.apache.catalina.valves.AccessLogValve</attribute>
<attribute name="initParams">
prefix=localhost_access_log.
suffix=.txt
pattern=common
</attribute>
</gbean>
Notice the similarity between the two declarations, where the parameter declarations in the server.xml are done in the xml, and they are done in the initParams attribute for the j2ee-server-tomcat-plan.xml.
Don't let the configuration scare you. Its not as complex as it looks, and the j2ee-server-tomcat-plan.xml file is mostly pre-configured to be used automatically when enabling the Tomcat module. You will only need to make minor modifications to it (if any).
However, let's take a look at each of the GBean objects and describe their configuration in a little more detail for those who wish to dabble in its configuration.
This GBean is the main service for Tomcat and handles its lifetime within the Geronimo container. It manages the major starting and stopping of the Tomcat sub-components. This GBean is required in order to even use Tomcat in Geronimo. It is not recommended to swap this out with a home-grown version unless a full Geronimo infrastructure is supported within the object. It is recommeneded to leave as-is.
Attribute
Required
Description
catalinaHome
No
Describes the relative location of the Catalina Home variable within the Geronimo container. Defaults to var/catalina
Reference
Required
Description
engineGBean
Yes
Reference to the name of an EngineGBean.
serverInfo
Yes
Reference to a ServerInfo GBean object.
Represents the Connector object for Tomcat. Multiple Connector GBeans may be declared for a container.
Attribute
Required
Description
protocol
No
Connector protocol String. Generally will be HTTP/1.1 or AJP/1.3. Defaults to HTTP/1.1.
initParams
No
A name/value pair list allowing you to configure parameters for the org.apache.catalina.connector.Connector object (See http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/http.html
for specific parameters). Each name/value pair is separated with a '=', and should be on its own line.
This GBean represents the Engine object in Tomcat and is wrapped and enabled with the EngineGBean object. It is essentially a wrapper for any type of Engine object. The TomcatEngine, which is a Geronimo extension on the org.apache.catalina.core.StandardEngine is typically used for this object. Although nearly any object that extends org.apache.catalina.core.StandardEngine can be used , again, there is some Geronimo based infrastructure that is used to help enable the integration. It is not recommended to swap this out.
Attribute
Required
Description
className
Yes
A String representation of the underlying Engine object. It is highly recommended to only use the org.apache.geronimo.tomcat.TomcatEngine object
initParams
No
A name/value pair list allowing you to configure parameters for the class declared in the className attribute. Each name/value pair is separated with a '=', and should be on its own line.
Reference
Required
Description
realmGBean
No
Reference to a TomcatRealm
which will be applied at the Engine level
TomcatValveChain
No
Reference to the first Valve in a chain of 1 or more valves which will be applied at the Engine level
This is the Tomcat Host object GBean wrapped by the HostGbean object. This wraps any type of org.apache.catalina.core.StandardHost object. One or more Host GBeans may be declared. Each host will represent its own virtual host.
Attribute
Required
Description
className
Yes
A String representation of the underlying Host object. It is highly recommended to only use the org.apache.catalina.core.StandardHost object, or one that is derived from this object.
initParams
No
A name/value pair list allowing you to configure parameters for the class declared in the className attribute. Each name/value pair is separated with a '=', and should be on its own line. See http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/host.html
for a list of configurable parameters.
Reference
Required
Description
engineGBean
Yes
The engine GBean name that represents the parent engine for this host.
realmGBean
No
Reference to a TomcatRealm
which will be applied at the Engine level
TomcatValveChain
No
Reference to the first Valve in a chain of 1 or more valves which will be applied at the Host level
The Realm GBean represents Tomcat Realm objects. There may be only one realm declared for the Engine and/or Host GBeans. This GBean may be attached to an Engine, Host, (or Context within the geronimo-tomcat.xml file).
Attribute
Required
Description
className
Yes
A String representation of the underlying Realm object.
initParams
No
A name/value pair list allowing you to configure parameters for the class declared in the className attribute. Each name/value pair is separated with a '=', and should be on its own line. See http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/realm.html
for a list of configurable parameters.
The Valve GBean (yes...you guessed it) represents the Tomcat Valve objects. This GBean may be attached to an Engine, Host, (or Context within the geronimo-tomcat.xml file). The Valve object is slightly different from the other objects in that you chain multiple Valves to preserve order. The chaining is done by adding a reference to a another Valve within the GBean configuration.
Attribute
Required
Description
className
Yes
A String representation of the underlying Valve object.
initParams
No
A name/value pair list allowing you to configure parameters for the class declared in the className attribute. Each name/value pair is separated with a '=', and should be on its own line. See http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/valve.html
for a list of configurable parameters.
Reference
Required
Description
NextValve
No
The GBean name referencing the next Valve in the chain.
Note: The content in this section applies to builds 208887 and forward (it will not work for Milestone 3 or lower).
The geronimo-web.xml file is the equivalent of the Tomcat context.xml file. It allows you to configure specific set-up parameters on a web application by web application basis. It is in this file you will be able to describe the context-root, attach application specific valves and realms, and declare your security mapping. The Geronimo deployer can deploy with this file internally to the web application, or externally. For the sake of this section, we will concentrate on an internal configuration. The geronimo-web.xml actually uses the same format for deploying to both Tomcat and Jetty (with a couple of additional config properties for Tomcat), and this file will normally reside in your war file's WEB-INF directory.
The geronimo-web.xml allows you to configure specific attributes regarding your specifc web application. You may set the context-root, class loader priority, the Tomcat Realm object, the tomcat-valve-chain, security role mappings, resource naming references, and configure Gbeans.
Note that a single geronimo-web.xml file supports either Tomcat or Jetty – the bulk of the settings are the same, and the container-config element can add custom properties for one or both containers.
The following is an example geronimo-web.xml file:
<web-app
xmlns="http://geronimo.apache.org/xml/ns/web"
xmlns:sec="http://geronimo.apache.org/xml/ns/security"
configId="MyTomcatWebApp">
<context-root>/test</context-root>
<context-priority-classloader>false</context-priority-classloader>
<container-config container="Tomcat">
<config-param name="TomcatRealm">TomcatJACCRealm</config-param>
<config-param name="TomcatValveChain">FirstValve</config-param>
<config-param name="VirtualHost">www.myexamplehost.com</config-param>
</container-config>
<security-realm-name>Geronimo</security-realm-name>
<security>
<default-principal realm-name="tomcat-properties-realm">
<principal class="org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal" name="metro"/>
</default-principal>
</security>
<gbean name="TomcatJACCRealm" class="org.apache.geronimo.tomcat.RealmGBean">
<attribute name="className">org.apache.geronimo.tomcat.realm.TomcatGeronimoRealm</attribute>
<attribute name="initParams">
userClassNames=org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal
roleClassNames=org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal
</attribute>
</gbean>
<gbean name="FirstValve" class="org.apache.geronimo.tomcat.ValveGBean">
<attribute name="className">org.apache.catalina.authenticator.SingleSignOn</attribute>
<reference name="NextValve"><moduleType>J2EEModule</moduleType><name>SecondValve</name></reference>
</gbean>
<gbean name="SecondValve" class="org.apache.geronimo.tomcat.ValveGBean">
<attribute name="className">org.apache.catalina.valves.AccessLogValve</attribute>
<attribute name="initParams">
prefix=localhost_access_log.
suffix=.txt
pattern=common
</attribute>
</gbean>
</web-app>
In this particular file, we have configured a web application that responds to a URL context of /test and only for the virtual host www.myexamplehost.com. It has set up a simple security mapping that uses the tomcat-properties-realm (which is declared in the included j2ee-server-tomcat-plan.xml that came with the Geronimo source). Declaring this security configuration also assumes we will be using JACC, so we have created the TomcatGeronimoRealm Gbean and added the reference to the TomcatRealm parameter. We are also using some valves that are specific to this context, so we have created the FirstValve and SecondValve Gbeans as a chain, and set set the TomcatValveChain parameter to the first valve in the chain (FirstValve).
TODO: Explain more on the parameters here...
Check Geronimo JIRA issue tracker
and the page for more information about the integration.
The Tomcat integration is mostly complete. There are still a few Tomcat Objects that can be turned into GBeans so they may be configured in the j2ee-server-tomcat-plan.xml or geronimo-tomcat.xml files.
The version of Apache Tomcat is 5.5.9.
cd modules/assembly maven tomcat
Start up Geronimo as follows (see Running):
java -jar bin/server.jar
To see the welcome page :
http://localhost:8080
By default, Geronimo is set up with Jetty as the web deployer (!JettyModuleBuilder
). When a webapp is deployed using !JettyModuleBuilder
it will reference Jetty as a web container (in other, more technical, words - the plan contains a reference to !JettyContainer
). A module builder chooses what container the webapp will be deployed to. To enable Apache Tomcat as a web container, it's necessary to enable !TomcatModuleBuilder
(which will assign Apache Tomcat to the deployed webapps). Which requires building the server again.
NOTE: It is no longer necessary to set java.endorsed.dirs variable on the java command line to start Tomcat.
NOTE: The CATALINA_HOME environment variable is not used by Tomcat when running inside Geronimo. The Catalina home directory is set to var/catalina/ via the GBean attribute catalinaHome in the j2ee-server-tomcat-plan.xml file.
NOTE: Default HTTP connector GBean listens on port 8090 and the default AJP/1.3 connector GBean listens on port 8009 These port numbers can be changed in the j2ee-server-tomcat-plan.xml file. If you are not running a web server in front of Geronimo that uses AJP, the TomcatAJPConnector GBean may be commented out.
To aid Geronimo problem diagnosis, start the Debug Console configuration by issuing the following command:
java -jar bin/deployer.jar --user system --password manager start org/apache/geronimo/DebugConsole
A simple start-up of Geronimo with Apache Tomcat and the !DebugConsole
webapp: (TBD: this example needs to be updated to match the commands above)
$ java -Djava.endorsed.dirs=lib/endorsed -jar bin/server.jar org/apache/geronimo/DebugConsole 16:45:26,242 INFO [Daemon] Server startup begun 16:45:26,299 INFO [Daemon] java.endorsed.dirs=lib/endorsed:/Projects/geronimo/modules/assembly/target/geronimo-1.0-SNAPSHOT/lib/endorsed 16:45:26,806 INFO [MBeanServerFactory] Created MBeanServer with ID: 4ba9a2:103a9e28e7c:-8000:Powerbook.local:1 16:45:26,807 INFO [Kernel] Starting boot 16:45:27,455 INFO [Kernel] Booted 16:45:27,523 INFO [ConfigurationManagerImpl] Loaded Configuration geronimo.config:name="org/apache/geronimo/System" 16:45:28,127 INFO [Configuration] Started configuration org/apache/geronimo/System 16:45:28,710 INFO [ReadOnlyRepository] Repository root is file:/Projects/geronimo/modules/assembly/target/geronimo-1.0-SNAPSHOT/repository/ 16:45:28,976 INFO [RMIRegistryService] Started RMI Registry on port 1099 16:45:29,019 INFO [ConfigurationManagerImpl] Loaded Configuration geronimo.config:name="org/apache/geronimo/DebugConsole" 16:45:29,094 INFO [ConfigurationManagerImpl] Loaded Configuration geronimo.config:name="org/apache/geronimo/Tomcat" 16:45:29,144 INFO [ConfigurationManagerImpl] Loaded Configuration geronimo.config:name="org/apache/geronimo/Server" 16:45:31,919 INFO [Configuration] Started configuration org/apache/geronimo/Server 16:45:32,923 INFO [HttpServer] Statistics on = false for org.apache.geronimo.jetty.JettyServer@29e9b 16:45:32,939 INFO [HttpServer] Version Jetty/5.1.4rc0 16:45:32,944 INFO [Container] Started org.apache.geronimo.jetty.JettyServer@29e9b 16:45:33,161 INFO [SocketListener] Started SocketListener on 0.0.0.0:8080 16:45:33,327 INFO [SecurityServiceImpl] JACC factory registered 16:45:33,410 INFO [HOWLLog] Initiating transaction manager recovery 16:45:33,657 WARN [HOWLLog] Received unexpected log record: org.objectweb.howl.log.xa.XALogRecord@b58796 16:45:33,658 INFO [HOWLLog] In doubt transactions recovered from log 16:45:33,733 INFO [GeronimoLoginConfiguration] Added Application Configuration Entry geronimo-properties-realm 16:45:33,735 INFO [GeronimoLoginConfiguration] Added Application Configuration Entry JMX 16:45:33,770 INFO [GeronimoLoginConfiguration] Installed Geronimo login configuration 16:45:34,288 INFO [Credential] Checking Resource aliases 16:45:34,726 INFO [SslListener] SslListener.needClientAuth=false 16:45:34,817 INFO [SocketListener] Started SocketListener on 0.0.0.0:8443 16:45:35,636 INFO [RMIConnectorServer] RMIConnectorServer started at: service:jmx:rmi://localhost/jndi/rmi:/JMXConnector 16:45:35,639 INFO [server:J2EEApplication=null,J2EEModule=org/apache/geronimo/Server,J2EEServer=geronimo,j2eeType=GBean,name=JMXService] Started JMXConnector service:jmx:rmi://localhost/jndi/rmi:/JMXConnector 16:45:36,454 INFO [Configuration] Started configuration org/apache/geronimo/Tomcat 16:45:36,489 INFO [GeronimoLoginConfiguration] Added Application Configuration Entry Geronimo 16:45:37,108 INFO [JAASRealm] Set JAAS app name Geronimo 16:45:37,212 INFO [TomcatContainer] Endorsed Dirs set to:lib/endorsed:/Projects/geronimo/modules/assembly/target/geronimo-1.0-SNAPSHOT/lib/endorsed 16:45:37,482 INFO [Embedded] Starting tomcat server 16:45:37,485 INFO [Embedded] Catalina naming disabled 16:45:38,288 INFO [StandardEngine] Starting Servlet Engine: Apache Tomcat/5.5.9 16:45:38,386 INFO [StandardHost] XML validation disabled 16:45:38,388 INFO [RealmBase] This Realm has already been started 16:45:38,787 INFO [WebappLoader] Dual registration of jndi stream handler: factory already defined 16:45:39,764 INFO [ContextConfig] Missing application web.xml, using defaults only StandardEngine[Geronimo].StandardHost[localhost].StandardContext[] 16:45:41,076 INFO [Http11Protocol] Initializing Coyote HTTP/1.1 on http-8090 16:45:41,301 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-8090 16:45:41,683 INFO [Configuration] Started configuration org/apache/geronimo/DebugConsole 16:45:41,915 INFO [RealmBase] This Realm has already been started 16:45:43,533 INFO [TomcatWebAppContext] TomcatWebAppContext started 16:45:43,537 INFO [Daemon] Server startup completed
The heart of the module is the GBean itself, which is org.apache.geronimo.tomcat.!TomcatContainer
. !TomcatContainer
is given a set of deployed webapps that are of org.apache.geronimo.tomcat.!TomcatWebAppContext
type. When a webapp is deployed, a configured !WebModuleBuilder
is asked for handling it. There are two !WebModuleBuilders
: !JettyModuleBuilder
and !TomcatModuleBuilder
. No matter what builder is used, the idea of deploying the webapp is the same. First, !TomcatModuleBuilder
creates a plan (wraps it into !TomcatWebAppContext
) and saves it in the repository (a place where configurations are stored). !TomcatWebAppContext
's plan contains a reference to !TomcatContainer
so that when the context starts up it hands itself over to !TomcatContainer
for deployment. It's therefore important to change the module builder if the decision of running Jetty or Tomcat is to be made.
If anyone knows the answers to these, please update the Wiki.
java.lang.ClassNotFoundException: COM.claymoresystems.ptls.SSLContext ..............
Does the HTTPS connector start properly?