Some templating in TomEE


Having some templetized configuration file is a great feature for the cloud. Here how to deal with it using TomEE.

Tomcat has some templating features.

Typically you can replace the ports in the server.xml by something like ${mySuperport} and set mySuperPort system property when you launch Tomcat. This still works in TomEE.

Here a sample:

<?xml version='1.0' encoding='utf-8'?>
<Server port="${tomee.shutdown}" shutdown="SHUTDOWN">
  <Listener className="org.apache.tomee.catalina.ServerListener" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <Service name="Catalina">
    <Connector port="${tomee.http}" protocol="HTTP/1.1"
               connectionTimeout="20000" />

    <Engine name="Catalina" defaultHost="${tomee.host}">
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true" />
    </Engine>
  </Service>
</Server>

Then simply add to CATALINA_OPTS these properties:

export CATALINA_OPTS="-Dtomee.host=localhost -Dtomee.http=8080 -Dtomee.shutdown=8005"

That’s cool but TomEE can come (in particular the plus version) with some additional services using additional ports. For instance the ssh console uses another port. Or let say you simply want to change dynamically your configuration.

These kind of services have their own configuration in $CATALINA_BASE/conf/conf.d/.properties. For instance for the ssh console it is: $CATALINA_BASE/conf/conf.d/ssh.properties.

Until 1.0.0 release to override these property values you had to set the property <service-name>.<attribute>. For instance to disable SOAP webservices (the service is called “cxf”) you had to set:

export CATALINA_OPTS="-Dcxf.disabled=true"

The good part is you don’t need to change the configuration file at all. But sometimes this change can be what you want. Or simply to be consistent with Tomcat you want to use ${xx} values. That’s now possible on trunk.

Simply edit <service name>.properties file and change the value to ${foo}. Then simply set the system property “foo” like for Tomcat.

Now your TomEE configuration is ready to be templetized (cloud, did you say cloud?).

I would like to thank Neale Rudd from metawerx.net for his help on this topic.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s