Control structures and special directives
Resin 3.1

Documentation
Examples
Changes

Overview
Installation
Configuration
Quercus
SOA/IoC
JSP
Servlets and Filters
Admin (JMX)
EJB
Amber
Security
Performance
Hessian
XML and XSLT
Third-party
Troubleshooting/FAQ

Command-Line Options
Tags
Common Tasks
Relax Schema
howto
Config FAQ
Scrapbook
DB Scrapbook

Environment tags
<resin>
<cluster>
<server>
Port tags
<host>
<web-app>
<database>
Session tags
Rewrite tags
Service tags
Log tags
EL variables and functions
Control tags
Tag Index
EL variables and functions
Tags
Tag Index

Resin's configuration files provide support for certain control tags for conditional processing.

Control Structures

The resin.conf and web.xml configuration files can use control structures. The syntax of the control structures is deliberately similar to the control structures used in JSTL.

These can be useful to create a resin.conf which works for both testing and deployment, depending on an environment parameter. When possible, users should avoid using the control tags when possible to keep their configuration files as simple as possible.

<web-app xmlns="http://caucho.com/ns/resin"
            xmlns:resin="http://caucho.com/ns/resin/core">
  <resin:choose>
  <resin:when test="\${mode='development'}">
    <resin:log>Development Mode</resin:log> 
  </resin:when>
  <resin:when test="\${mode='deploy'}">
    <resin:log>Deployment Mode</resin:log> 
  </resin:when>
  <resin:otherwise>
    <resin:log>Unknown Mode \${mode}</resin:log>
  </resin:otherwise>
  <resin:choose>
</web-app>

The source code for the control elements is found in com.caucho.config.core.

resin:set

resin:set adds an EL variable to the current context.

<resin:set var="name" value="\${value}"/>
namename of the variable to setrequired
valuevaluerequired
resin:set in resin.conf
<resin xmlns="http://caucho.com/ns/resin"
          xmlns:resin="http://caucho.com/ns/resin/core">
  <resin:set name="root" value="/var/www">

  <cluster id="app-tier">
    <root-directory>${root}</root-directory>

    ...
  </cluster>
</resin>

resin:if

resin:if executes part of the configuration file conditionally.

<resin:if test="\${expr}"> ... <resin:if>
testthe test to perform

resin:choose

resin:choose implements an if, elsif, else.

<resin:choose> <resin:when test="\${expr1}"> ... </resin:when> <resin:when test="\${expr2}"> ... </resin:when> <resin:otherwise> ... </resin:otherwise> <resin:choose>
resin:when
resin:choose

resin:when

child of resin:choose

<resin:when> conditionally configures a block within a <resin:choose> block. If the test matches, Resin will use the enclosed configuration.

testthe test to perform

resin:otherwise

child of resin:choose

<resin:otherwise> is the catch-all configuration for a <resin:choose> block when none of the <resin:when> items match.

testthe test to perform

Special Directives

resin:log

Logs a message to the given log file. The content of the element is the message.

logging in resin-web.xml
<web-app xmlns="http://caucho.com/ns/resin">

  <resin:log>Starting server \${server.name}</resin:log>
</web-app>

resin:import

resin:import is used to read configuration information from another file. The target file is validated by a schema where the schema depends on the location of the resin:import. A resin:import in <server> will have a target with a top-level of <server>.

patha path to a fileeither path or fileset is required
fileseta fileseteither path or fileset is required
optionalif true, no error when file does not existfalse
example import as used in app-default.xml
<resin xmlns="http://caucho.com/ns/resin"
          xmlns:resin="http://caucho.com/ns/resin/core">
  <cluster id="app-tier">

    <web-app-default>
      <resin:import path="WEB-INF/web.xml" optional="true"/>
      <resin:import path="WEB-INF/resin-web.xml" optional="true"/>
    </web-app-default>

  </cluster>
</resin>

resin:env

resin:env creates a new environment for a section of the configuration file. Some users may want to use this to create resources or databases with custom <class-loader> tags.

resin:env is tricky and only required for some extraordinary circumstances. Using it correctly requires a good understanding of classloaders.

Here is an example of a solution for the situation where a custom access logging class requires an old version of a jar that the web application uses as well. The requirement is that the example.MyAccessLog use an old version of the classes in Foo.jar, webapps use a newer version of the jar.

In a normal circumstance, access-log is used in the <host> environment. If the example.MyAccessLog uses a class from a jar file oldversion-Foo.jar, oldversion-Foo.jar needs to available to the classloader for the <host> environment. Because a %lt;web-app> inherits the classes of the <host>, the webapp will end up with the Foo.jar classes from the host's classloader; WEB-INF/lib/Foo.jar will not provide the classes because they have already been defined in the parent (host) classloader.

The following example solves the problem by using resin:env to create an environment just for the instantiation of the example.MyAccessLog class.

<host id=''>
  <resin:env>
   <class-loader>
     <library-loader path="/opt/lib/oldversion-Foo.jar"/>
   </class-loader>

   <access-log resin:type="example.MyAccessLog"/>
  </resin:env>

  ...

  <web-app>
    <!-- WEB-INF/lib can contain Foo.jar and the classes are not overridden 
         by the classes in oldversion-Foo.jar.
       -->
    ...
  </web-app>
</host>

EL variables and functions
Tags
Tag Index
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin ® is a registered trademark, and Quercustm, Ambertm, and Hessiantm are trademarks of Caucho Technology.