Caucho maker of Resin Server | Application Server (Java EE Certified) and Web Server


 

Resin Documentation

home company blog wiki docs 
app server web server 
health cloud java ee pro 
 Resin Server | Application Server (Java EE Certified) and Web Server
 

el variables and functions


Resin configuration can directly access Resin-IoC/WebBeans-configured beans and variables using EL expressions in the configuration files. Predefines variables include webApp, host, and resin variables.

Examples

Servlet/Filter initialization

EL expressions can be used to configure servlets and filters. init-param values can use JSP EL expressions, including the ability to use system properties.

Servlets, filters, and resources can be configured like beans with setter methods are called directly (See Bean-style init).

One example use for the bean-style servlet initialization is to avoid JNDI lookup inside the servlet code. For example, a servlet that that uses a JDBC DataSource might look like:

Servlet using JDBC
package test;

...

public class TestServlet extends HttpServlet {
  private DataSource _dataSource;

  /**
   * Bean setter is called to configure the servlet
   * before the init() method.
   */
  public void setDataSource(DataSource dataSource)
  {
    _dataSource = dataSource;
  }

  ...
}

The servlet is configured as follows:

Example configuration
<web-app>
  <allow-servlet-el/>

  <servlet servlet-name='test'
           servlet-class='test.TestServlet'>
    <init>
      <data-source>${jndi("java:comp/env/jdbc/test")}</data-source>
    </init>
  </servlet>

  ...
</web-app>

The <data-source> xml tag corresponds to the setDataSource method of the bean. More infomation on this powerful pattern is in the bean configuration section of the documentation.

Environment variables

Environment variables inherited by the process from the operting system are available as variables in el expressions, for example ${LANG}.

fmt.sprintf()

Format a string using a sprintf-like format string.

fmt.sprintf(format[,arg1, arg2 ... argN])
formatthe format string (see below)required
arg1..argNthe values used for the conversions in the format stringn/a

sprintf accepts a series of arguments, applies to each a format specifier from `format', and returns the formatted data as a string. `format' is a string containing two types of objects: ordinary characters (other than `%'), which are copied unchanged to the output, and conversion specifications, each of which is introduced by `%'. (To include `%' in the output, use `%%' in the format string).

A conversion specification has the following form:

%[FLAGS][WIDTH][.PREC][TYPE]

TYPE is required, the rest are optional.

The following TYPE's are supported:

%%a percent sign
%ca character with the given number
%sa string, a null string becomes "#null"
%za string, a null string becomes the empty string ""
%da signed integer, in decimal
%oan integer, in octal
%uan integer, in decimal
%xan integer, in hexadecimal
%Xan integer, in hexadecimal using upper-case letters
%ea floating-point number, in scientific notation
%Ea floating-point number, like %e with an upper-case "E"
%fa floating-point number, in fixed decimal notation
%ga floating-point number, in %e or %f notation
%Ga floating-point number, like %g with an upper-case "E"
%pa pointer (outputs a value like the default of toString())

Intepret the word `integer' to mean the java type long. Since java does not support unsigned integers, all integers are treated the same.

The following optional FLAGS are supported:

0If the TYPE character is an integer leading zeroes are used to pad the field width instead of spaces (following any indication of sign or base).
+Include a `+' with positive numbers.
(a space)use a space placeholder for the `+' that would result from a positive number
-The result of is left justified, and the right is padded with blanks until the result is `WIDTH' in length. If you do not use this flag, the result is right justified, and padded on the left.
#an alternate display is used, for `x' and `X' a non-zero result will have an "0x" prefix; for floating point numbers the result will always contain a decimal point.
jescape a string suitable for a Java string, or a CSV file. The following escapes are applied: " becomes \", newline becomes \n, return becomes \r, \ becomes \\.
vescape a string suitable for CSV files, the same as `j' with an additional " placed at the beginning and ending of the string
mescape a string suitable for a XML file. The following escapes are applied: < becomes &lt;, > becomes &gt; & becomes &amp; ' becomes &#039, " becomes &034;

The optional WIDTH argument specifies a minium width for the field. Spaces are used unless the `0' FLAG was used to indicate 0 padding.

The optional PREC argument is introduced with a `.', and gives the maximum number of characters to print; or the minimum number of digits to print for integer and hex values; or the maximum number of significant digits for `g' and `G'; or the number of digits to print after the decimal point for floating points.

fmt.timestamp()

Format a timestamp string.

fmt.timestamp(format[,date])
formatthe format string (see below)required
datean object with or or the current date and time
msg="The current date and time is ${fmt.timestamp('%Y/%m/%d %H:%M:%S.%s')}"
msg="time=${fmt.timestamp('[%Y/%m/%d %H:%M:%S.%s]')}"

format contains regular characters, which are just copied to the output string, and percent codes which are substituted with time and date values.

CODEMEANING
%aday of week (short)
%Aday of week (verbose)
%bday of month (short)
%Bday of month (verbose)
%cJava locale date
%dday of month (two-digit)
%H24-hour (two-digit)
%I12-hour (two-digit)
%jday of year (three-digit)
%mmonth (two-digit)
%Mminutes
%pam/pm
%Sseconds
%smilliseconds
%Wweek in year (three-digit)
%wday of week (one-digit)
%yyear (two-digit)
%Yyear (four-digit)
%Ztime zone (name)
%ztime zone (+/-0800)

host

host properties
VARIABLEMEANING
nameThe name of the host
regexpRegular expression values for host regexp matches
rootThe root directory of the host
urlThe canonical url of the host

Example

<host regexp="www.([^.]+).com">
  <root-directory>/opt/www/${host.regexp[1]}</root-directory>

  <context-param server-id="${server.name}"/>

  <web-app id="/">
    <document-directory>webapps/ROOT</document-directory>
  </web-app>
</host>

java

java properties
VARIABLEMEANING
versionThe JDK version

jndi()

The configuration EL supports the static function jndi:lookup. jndi:lookup can be used to lookup a JNDI value for the configuration.

configuring JNDI
<servlet servlet-name='foo'
         servlet-class='qa.FooServlet'>
  <init>
    <data-source>${jndi:lookup("java:comp/env/jdbc/test")}</data-source>
  </init>
</servlet>

resin

resin properties
VARIABLEMEANING
addressThe local IP address
confPath to the configuration file
homeThe the location of the Resin executables
hostNameThe local hostname as returned by InetAddress
rootThe location of the content, specified at startup with --resin-root
serverIdThe identity of the active <server>, specified at startup with --server
versionThe resin version, e.g. 3.1.0

server

Values related to the active <server>.

server properties
VARIABLEMEANING
addressthe bind address of the cluster and load balancing port
idThe identity of the active <server>, specified at startup with --server
portthe cluster and load balancing port
httpAddressthe bind address of the http listener, INADDR_ANY for all addresses
httpPortthe port number of the http listener
httpsAddressthe bind address of the ssl http listener, INADDR_ANY for all addresses
httpsPortthe port number of the ssl http listener

System properties

System properties are available as variables in el expressions. Many system property names are not valid el identifiers; in that case the system variable is used, for example ${system['java.io.tmpdir']}.

A full list of standard java system properties is provided in the javadoc for java.lang.System.

Standard system properties
VARIABLEMEANING
java.io.tmpdirDefault temp file path
os.nameOperating system name
os.archOperating system architecture
os.versionOperating system version
user.nameUser's account name
user.homeUser's home directory
user.dirUser's current working directory

webApp

webApp properties
VARIABLEMEANING
nameThe name of the web-app
contextPathThe context path of the web-app
regexpRegular expression values for web-app regexp matches
rootThe root directory of the web-app
urlThe canonical url of the web app

Copyright © 1998-2012 Caucho Technology, Inc. All rights reserved. Resin ® is a registered trademark. Quercustm, and Hessiantm are trademarks of Caucho Technology.

Cloud-optimized Resin Server is a Java EE certified Java Application Server, and Web Server, and Distributed Cache Server (Memcached).
Leading companies worldwide with demand for reliability and high performance web applications including SalesForce.com, CNET, DZone and many more are powered by Resin.

home company blog wiki docs 
app server web server 
health cloud java ee pro