Environment: Class Loaders, Resources and JNDI
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

tags
Common Tasks
Relax Schema
howto
Config FAQ
Scrapbook
DB Scrapbook

env tags
<resin>
<cluster>
<server>
port tags
<host>
<web-app>
<database>
session tags
rewrite tags
service tags
log
el variables
el control
tags
tags
<resin>

Environment tags configure class-loaders, logging, authentication, EL variables and control, and resources like databases, JMS queues, EJB servers, and web service clients. Many of the resources are stored in JNDI or in EL variables for later assemply.

Any environment resource can appear in any of Resin environments: <resin>, <cluster>, <host> and <web-app>. Resources configured at parent levels are shared among all children, so a database can share connection pools for all web-apps or an authenticator can provide single-signon.

<authenticator>
child of resin, cluster, host, web-app, login-config

<authenticator configures an authentication resource for the current environment.

Resin's servlet authentication uses an authentication resource to validate user login and to provide single-signon capability. The authenticator is configured in the environment context where it is shared. So an authenticator configured in the web-app only applies to the web-app, but an authenticator configured in the host will apply to all hosts.

The authenticator class is selected with the type attribute. It can be any custom class extending com.caucho.server.security.AbstractAuthenticator. Configuration of the authenticator uses bean-style configuration in the <init> tag.

jndi-nameThe JNDI name where the authenticator is stored. Since Resin 3.0java:comp/env/caucho/auth
typeThe implementing class for the authenticator. Since Resin 3.0required
initA bean-style configuration section. Since Resin 3.0none
<bean>
child of resin, cluster, host, web-app

<bean> configures a custom bean resource and stores in JNDI. <bean> is a synonym for <bean>.

Resources are beans stored in JNDI. The resources can be created from any Java class that conforms to the bean conventions. Configuration of the resource is in the <init> section. Field values may use JSP-EL expressions as well as constant strings or even complex sub-beans.

jndi-nameJNDI name for the resource. Since Resin 3.0
typeApplication class implementing the resource. Since Resin 3.0required
argArguments to the resource's constructor. Since Resin 3.0optional
initIoC/JAXB configuration for the beanoptional
listenerRegisters the bean as a listener for a JMX emitter. Resin 3.0optional
mbean-nameJMX name for management registration. Resin 3.0optional
varEL variable name for the bean. Resin 3.0optional
Custom Bean configured in resin-web.xml
<web-app xmlns="http://caucho.com/ns/resin">
  <bean jndi-name="env/test">
    <type>test.MyBean</type>
    <init>
      <greeting>Hello</greeting>
      <server>${serverId}</server>
      <sub-bean>
        <value>${2 + 2}</value>
      </sub-bean>
    </init>
  </bean>
</web-app>
<bean> schema
r_bean = element bean { (jndi-name? & mbean-name? & mbean-interface? & var?), (type, arg*)?, (init | listener)* } element listener { mbean-name, handback* }
<case-insensitive>
child of resin, cluster, host, web-appdefault true on Windows, false on Unix.

<case-insensitive> specifies whether the environment context is case sensitive or insensitive.

Because some operating systems are case-insensitive, it is important for security reasons for Resin to behave differently for case-sensitive and case-insensitive directories. For example, when case-insensitive is true, url-patterns will match in a case-insensitive manner, so TEST.JSP will work like test.jsp.

<character-encoding>
child of resin, cluster, host, web-appdefault The default value is ISO-8859-1.

<character-encoding> specifies the default character encoding for the environment.

<web-app id='/'>
  <character-encoding>shift_jis</character-encoding>
  ...

</web-app>
<class-loader>
child of resin, cluster, host, web-app

<class-loader> configures a dynamic classloader for the current environment.

Each environment (<cluster>, <host>, <web-app>) etc, can add dynamic classloaders. The environment will inherit the parent classloaders. Each <class-loader> is comprised of several implementing loader items: library-loader for WEB-INF/lib, compiling-loader for WEB-INF/classes.

<class-loader> in resin-web.xml
<web-app xmlns="http://caucho.com/ns/resin">
  <prologue>
    <class-loader>
      <compiling-loader path="WEB-INF/classes"/>

      <library-loader path="WEB-INF/lib"/>
    </class-loader>
  </prologue>
</web-app>
<compiling-loader>
child of class-loader

<compiling-loader> automatically compiles Java code into .class files before loading them.

argsAdditional arguments to be passed to the Java compiler. Resin 3.0none
batchIf true, multiple changed *.java files will be compiled in a single batch. Resin 3.0.7true
encodingI18N encoding for the Java compiler. Since Resin 3.0none
pathFilesystem path for the class loader. Since Resin 3.0required
sourceJava source directory. Since Resin 3.0value of path
require-sourceIf true, .class files without matching .java files will be deleted. Since Resin 3.0false
<compiling-loader> for WEB-INF/src
<web-app xmlns="http://caucho.com/ns/resin">
  <prologue>
    <class-loader>
      <compiling-loader path="WEB-INF/classes"
                        source="WEB-INF/src"/>
    </class-loader>
  </prologue>
</web-app xmlns="http://caucho.com/ns/resin">
<connector>
child of resin, cluster, host, web-app

<connector> configures a JCA resource adapter and its associated connection factories.

The resource adapter/connector will have been added as a rar file (see resource-deploy. The <connector> configures that rar resource.

Connector Example
<connector connector-name="Test Resource">
  <connection-factory jndi-name="eis/test">
    <init>
      <value>b</value>
    </init>
  </connection-factory>
</connector>
connectorConfigures a connectorrequired
connector-nameSpecifies the rar connector's display-namerequired
resource-adapterConfigures the resource-adapteroptional
connection-factoryConfigures a connection-factoryoptional
jndi-nameJNDI name for a resource-adapter or connection-factoryrequired
typeFor connectors with multiple connection-factories, specifies the connection-factoryoptional
local-transaction-optimizationEnables the local transaction optimization. Resin 3.0.7true
initBean-style initializationoptional
connector schema
element connector { connector-name { string } & resource-adapter? & connection-factory* } element connection-factory { jndi-name, type?, element init { any }? } element resource-adapter { jndi-name, element init { any }? }
<database>
child of resin, cluster, host, web-app

<database> defines a database (i.e. DataSource) resource.

The database configuration section has more details on the configuration. A code pattern for using databases is in a DataSource tutorial.

<database jndi-name='jdbc/test_mysql'>
  <driver 
    type="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
    <url>jdbc:mysql://localhost:3306/test</url>
    <user></user>
    <password></password>
  </driver>
</database>
<dependency>
child of resin, cluster, host, web-app

<dependency> adds dependent files which should force a reload when changed, like web.xml and resin-web.xml.

pathFilesystem path to the dependent file. Since Resin 3.0required
web.xml
<web-app xmlns="http://caucho.com/ns/resin">
  <dependency path="WEB-INF/struts-config.xml"/>
  ...
</web-app>
<dependency-check-interval>
child of resin, cluster, host, web-appdefault 2s

<dependency-check-interval> Configures how often the environment context should be checked for changes. The default value is set low for development purposes, deployments should use something larger like 5m or 1h.

Resin automatically checks each environment for updates, generally class or configuration updates. Because these checks can take a considerable amount of time, deployment servers should use high values like 60s or more while development machines will want low values like 2s.

The interval defaults to the parent's interval. So the web-app will default to the host's value.

default 2s
deployment dependency-check-interval
<resin xmlns="http://caucho.com/ns/resin">
  <cluster id="app-tier">
    <dependency-check-interval>1h<dependency-check-interval>

    <server id="app-a" .../>

    <host id=""/>
      ...
  </cluster>
</resin>
<ejb-server>
child of resin, cluster, host, web-app

Configures an EJB/JPA server. See the CMP configuration for more details.

<env-entry>
child of resin, host-default, host, web-app-default, web-app

<env-entry> configures a JNDI scalar value for JNDI-based application configuration.

Some application beans prefer to retrieve configuration data from JNDI, including String, Integer, and Double constants. env-entry configures that data in the current context. As with other Resin configuration, the value can use JSP-EL expressions.

env-entry-nameJNDI name to store the value. Since Servlet 2.1required
env-entry-typeJava type for the value. Since Servlet 2.1required
env-entry-valueValue to be stored. Since Servlet 2.1required

The example configuration stores a string in java:comp/env/greeting. Following the J2EE spec, the env-entry-name is relative to java:comp/env. If the env-entry is in the <host> context, it will be visible to all web-apps in the host.

Example resin-web.xml fragment
<web-app xmlns="http://caucho.com/ns/resin">
  <env-entry>
    <env-entry-name>greeting</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>Hello, World</env-entry-value>
  </env-entry>

  <servlet ...>
  </servlet>
</web-app>

The following servlet fragment is a typical use in a servlet. The servlet only looks up the variable once and stores it for later use.

GreetingServlet.java
import java.io.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class TestServlet extends HttpServlet {
  private String greeting;

  public void init()
    throws ServletException
  {
    try {
      Context env = 
        (Context) new InitialContext().lookup("java:comp/env");
      greeting = (String) env.lookup("greeting");
    } catch (NamingException e) {
      throw new ServletException(e);
    }
  }

  ...
}
env-entry schema
element env-entry { env-entry-name, env-entry-type, env-entry-value }
<javac>
child of resin, cluster, host, web-app

<javac> configures the Java compiler for automatically compiled files.

The javac configuration is used for JSP, PHP, EJB and compiling-loader configuration.

The eclipse compiler requires the presence of $RESIN_HOME/lib/eclipse-compiler.jar (which is included with Resin). It is a very fast compiler that was developed as part of the Eclipse project.

Eclipse compiler
 <javac compiler="eclipse" args="-source 1.5"/>

The internal compiler requires tools.jar from the JDK installation, so a JDK must be used (not a JRE). Sometimes the internal compiler causes errors, creating exceptions or simply hanging and taking up a thread. The solution is to change the compiler to use an external compiler.

Internal compiler
 <javac compiler="internal" args=""/>

The javac compiler is included with the JDK. It executes that same as the internal compiler, however it is executed as an external process and is less prone to the problems described for the internal compiler. In resin.conf with the javac configuration option:

javac JDK compiler
 <javac compiler="javac" args=""/>
compilerConfigures the Java compiler to use. Since Resin 3.0internal
argsAny additional arguments for the compiler. Since Resin 3.0none
encodingAny encoding valued for the compiler. Since Resin 3.0none
<jndi-link>
child of resin, cluster, host, web-app

<jndi-link> creates a symbolic link from one jndi name to another, or links to a foreign JNDI context.

Resin's JNDI can link to foreign JNDI contexts. For example, third-party EJB servers will often expose their EJB beans through a JNDI context. jndi-link will create the appropriate InitialContextFactory, configure it, and lookup the foreign JNDI objects.

factoryClass name of the JNDI InitialContextFactory. Since Resin 1.2optional
foreign-nameThe target name of the symbolic link, or the sub-context of the foreign JNDI context. Since Resin 1.2none
init-paramConfiguration parameters for the JNDI environment passed to InitialContextFactory. Since Resin 1.2none
jndi-nameThe JNDI name to use for the link. Resin 3.0required
A JNDI symbolic link for a DataSource
<web-app xmlns="http://caucho.com/ns/resin"dd>
  <database jndi-name="jdbc/oracle">
    ...
  </database>

  <jndi-link jndi-name="java:comp/env/jdbc/gryffindor">
    <foreign-name>java:comp/env/jdbc/oracle</foreign-name>
  </jndi-link>

  <jndi-link jndi-name="java:comp/env/jdbc/slytherin">
    <foreign-name>java:comp/env/jdbc/oracle</foreign-name>
  </jndi-link>
</web-app>
A JNDI foreign context for all EJB
<web-app xmlns="http://caucho.com/ns/resin">
  <jndi-link jndi-name='java:comp/env/ejb'>
    <factory>com.caucho.ejb.hessian.HessianContextFactory</factory>
    <init-param java.naming.provider.url='http://ejb.hogwarts.com:80/hessian'/>
  </jndi-link>
</web-app>
A JNDI foreign context for selected EJB
<web-app xmlns="http://caucho.com/ns/resin">
  <jndi-link jndi-name='java:comp/env/remote-ejb'>
    <factory>com.caucho.ejb.hessian.HessianContextFactory</factory>
    <init-param java.naming.provider.url='http://ejb.hogwarts.com:80/hessian'/>
  </jndi-link>

  <jndi-link jndi-name="java:comp/env/ejb/Foo">
    <foreign-name>java:comp/env/remote-ejb/Foo</foreign-name>
  </jndi-link>

  <jndi-link jndi-name="java:comp/env/ejb/Bar">
    <foreign-name>java:comp/env/local-ejb/Bar</foreign-name>
  </jndi-link>
</web-app>
<library-loader>
child of class-loader

<library-loader> configures a jar library, WEB-INF/lib-style class loader.

The library-loader will add jar files in its path to the current classpath. Jar files are recognized wihen they have a filename extension of .jar or .zip.

pathFilesystem path for the class loader. Since Resin 3.0required

See DirectoryLoader.

<log>
child of resin, cluster, host, web-app

<log> configures JDK 1.4 java.util.logger handler.

The log configuration describes log in detail.

<logger>
child of resin, cluster, host, web-app

<log> configures JDK 1.4 java.util.logger Logger level.

The log configuration describes log in detail.

compilation logging
<resin xmlns="http://caucho.com/ns/resin">
  <log name="" level="all" path="log/debug.log"/>
  <logger name="com.caucho.java" level="fine"/>

  <cluster id="app-tier">
    ...
  </cluster>
</resin>
<reference>
child of resin, cluster, host, web-app

<reference> configures a JNDI ObjectFactory.

JNDI ObjectFactories are used to create objects from JNDI references. The <reference> tag configures the ObjectFactory and stores it in JNDI.

jndi-nameJNDI name for the reference. Since Resin 3.0required
factoryClass name of the ObjectFactory. Resin 3.0required
initBean-style initialization for the factorynone
<reference>
  <jndi-name>hessian/hello</jndi-name>
  <factory>com.caucho.hessian.client.HessianProxyFactory</factory>
  <init url="http://localhost:8080/ejb/hello"/>
        type="test.HelloHome"/>
</reference>
<resin:if>

<resin:if> executes part of the configuration file conditionally.

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:import>

<resin:import> reads 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 <cluster> will have a target with a top-level of <server>.

<resin:import> is a key capability of the resin.conf file. User configuration files like web.xml and resin-web.xml are implemented by <resin:import>.

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
resin-web.xml 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:log>

<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:set>

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

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: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.

<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
<resource>
child of resin, cluster, host, web-app

<resource> configures a custom bean resource and stores in JNDI. <resource> is a synonym for <bean>.

Resources are beans stored in JNDI. The resources can be created from any Java class that conforms to the bean conventions. Configuration of the resource is in the <init> section. Field values may use JSP-EL expressions as well as constant strings or even complex sub-beans.

jndi-nameJNDI name for the resource. Since Resin 3.0required
typeBean class implementing the resource. Since Resin 3.0required
argArguments to the resource's constructor. Since Resin 3.0optional
mbean-nameJMX name for management registration. Resin 3.0optional
initBean-style initialization for the beanoptional
listenerRegisters the bean as a listener for a JMX emitter. Resin 3.0optional
local-transaction-optimizationEnables the local transaction optimization. Resin 3.0.7true
<resource jndi-name="env/test">
  <type>test.MyBean</type>
  <init>
    <greeting>Hello</greeting>
    <server>${'${'}serverId}</server>
    <sub-bean>
      <value>${'${2'} + 2}</value>
    </sub-bean>
  </init>
</resource>
schema
r_listener-Resource = element listener { r_mbean-name, r_handback* } r_resource = element resource { (r_jndi-name? & r_mbean-name? & r_mbean-interface?), (r_type, r_arg*)?, (r_init* & r_listener-Resource*) }
<resource-deploy>
child of resin, cluster, host-default, host, web-app-default, web-app

<resource-deploy> defines a deployment directory for .rar files.

Connectors and resources defined in .rar files must be deployed before they can be configured by connector. The <resource-deploy> tag specifies the directory for that deployment.

resource-deployConfigures .rar deploymentrequired
pathConfigures the path where users will place .rar filesrequired
expand-pathConfigures the directory where Resin will expand rar filesthe path value
schema
element resource-deploy { path & expand-path? }
example resource-deploy
<resin xmlns="http://caucho.com/ns/resin">
  <cluster id="app-tier">

    <host id="">
      <resource-deploy path="deploy"/>
    </host>
  </cluster>
</resin>
<resource-ref>
child of resin, cluster, host, web-app

<resource-ref> declares that the application needs a resouce configuration.

resource-ref is not directly used by Resin. It's a servlet configuration item intended to tell GUI tools which resources need configuration. Resource configuration in Resin uses the resource, reference, database, and ejb-server tags.

For backwards compatibility, Resin 2.1-style configuration files may still use resource-ref to configure resources, but it's recommended to convert the configuration.

<servlet-hack>
child of class-loader

Use of servlet-hack is discouraged. Using servlet-hack violates the JDK's classloader delegation model and can produce surprising ClassCastExceptions.

servlet-hack reverses the normal class loader order. Instead of parent classloaders having priority, child classloaders have priority.

<simple-loader>
child of class-loader

<simple-loader> Configures a simple WEB-INF/classes-style class loader.

.class files in the specified directory will be loaded without any special compilation steps (in contrast with compiling-loader.)

pathFilesystem path for the class loader. Since Resin 3.0required
prefixClass package prefix to only load to a subset of classes. Resin 3.0none
<stderr-log>
child of resin, cluster, host-default, host, web-app-default, web-app

Configures the destination for System.err.

The log configuration describes stderr-log in detail.

<stdout-log>
child of resin, cluster, host-default, host, web-app-default, web-app

Configures the destination for System.out.

The log configuration describes stderr-log in detail.

<system-property>
child of resin, cluster, host, web-app

Sets a Java system property. The effect is the same as if you had called java.lang.System before starting Resin.

<resin xmlns="http://caucho.com/ns/resin">
  <system-property foo="bar"/>
</resin>
<temp-dir>
child of resin, cluster, host-default, host, web-app-default, web-appdefault Defaults to WEB-INF/tmp

<temp-dir> configures the application temp directory. This is the path used in javax.servlet.context.tempdir.

<tree-loader>
child of class-loader

<tree-loader> configures a jar library, WEB-INF/lib-style class loader similar to library-loader, but will also find .jar and .zip files in subdirectories.

pathFilesystem path for the class loader. Since Resin 3.0required
<web-service-client>
child of web-app

<web-service-client> configures a proxy to a web-service. It uses a Java interface and a URL to select the web-service.

The URL is defined as: encoding:location, where location is typically a HTTP URL.

See the hello world tutorial for an example.

hessian:http://foo.com/hello/hessianDefines a hessian service at http://foo.com/hello/hessian
rest:http://foo.com/hello/restDefines a REST service at http://foo.com/hello/rest
soap:http://foo.com/hello/soapDefines a REST service at http://foo.com/hello/soap
web-service-client
element web-service-client { jndi-name & url & interface }
<work-dir>
child of resin, config, host, web-appdefault Defaults to WEB-INF/work

<work-dir> configures a work directory for automatically generated code, e.g. for JSP, PHP, and JPA classes.


tags
tags
<resin>
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin ® is a registered trademark, and Quercustm, Ambertm, and Hessiantm are trademarks of Caucho Technology.