Eclipse Jetty Operations Guide
The Eclipse Jetty Operations Guide targets sysops, devops, and developers who want to install Eclipse Jetty as a standalone server to deploy web applications.
Introduction
If you are new to Eclipse Jetty, read here to download, install, start and deploy web applications to Jetty.
Eclipse Jetty Features
If you know Eclipse Jetty already, jump to a feature:
TODO
-
Jetty Overview
-
Jetty Modules
-
Rewrite Modules
Introduction to Eclipse Jetty
This section will get you started with Eclipse Jetty.
Quick Jetty Setup
Jetty is distributed in an artifact that expands in a directory called $JETTY_HOME, which should not be modified.
Configuration for Jetty is typically done in one (or more) other directories called $JETTY_BASE.
The following commands can be used to setup a $JETTY_BASE directory that supports deployment of *.war files and a clear-text HTTP connector:
$ export JETTY_HOME=/path/to/jetty-home $ mkdir /path/to/jetty-base $ cd /path/to/jetty-base $ java -jar $JETTY_HOME/start.jar --add-module=server,http,deploy
This will create a $JETTY_BASE/start.d/ directory and other directories that contain the configuration of the server, including the $JETTY_BASE/webapps/ directory, in which standard *.war files can be deployed.
To deploy Jetty’s demo web applications, run this command:
$ java -jar $JETTY_HOME/start.jar --add-module=demo
Now you can start the Jetty server with:
$ java -jar $JETTY_HOME/start.jar
Point your browser at http://localhost:8080 to see the web applications deployed in Jetty.
The Jetty server can be stopped with ctrl-c in the terminal window.
The following sections will guide you in details about downloading, installing and starting Jetty, as well as deploying your web applications to Jetty.
Downloading Eclipse Jetty
The Eclipse Jetty distribution is available for download from https://www.eclipse.org/jetty/download.html
The Eclipse Jetty distribution is available in both zip and gzip formats; download the one most appropriate for your system, typically zip for Windows and gzip for other operative systems.
Installing Eclipse Jetty
After the download, unpacking the Eclipse Jetty distribution will extract the files into a directory called jetty-distribution-VERSION, where VERSION is the version that you downloaded, for example 10.0.0, so that the directory is called jetty-distribution-10.0.0.
Unpack the Eclipse Jetty distribution compressed file in a convenient location, for example under /opt.
| For Windows users, you should unpack Jetty to a path that does not contain spaces. |
The rest of the instructions in this documentation will refer to this location as $JETTY_HOME, or ${jetty.home}.
| It is important that only stable release versions are used in production environments. Versions that have been deprecated or are released as Milestones (M), Alpha, Beta or Release Candidates (RC) are not suitable for production as they may contain security flaws or incomplete/non-functioning feature sets. |
If you are new to Jetty, read the Jetty architecture short section to become familiar with the terms used in this document. Otherwise, you can jump to the start Jetty section.
Eclipse Jetty Architecture Overview
There are two main concepts on which the Eclipse Jetty standalone server is based:
-
the Jetty module system, that provides the Jetty features
-
the
$JETTY_BASEdirectory, that provides a place where you configure the modules, and therefore the features, you need for your web applications
After installing Jetty, you want to setup a $JETTY_BASE directory where you configure Jetty modules.
Eclipse Jetty Architecture: Modules
The Jetty standalone server is made of components that are assembled together, configured and started to provide different features.
A Jetty module is made of one or more components that work together to provide typically one feature, although they may provide more than one feature.
A Jetty module is nothing more than Jetty components assembled together like you would do using Java APIs, just done in a declarative way using configuration files rather than using Java APIs. What you can do in Java code to assemble Jetty components, it can be done using Jetty modules.
A Jetty module may be dependent on other Jetty modules: for example, the http Jetty module depends on the server Jetty module, that in turn depends on the threadpool and logging Jetty modules.
Every feature in a Jetty server is enabled by enabling correspondent Jetty modules.
For example, if you enable only the http Jetty module, then your Jetty standalone server will only be able to listen to a network port for clear-text HTTP requests.
It will not be able to process secure HTTP (i.e. https) requests, it will not be able to process WebSocket, or HTTP/2 or any other protocol because the correspondent modules have not been enabled.
You can even start a Jetty server without listening on a network port — for example because you have enabled a custom module you wrote that provides the features you need.
This allows the Jetty standalone server to be as small as necessary: modules that are not enabled are not loaded, don’t waste memory, and you don’t risk that client use a module that you did not know was even there.
For more detailed information about the Jetty module system, see this section.
Eclipse Jetty Architecture: $JETTY_BASE
Instead of managing multiple Jetty implementations out of several different distribution locations, it is possible to maintain a separation between the binary installation of the standalone Jetty (known as ${jetty.home}), and the customizations for your specific environment(s) (known as ${jetty.base}).
In addition to easy management of multiple server instances, is allows for quick, drop-in upgrades of Jetty.
There should always only be one Jetty Home (per version of Jetty), but there can be multiple Jetty Base directories that reference it.
This separation between $JETTY_HOME and $JETTY_BASE allows upgrades without affecting your web applications.
$JETTY_HOME contains the Jetty runtime and libraries and the default configuration, while a $JETTY_BASE contains your web applications and any override of the default configuration.
For example, with the $JETTY_HOME installation the default value for the network port for clear-text HTTP is 8080.
However, you want that port to be 6060, for example because you are behind a load balancer that is configured to forward to the backend on port 6060.
Instead, you want to configure the clear-text HTTP port in your $JETTY_BASE.
When you upgrade Jetty, you will upgrade only files in $JETTY_HOME, and all the configuration in $JETTY_BASE will remain unchanged.
Installing the Jetty runtime and libraries in $JETTY_HOME also allows you to leverage file system permissions: $JETTY_HOME may be owned by an administrator user (so that only administrators can upgrade it), while $JETTY_BASE directories may be owned by a less privileged user.
If you had changed the default configuration in $JETTY_HOME, when you upgrade Jetty, say from version 10.0.0 to version 10.0.1, your change would be lost.
Maintaining all the changes in $JETTY_HOME, and having to reconfigure these with each upgrade results in a massive commitment of time and effort.
To recap:
$JETTY_BASE-
-
This is the location for your configurations and customizations to the Jetty distribution.
-
$JETTY_HOME-
-
This is the location for the Jetty distribution binaries, default XML IoC configurations, and default module definitions.
-
Jetty Home should always be treated as a standard of truth. All configuration modifications, changes and additions should always be made in the appropriate Jetty Base directory.
Eclipse Jetty Architecture: $JETTY_HOME and $JETTY_BASE Configuration Resolution
Potential configuration is resolved from these 2 directory locations. When Jetty starts up in processes configuration from them as follows:
- Check Jetty Base First
-
If the referenced configuration exists, relative to the defined Jetty base, it is used.
- Check Jetty Home Second
-
If the referenced configuration exists, relative to the defined Jetty home, it is used.
- Use java.io.File(String pathname) Logic
-
Lastly, use the reference as a
java.io.File(String pathname)reference, following the default resolution rules outlined by that constructor.In brief, the reference will be used as-is, be it relative (to current working directory, aka $\{user.dir}) or absolute path, or even network reference (such as on Windows and use of UNC paths).
Starting Eclipse Jetty
Eclipse Jetty as a standalone server has no graphical user interface, so configuring and running the server is done from the command line.
Recall from the Eclipse Jetty standalone server architecture section that Jetty is based on modules, that provides features, and on $JETTY_BASE, the place where you configure which module (and therefore which feature) you want to enable, and where you configure module parameters.
Jetty is started by executing $JETTY_HOME/start.jar, but first we need to create a $JETTY_BASE:
$ JETTY_BASE=/path/to/jetty.base $ cd $JETTY_BASE $ java -jar $JETTY_HOME/start.jar
ERROR : Nothing to start, exiting ...
Usage: java -jar $JETTY_HOME/start.jar [options] [properties] [configs]
java -jar $JETTY_HOME/start.jar --help # for more information
The error is normal, since the $JETTY_BASE you just created is empty and therefore there is no configuration to use to assemble the Jetty server.
However, it shows that start.jar takes parameters, whose details can be found in this section.
You can explore what modules are available out of the box via:
$ java -jar $JETTY_HOME/start.jar --list-modules=*
Try to enable the http module (see also this section for additional information):
$ java -jar $JETTY_HOME/start.jar --add-module=http
INFO : mkdir ${jetty.base}/start.d
INFO : server transitively enabled, ini template available with --add-module=server
INFO : logging-jetty transitively enabled
INFO : http initialized in ${jetty.base}/start.d/http.ini
INFO : resources transitively enabled
INFO : threadpool transitively enabled, ini template available with --add-module=threadpool
INFO : logging/slf4j dynamic dependency of logging-jetty
INFO : bytebufferpool transitively enabled, ini template available with --add-module=bytebufferpool
INFO : mkdir ${jetty.base}/resources
INFO : copy ${jetty.home}/modules/logging/jetty/resources/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties
INFO : Base directory was modified
Now you can start Jetty:
$ java -jar $JETTY_HOME/start.jar
2020-09-11 15:35:17.451:INFO :oejs.Server:main: jetty-10.0.0-SNAPSHOT; built: 2020-09-10T11:01:33.608Z; git: b10a14ebf9b200da388f4f9a2036bd8117ee0b11; jvm 11.0.8+10
2020-09-11 15:35:17.485:INFO :oejs.AbstractConnector:main: Started ServerConnector@2d52216b{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2020-09-11 15:35:17.496:INFO :oejs.Server:main: Started Server@44821a96{STARTING}[10.0.0-SNAPSHOT,sto=5000] @553ms
Note how Jetty is listening on port 8080 for clear-text HTTP/1.1 connections.
After having enabled the http module, the $JETTY_BASE directory looks like this:
JETTY_BASE
├── resources
│ └── jetty-logging.properties (1)
└── start.d (2)
└── http.ini (3)
| 1 | The resources/jetty-logging.properties file has been created because the http modules depends on the server module, which in turn depends on the logging module; the logging module created this file that can be configured to control the server logging level. |
| 2 | The start.d/ directory contains the configuration files for the modules. |
| 3 | The start.d/http.ini file is the http module configuration file, where you can specify values for the http module properties. |
In the http.ini file you can find the following content (among other content):
--module=http (1)
# jetty.http.port=8080 (2)
...
| 1 | This line enables the http module and should not be modified. |
| 2 | This line is commented out and specifies the default value for the module property jetty.http.port, which is the network port that listens for clear-text HTTP connections. |
You can change the module property jetty.http.port value directly from the command line:
$ java -jar $JETTY_HOME/start.jar jetty.http.port=9999
To make this change persistent, you can edit the http.ini file, uncomment the module property jetty.http.port and change its value to 9999:
--module=http jetty.http.port=9999 ...
If you restart Jetty, the new value will be used:
$ java -jar $JETTY_HOME/start.jar
2020-09-11 15:35:17.451:INFO :oejs.Server:main: jetty-10.0.0-SNAPSHOT; built: 2020-09-10T11:01:33.608Z; git: b10a14ebf9b200da388f4f9a2036bd8117ee0b11; jvm 11.0.8+10
2020-09-11 15:35:17.485:INFO :oejs.AbstractConnector:main: Started ServerConnector@2d52216b{HTTP/1.1, (http/1.1)}{0.0.0.0:9999}
2020-09-11 15:35:17.496:INFO :oejs.Server:main: Started Server@44821a96{STARTING}[10.0.0-SNAPSHOT,sto=5000] @553ms
Note how Jetty is now listening on port 9999 for clear-text HTTP/1.1 connections.
| If you want to enable support for different protocols such as secure HTTP/1.1 or HTTP/2, or configured Jetty behind a load balancer, read this section. |
The Jetty server is now up and running, but it has no web applications deployed, so it just replies with 404 Not Found to every request.
It is time to deploy your web applications to Jetty.
For more detailed information about the Jetty start system, you can read the Jetty start system section.
Deploying Web Applications to Eclipse Jetty
For the purpose of deploying web applications to Jetty, there are two types of resources that can be deployed:
-
Standard Web Application Archives, in the form of
*.warfiles or*.wardirectories, defined by the Servlet specification. Their deployment is described in this section. -
Jetty context XML files, that allow you to customize the deployment of standard web applications, and also allow you use Jetty components, and possibly custom components written by you, to assemble your web applications. Their deployment is described in this section.
Deploying Standard *.war Web Applications
A standard Servlet web application is packaged in either a *.war file or in a directory with the structure of a *.war file.
|
Recall that the structure of a
|
To deploy a standard web application, you need to enable the deploy module (see the deploy module complete definition here).
$ java -jar $JETTY_HOME/start.jar --add-module=deploy
INFO : webapp transitively enabled, ini template available with --add-module=webapp
INFO : security transitively enabled
INFO : servlet transitively enabled
INFO : deploy initialized in ${jetty.base}/start.d/deploy.ini
INFO : mkdir ${jetty.base}/webapps
INFO : Base directory was modified
The deploy module creates the $JETTY_BASE/webapps directory, the directory where *.war files or *.war directories should be copied so that Jetty can deploy them.
|
The Whether these web applications are served via clear-text HTTP/1.1, or secure HTTP/1.1, or secure HTTP/2 (or even all of these protocols) depends on whether the correspondent Jetty modules have been enabled. Refer to the section about protocols for further information. |
Now you need to copy a web application to the $JETTY_BASE/webapps directory:
curl https://repo1.maven.org/maven2/org/eclipse/jetty/test-jetty-webapp/10.0.0/test-jetty-webapp-10.0.0.war --output $JETTY_BASE/webapps/test.war
The $JETTY_BASE directory is now:
$JETTY_BASE
├── resources
│ └── jetty-logging.properties
├── start.d
│ ├── deploy.ini
│ └── http.ini
└── webapps
└── test.war
Now start Jetty:
$ java -jar $JETTY_HOME/start.jar
2020-09-16 09:53:38.182:INFO :oejs.Server:main: jetty-10.0.0-SNAPSHOT; built: 2020-09-16T07:47:47.334Z; git: d45455b32d96f516d39e03b53e91502a34b04f37; jvm 15+36-1562
2020-09-16 09:53:38.205:INFO :oejdp.ScanningAppProvider:main: Deployment monitor [file:///tmp/jetty.base/webapps/] at interval 1
2020-09-16 09:53:38.293:WARN :oejshC.test:main: The async-rest webapp is deployed. DO NOT USE IN PRODUCTION!
2020-09-16 09:53:38.298:INFO :oejw.StandardDescriptorProcessor:main: NO JSP Support for /test, did not find org.eclipse.jetty.jsp.JettyJspServlet
2020-09-16 09:53:38.306:INFO :oejss.DefaultSessionIdManager:main: DefaultSessionIdManager workerName=node0
2020-09-16 09:53:38.306:INFO :oejss.DefaultSessionIdManager:main: No SessionScavenger set, using defaults
2020-09-16 09:53:38.307:INFO :oejss.HouseKeeper:main: node0 Scavenging every 660000ms
2020-09-16 09:53:38.331:INFO :oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@45b4c3a9{Async REST Webservice Example,/test,[file:///tmp/jetty-0_0_0_0-8080-test_war-_test-any-15202033063643714058.dir/webapp/, jar:file:///tmp/jetty-0_0_0_0-8080-test_war-_test-any-15202033063643714058.dir/webapp/WEB-INF/lib/example-async-rest-jar-10.0.0-SNAPSHOT.jar!/META-INF/resources],AVAILABLE}{/tmp/jetty.base/webapps/test.war}
2020-09-16 09:53:38.338:INFO :oejs.AbstractConnector:main: Started ServerConnector@543295b0{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2020-09-16 09:53:38.347:INFO :oejs.Server:main: Started Server@5ffead27{STARTING}[10.0.0-SNAPSHOT,sto=5000] @593ms
Now you can access the web application by pointing your browser to http://localhost:8080/test.
If you want to customize the deployment of your web application, for example by specifying a contextPath different from the file/directory name, or by specifying JNDI entries, or by specifying virtual hosts, etc. read this section.
Using start.jar
TODO: review in light of Jetty 10
The most basic way of starting the Jetty standalone server is to execute the start.jar, which is a bootstrap for starting Jetty with the configuration you want.
[jetty-distribution-{VERSION}]$ java -jar start.jar
2013-09-23 11:27:06.654:INFO:oejs.Server:main: jetty-{VERSION}
...
Jetty is a highly modularized web server container. Very little is mandatory and required, and most components are optional; you enable or disable them according to the needs of your environment.
At its most basic, you configure Jetty from two elements:
-
A set of libraries and directories that make up the server classpath.
-
A set of Jetty XML configuration files (IoC style) that establish how to build the Jetty server and its components.
Instead of editing these directly, Jetty 9.1 introduced more options on how to configure Jetty (these are merely syntactic sugar that eventually resolve into the two basic configuration components).
Jetty Startup Features include:
-
A separation of the Jetty distribution binaries in
${jetty.home}and the environment specific configurations (and binaries) found in${jetty.base}(detailed in Managing Jetty Base and Jetty Home.) -
You can enable a set of libraries and XML configuration files via the newly introduced module system.
-
All of the pre-built XML configuration files shipped in Jetty are now parameterized with properties that you can specify in your
${jetty.base}/start.ini(demonstrated in Quick Start Configuration).
These are powerful new features, made to support a variety of styles of configuring Jetty, from a simple property based configuration, to handling multiple installations on a server, to customized stacks of technology on top of Jetty, and even the classic, custom XML configurations of old.
For example, if you use the ${jetty.base} concepts properly, you can upgrade the Jetty distribution without having to remake your entire tree of modifications to Jetty.
Simply separate out your specific modifications to the ${jetty.base}, and in the future, just upgrade your ${jetty.home} directory with a new Jetty distribution.
Executing start.jar
When executed start.jar performs the following actions:
-
Loads and parses all INIs found in
${jetty.base}/start.d/*.inias command line arguments. -
Loads and parses
${jetty.base}/start.inias command line arguments.-
Please see Start.ini vs. Start.d for more information on the difference between these.
-
-
Parses actual command line arguments used to execute
start.jaritself. -
Resolves any XML configuration files, modules, and libraries using base vs. home resolution steps:
-
Checks whether file exists as relative reference to
${jetty.base}. -
Checks whether file exists as relative reference to
${jetty.home}. -
Uses default behavior of
java.io.File(Relative toSystem.getProperty("user.dir") and then as absolute file system path).
-
-
Loads any dependent modules (merges XXNK, library, and properties results with active command line).
-
Builds out server classpath.
-
Determines run mode as one of:
-
Shows informational command line options and exit.
-
Executes Jetty normally, waits for Jetty to stop.
-
Executes a forked JVM to run Jetty in, waits for forked JVM to exit.
-
start.jar Command Line Options
Command Line Options
- --help
-
Obtains the current list of command line options and some basic usage help.
- --version
-
Shows the list of server classpath entries, and prints version information found for each entry.
- --list-classpath
-
Similar to --version, shows the server classpath.
- --list-config
-
Lists the resolved configuration that will start Jetty.
-
Java environment
-
Jetty environment
-
JVM arguments
-
Properties
-
Server classpath
-
Server XML configuration files
-
- --dry-run
-
Print the command line that the start.jar generates, then exit. This may be used to generate command lines when the start.ini includes -X or -D arguments:
$ java -jar start.jar --dry-run > jetty.sh $ . jetty.sh
- --dry-run=<parts>
-
Print specific parts of the command line. The parts are a comma separated list of:
-
"java" - the JVM to run
-
"opts" - the JVM options (eg -D and -X flags)
-
"path" - the JVM class path or JPMS modules options
-
"main" - the main class to run
-
"args" - the arguments passed to the main class
-
It is possible to decompose the start command:
$ OPTS=$(java -jar start.jar --dry-run=opts,path) $ MAIN=$(java -jar start.jar --dry-run=main) $ ARGS=$(java -jar start.jar --dry-run=args) $ java $OPTS -Dextra=opt $MAIN $ARGS extra=arg
Alternatively to create an args file for java:
$ java -jar start.jar --dry-run=opts,path,main,args > /tmp/args $ java @/tmp/args
- --exec
-
Forces the start to use a forked instance of java to run Jetty. Some modules include
--execin order to set java command line options. Some start options, such as--jpmsalso imply--exec - --exec-properties=<filename>
-
Assign a fixed name to the file used to transfer properties to the sub process. This allows the generated properties file to be saved and reused. Without this option, a temporary file is used.
- --commands=<filename>
-
Instructs
start.jarto use each line of the specified file as arguments on the command line.
Debug and Start Logging
- --debug
-
Enables debugging output of the startup procedure.
Note: This does not set up debug logging for Jetty itself. For information on logging, please see the section on Configuring Jetty Logging.]
- --start-log-file=<filename>
-
Sends all startup output to the filename specified. Filename is relative to
${jetty.base}. This is useful for capturing startup issues where the Jetty-specific logger has not yet kicked in due to a possible startup configuration error.
Module Management
- --list-modules
-
Lists all the modules defined by the system. Looks for module files using the normal
${jetty.base}and${jetty.home}resolution logic. Also lists enabled state based on information present on the command line, and all active startup INI files. - --list-modules=<tag>(,<tag>)*
-
List modules by tag. Use '*' for all tags. Prefix a tag with '-' to exclude the tag. The special tag "internal" is always excluded unless it is explicitly included.
- --list-all-modules
-
List all modules.
- --module=<name>,(<name>)*
-
Enables one or more modules by name (use
--list-modulesto see the list of available modules). This enables all transitive (dependent) modules from the module system as well. If you use this from the shell command line, it is considered a temporary effect, useful for testing out a scenario. If you want this module to always be enabled, add this command to your${jetty.base}/start.ini. - --add-to-start=<name>,(<name>)*
-
Enables a module by appending lines to the
${jetty.base}/start.inifile. The lines that are added are provided by the module-defined INI templates. Note: Transitive modules are also appended. If a module contains an .ini template with properties, you can also edit these properties when activating the module. To do this, simply list the property and its value after the-add-to-startcommand, such as in the following example:$ java -jar start.jar --add-to-start=http jetty.http.port=8379 jetty.http.host=1.2.3.4
Doing this will uncomment the property in the associated .ini file and set it to the value specified.
- --update-ini
-
Used to update a specified property or properties that exist in an existing .ini file. Jetty scans the command line,
${jetty.base}and${jetty.home}for .ini files that have the specified property and update it accordingly.[my-base]$ java -jar /path/to/jetty-home/start.jar --update-ini jetty.http.port=8417 ConfigSource <command-line> ConfigSource ${jetty.base} INFO : http property updated jetty.http.port=8417 INFO : http updated ${jetty.base}/start.d/http.ini ConfigSource ${jetty.home} - --create-startd
-
Creates a
${jetty.base}/start.d/directory. If a${jetty.base}/start.inifile already exists, it is copied to the${jetty.base}/start.ddirectory.
|
With respect to |
- --write-module-graph=<filename>
-
Advanced feature: Creates a graphviz dot file of the module graph as it exists for the active
${jetty.base}.# generate module.dot $ java -jar start.jar --module=websocket --write-module-graph=modules.dot # post process to a PNG file $ dot -Tpng -o modules.png modules.dot
See graphviz.org for details on how to post-process this dotty file into the output best suited for your needs.
- --create-files
-
Create any missing files that are required by initialized modules. This may download a file from the network if the module provides a URL.
- --skip-file-validation=<modulename>(,<modulename)*
-
Disable the [files] section validation of content in the
${jetty.base}directory for a specific module. Useful for modules that have downloadable content that is being overridden with alternatives in the${jetty.base}`directory.
This advanced option is for administrators that fully understand the configuration of their ${jetty.base}and are willing to forego some of the safety checks built into the jetty-start mechanism.
- --approve-all-licenses
-
Approve all license questions. Useful for enabling modules from a script that does not require user interaction.
Startup / Shutdown Command Line
- --stop
-
Sends a stop signal to the running Jetty instance.
Note: The server must have been started with various stop properties for this to work.
- STOP.PORT=<number>
-
The port to use to stop the running Jetty server. This is an internal port, opened on localhost, used solely for stopping the running Jetty server. Choose a port that you do not use to serve web traffic.
Required for
--stopto function. - STOP.KEY=<alphanumeric>
-
The passphrase defined to stop the server.
Required for
--stopto function. - STOP.WAIT=<number>
-
The time (in seconds) to wait for confirmation that the running Jetty server has stopped. If not specified, the stopper waits indefinitely for the server to stop.
If the time specified elapses, without a confirmation of server stop, then the
--stopcommand exits with a non-zero return code.
You can configure a port number for Jetty to listen on for a stop command, so you are able to stop it from a different terminal.
This requires the use of a "secret" key, to prevent malicious or accidental termination.
Use the STOP.PORT and STOP.KEY (or -DSTOP.PORT= and -DSTOP.KEY=, respectively, which will set these as system parameters) parameters as arguments to the start.jar:
> java -jar ${JETTY_HOME}/start.jar STOP.PORT=1234 STOP.KEY=secretpassword
Then, to stop Jetty from a different terminal, you need to supply this port and key information.
You can either use a copy of the Jetty distribution, the jetty-maven-plugin, the jetty-ant plugin, or a custom class to accomplish this.
Here’s how to use the Jetty distribution, leveraging start.jar, to perform a stop:
> java -jar start.jar STOP.PORT=8181 STOP.KEY=abc123 --stop
To perform a graceful shutdown of Jetty, the statsmodule must be enabled.
Advanced Commands
- --lib=<classpath>
-
Add arbitrary classpath entries to the the server classpath.
- --include-jetty-dir=<path>
-
Include an extra Jetty directory to use as a source for configuration details. This directory behaves similarly to
${jetty.base}but sits at a layer between${jetty.base}and${jetty.home}. This allows for some complex hierarchies of configuration details. - --download=<http-uri>|<location>
-
If the file does not exist at the given location, download it from the given http URI. Note: location is always relative to
${jetty.base}. You might need to escape the slash "\|" to use this on some environments. - maven.repo.uri=[url]
-
The url to use to download Maven dependencies. Default is https://repo1.maven.org/maven2/.
Shaded Start.jar
If you have a need for a shaded version of start.jar (such as for Gradle), you can achieve this via a Maven dependency.
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-start</artifactId>
<version>{VERSION}</version>
<classifier>shaded</classifier>
</dependency>
Start.jar without exec or forking.
Some Jetty modules include the --exec option so that java command line options can be set.
Also some start.jar options (eg. --jpms) include an implicit --exec.
To start jetty without forking a new JVM instance from the start JVM, the --dry-run option can be used to generate a command line:
$ CMD=$(java -jar start.jar --dry-run) $ $CMD
It is possible to decompose the start command so that it can be modified:
$ OPTS=$(java -jar start.jar --dry-run=opts,path) $ MAIN=$(java -jar start.jar --dry-run=main) $ ARGS=$(java -jar start.jar --dry-run=args) $ java $OPTS -Dextra=opt $MAIN $ARGS extra=arg
Alternatively to create an args file for java:
$ java -jar start.jar --dry-run=opts,path,main,args > /tmp/args $ java @/tmp/args
Customizing Web Application Deployment
Most of the times you want to be able to customize the deployment of your web applications, for example by changing the contextPath, or by adding JNDI entries, or by configuring virtual hosts, etc.
The customization is performed by the deploy module by processing Jetty context XML files.
The deploy module contains the DeploymentManager component that scans the $JETTY_BASE/webapps directory for changes, following the deployment rules described in this section.
Hot vs Static Deployment
The DeploymentManager scans the $JETTY_BASE/webapps directory for changes every N seconds, where N is configured via the jetty.deploy.scanInterval property.
By default, the scan interval is 1 second, which means that hot deployment is enabled: if a file is added/changed/removed from the $JETTY_BASE/webapps directory, the DeploymentManager will notice the change and respectively deploy/redeploy/undeploy the web application.
Setting the scan interval to 0 means that static deployment is enabled, and the DeploymentManager will not scan the $JETTY_BASE/webapps directory for changes.
This means that to deploy/redeploy/undeploy a web application you will need to stop and restart Jetty.
The following command line disables hot deployment by specifying the jetty.deploy.scanInterval property on the command line, and therefore only for this particular run:
$ java -jar $JETTY_HOME/start.jar jetty.deploy.scanInterval=0
To make static deployment persistent, you need to edit the deploy module configuration file, $JETTY_BASE/start.d/deploy.ini, uncomment the module property jetty.deploy.scanInterval and change its value to 0:
--module=deploy
jetty.deploy.scanInterval=0
...
Deployment Rules
Adding a *.war file, a *.war directory, a Jetty context XML file or a normal directory to $JETTY_BASE/webapps causes the DeploymentManager to deploy the new web application.
Updating a *.war file or a Jetty context XML file causes the DeploymentManager to redeploy the web application, which means that the Jetty context component representing the web application is stopped, then reconfigured, and then restarted.
Removing a *.war file, a *.war directory, a Jetty context XML file or a normal directory from $JETTY_BASE/webapps causes the DeploymentManager to undeploy the web application, which means that the Jetty context component representing the web application is stopped and removed from the Jetty server.
When a file or directory is added to $JETTY_BASE/webapps, the DeploymentManager derives the web application contextPath from the file or directory name, with the following rules:
-
If the directory name is, for example,
mywebapp/, it is deployed as a standard web application if it contains aWEB-INF/subdirectory, otherwise it is deployed as a web application of static content. ThecontextPathwould be/mywebapp(that is, the web application is reachable athttp://localhost:8080/mywebapp/). -
If the directory name is
ROOT, case insensitive, thecontextPathis/(that is, the web application is reachable athttp://localhost:8080/). -
If the directory name ends with
.d, for exampleconfig.d/, it is ignored, although it may be referenced to configure other web applications (for example to store common files). -
If the
*.warfile name is, for example,mywebapp.war, it is deployed as a standard web application with the context path/mywebapp(that is, the web application is reachable athttp://localhost:8080/mywebapp/). -
If the file name is
ROOT.war, case insensitive, thecontextPathis/(that is, the web application is reachable athttp://localhost:8080/). -
If both the
mywebapp.warfile and themywebapp/directory exist, only the file is deployed. This allows the directory with the same name to be the*.warfile unpack location and avoid that the web application is deployed twice. -
A Jetty context XML file named
mywebapp.xmlis deployed as a web application by processing the directives contained in the XML file itself, which must set thecontextPath. -
If both
mywebapp.xmlandmywebapp.warexist, only the XML file is deployed. This allows the XML file to reference the*.warfile and avoid that the web application is deployed twice.
Deploying Jetty Context XML Files
A Jetty context XML file is a Jetty XML file that allows you to customize the deployment of web applications.
Recall that the DeploymentManager component of the Jetty deploy module gives priority to Jetty context XML files over *.war files or directories.
|
To deploy a web application using a Jetty context XML file, simply place the file in the $JETTY_BASE/webapps directory.
A simple Jetty context XML file, for example named wiki.xml is the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext"> (1)
<Set name="contextPath">/wiki</Set> (2)
<Set name="war">/opt/myapps/myapp.war</Set> (3)
</Configure>
| 1 | Configures a WebAppContext, which is the Jetty component that represents a standard Servlet web application. |
| 2 | Specifies the web application contextPath, which may be different from the *.war file name. |
| 3 | Specifies the file system path of the *.war file. |
The $JETTY_BASE directory would look like this:
$JETTY_BASE
├── resources
│ └── jetty-logging.properties
├── start.d
│ ├── deploy.ini
│ └── http.ini
└── webapps
└── wiki.xml
The *.war file may be placed anywhere in the file system and does not need to be placed in the $JETTY_BASE/webapps directory.
|
If you place both the Jetty context XML file and the *.war file in the $JETTY_BASE/webapps directory, remember that they must have the same file name, for example wiki.xml and wiki.war, so that the DeploymentManager deploys the web application only once using the Jetty context XML file (and not the *.war file).
|
You can use the features of Jetty XML files to avoid to hard-code file system paths or other configurations in your Jetty context XML files, for example by using system properties:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/wiki</Set>
<Set name="war"><SystemProperty name="myapps.dir"/>/myapp.war</Set>
</Configure>
Note how the *.war file path is now obtained by resolving the system property myapps.dir that you can specify on the command line when you start Jetty:
$ java -jar $JETTY_HOME/start.jar -Dmyapps.dir=/opt/myapps
Configuring JNDI Entries
A web application may reference a JNDI entry, such as a JDBC DataSource from the web application web.xml file.
The JNDI entry must be defined in the Jetty context XML file, for example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/mywebapp</Set>
<Set name="war">/opt/webapps/mywebapp.war</Set>
<New class="org.eclipse.jetty.plus.jndi.Resource">
<Arg />
<Arg>jdbc/myds</Arg>
<Arg>
<New class="com.mysql.cj.jdbc.MysqlConnectionPoolDataSource">
<Set name="url">jdbc:mysql://localhost:3306/databasename</Set>
<Set name="user">user</Set>
<Set name="password">password</Set>
</New>
</Arg>
</New>
</Configure>
|
Class File |
Configuring Virtual Hosts
A virtual host is an internet domain name, registered in the Domain Name Server (DNS), for an IP address such that multiple virtual hosts will resolve to the same IP address of a single server instance.
If you have multiple web applications deployed on the same Jetty server, by using virtual hosts you will be able to target a specific web application.
For example, you may have a web application for your business and a web application for your hobbies , both deployed in the same Jetty server.
By using virtual hosts, you will be able to have the first web application available at http://domain.biz/, and the second web application available at http://hobby.net/.
Another typical case is when you want to use different subdomains for different web application, for example a project website is at http://project.org/ and the project documentation is at http://docs.project.org.
Virtual hosts can be used with any context that is a subclass of ContextHandler.
Virtual Host Names
Jetty supports the following variants to be specified as virtual host names:
www.hostname.com-
A fully qualified domain name. It is important to list all variants as a site may receive traffic for both
www.hostname.comandhostname.com. *.hostname.com-
A wildcard domain name which will match only one level of arbitrary subdomains. *.foo.com will match www.foo.com and m.foo.com, but not www.other.foo.com.
10.0.0.2-
An IP address may be set as a virtual host to indicate that a web application should handle requests received on the network interface with that IP address for protocols that do not indicate a host name such as HTTP/0.9 or HTTP/1.0.
@ConnectorName-
A Jetty
ServerConnectorname to indicate that a web application should handle requests received on theServerConnectorwith that name, and therefore received on a specific IP port. AServerConnectorname can be set via http://www.eclipse.org/jetty/javadoc/10.0.0.beta2/org/eclipse/jetty/server/AbstractConnector.html#setName(java.lang.String). www.√integral.com-
Non-ASCII and IDN domain names can be set as virtual hosts using Puny Code equivalents that may be obtained from a Punycode/IDN converters. For example if the non-ASCII domain name
www.√integral.comis given to a browser, then the browser will make a request that uses the domain namewww.xn—integral-7g7d.com, which is the name that should be added as the virtual host name.
Virtual Hosts Configuration
If you have a web application mywebapp.war you can configure its virtual hosts in this way:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/mywebapp</Set>
<Set name="war">/opt/webapps/mywebapp.war</Set>
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>mywebapp.com</Item>
<Item>www.mywebapp.com</Item>
<Item>mywebapp.net</Item>
<Item>www.mywebapp.net</Item>
</Array>
</Set>
</Configure>
Your web application will be available at:
-
http://mywebapp.com/mywebapp -
http://www.mywebapp.com/mywebapp -
http://mywebapp.net/mywebapp -
http://www.mywebapp.net/mywebapp
|
You configured the As such, a request to Likewise, a request to |
Same Context Path, Different Virtual Hosts
If you want to deploy different web applications to the same context path, typically the root context path /, you must use virtual hosts to differentiate among web applications.
You have domain.war that you want to deploy at http://domain.biz/ and hobby.war that you want to deploy at http://hobby.net.
To achieve this, you simply use the same context path of / for each of your webapps, while specifying different virtual hosts for each of your webapps:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war">/opt/webapps/domain.war</Set>
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>domain.biz</Item>
</Array>
</Set>
</Configure>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war">/opt/webapps/hobby.war</Set>
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>hobby.net</Item>
</Array>
</Set>
</Configure>
Different Port, Different Web Application
Sometimes it is required to serve different web applications from different IP ports, and therefore from different ServerConnectors.
For example, you want requests to http://localhost:8080/ to be served by one web application, but requests to http://localhost:9090/ to be served by another web application.
This configuration may be useful when Jetty sits behind a load balancer.
In this case, you want to configure multiple connectors, each with a different name, and then reference the connector name in the web application virtual host configuration:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war">/opt/webapps/domain.war</Set>
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>@port8080</Item>
</Array>
</Set>
</Configure>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war">/opt/webapps/hobby.war</Set>
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>@port9090</Item>
</Array>
</Set>
</Configure>
|
Web application Likewise, web application See this section for further information about how to configure connectors. |
Configuring *.war File Extraction
By default, *.war files are uncompressed and its content extracted in a temporary directory.
The web application resources are served by Jetty from the files extracted in the temporary directory, not from the files within the *.war file, for performance reasons.
If you do not want Jetty to extract the *.war files, you can disable this feature, for example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/mywebapp</Set>
<Set name="war">/opt/webapps/mywebapp.war</Set>
<Set name="extractWAR">false</Set>
</Configure>
Overriding web.xml
You can configure an additional web.xml that complements the web.xml file that is present in the web application *.war file.
This additional web.xml is processed after the *.war file web.xml.
This allows you to add host specific configuration or server specific configuration without having to extract the web application web.xml, modify it, and repackage it in the *.war file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/mywebapp</Set>
<Set name="war">/opt/webapps/mywebapp.war</Set>
<Set name="overrideDescriptor">/opt/webapps/mywebapp-web.xml</Set>
</Configure>
The format of the additional web.xml is exactly the same as a standard web.xml file, for example:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>my-servlet</servlet-name>
<init-param>
<param-name>host</param-name>
<param-value>192.168.0.13</param-value>
</init-param>
</servlet>
</web-app>
In the example above, you configured the my-servlet Servlet (defined in the web application web.xml), adding a host specific init-param with the IP address of the host.
Configuring Eclipse Jetty Connectors and Protocols
Connectors are the network components through which Jetty accepts incoming network connections.
Each connector listens on a network port and can be configured with ConnectionFactory components that understand one or more network protocols.
Understanding a protocol means that the connector is able to interpret incoming network bytes (for example, the bytes that represent an HTTP/1.1 request) and convert them into more abstract objects (for example an HttpServletRequest object) that are then processed by applications.
Conversely, an abstract object (for example an HttpServletResponse) is converted into the correspondent outgoing network bytes (the bytes that represent an HTTP/1.1 response).
Like other Jetty components, connectors are enabled and configured by enabling and configuring the correspondent Jetty module.
Recall that you must always issue the commands to enable Jetty modules from within the $JETTY_BASE directory, and that the Jetty module configuration files are in the $JETTY_BASE/start.d/ directory.
|
You can obtain the list of connector-related modules in this way:
$ java -jar $JETTY_HOME/start.jar --list-modules=connector
Configuring Clear-Text HTTP/1.1
Clear text HTTP/1.1 is enabled with the http Jetty module with the following command (issued from within the $JETTY_BASE directory):
$ java -jar $JETTY_HOME/start.jar --add-module=http
INFO : mkdir ${jetty.base}/start.d
INFO : server transitively enabled, ini template available with --add-module=server
INFO : logging-jetty transitively enabled
INFO : http initialized in ${jetty.base}/start.d/http.ini
INFO : resources transitively enabled
INFO : threadpool transitively enabled, ini template available with --add-module=threadpool
INFO : logging/slf4j dynamic dependency of logging-jetty
INFO : bytebufferpool transitively enabled, ini template available with --add-module=bytebufferpool
INFO : mkdir ${jetty.base}/resources
INFO : copy ${jetty.home}/modules/logging/jetty/resources/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties
INFO : Base directory was modified
After having enabled the http module, the $JETTY_BASE directory looks like this:
JETTY_BASE
├── resources
│ └── jetty-logging.properties
└── start.d
└── http.ini
The http.ini file is the file that you want to edit to configure network and protocol parameters — for more details see this section.
Note that the http Jetty module depends on the server Jetty module.
Some parameters that you may want to configure are in fact common HTTP parameters that are applied not only for clear-text HTTP/1.1, but also for secure HTTP/1.1 or for clear-text HTTP/2 or for encrypted HTTP/2, and these configuration parameters may be present in the server module configuration file.
You can force the creation of the server.ini file via:
$ java -jar $JETTY_HOME/start.jar --add-module=server
Now the $JETTY_BASE directory looks like this:
JETTY_BASE
├── resources
│ └── jetty-logging.properties
└── start.d
├── http.ini
└── server.ini
Now you can edit the server.ini file — for more details see this section.
Configuring Secure HTTP/1.1
Secure HTTP/1.1 is enabled with both the ssl and https Jetty modules with the following command (issued from within the $JETTY_BASE directory):
$ java -jar $JETTY_HOME/start.jar --add-modules=ssl,https
INFO : mkdir ${jetty.base}/start.d
INFO : server transitively enabled, ini template available with --add-module=server
INFO : logging-jetty transitively enabled
INFO : resources transitively enabled
INFO : https initialized in ${jetty.base}/start.d/https.ini
INFO : ssl initialized in ${jetty.base}/start.d/ssl.ini
INFO : threadpool transitively enabled, ini template available with --add-module=threadpool
INFO : logging/slf4j transitive provider of logging/slf4j for logging-jetty
INFO : logging/slf4j dynamic dependency of logging-jetty
INFO : bytebufferpool transitively enabled, ini template available with --add-module=bytebufferpool
INFO : mkdir ${jetty.base}/resources
INFO : copy ${jetty.home}/modules/logging/jetty/resources/jetty-logging.properties to ${jetty.base}/resources/jetty-logging.properties
INFO : Base directory was modified
The command above enables the ssl module, that provides the secure network connector, the keystore configuration and TLS configuration — for more details see this section.
Then, the https module adds HTTP/1.1 as the protocol secured by TLS.
The $JETTY_BASE directory looks like this:
$JETTY_BASE
├── resources
│ └── jetty-logging.properties
└── start.d
├── https.ini
└── ssl.ini
Note that the keystore file is missing, because you have to provide one with the cryptographic material you want (read this section to create your own keystore).
You need to configure these two properties by editing ssl.ini:
-
jetty.sslContext.keyStorePath -
jetty.sslContext.keyStorePassword
As a quick example, you can enable the test-keystore module, that provides a keystore containing a self-signed certificate:
$ java -jar $JETTY_HOME/start.jar --add-modules=test-keystore
INFO : test-keystore initialized in ${jetty.base}/start.d/test-keystore.ini
INFO : mkdir ${jetty.base}/etc
INFO : copy ${jetty.home}/modules/test-keystore/test-keystore.p12 to ${jetty.base}/etc/test-keystore.p12
INFO : Base directory was modified
The $JETTY_BASE directory is now:
├── etc
│ └── test-keystore.p12
├── resources
│ └── jetty-logging.properties
└── start.d
├── https.ini
├── ssl.ini
└── test-keystore.ini
Starting Jetty yields:
$ java -jar $JETTY_HOME/start.jar
2020-09-22 08:40:49.482:INFO :oejs.Server:main: jetty-10.0.0-SNAPSHOT; built: 2020-09-21T14:44:05.094Z; git: 5c33f526e5b7426dd9644ece61b10184841bb8fa; jvm 15+36-1562
2020-09-22 08:40:49.709:INFO :oejus.SslContextFactory:main: x509=X509@14cd1699(mykey,h=[localhost],w=[]) for Server@73a1e9a9[provider=null,keyStore=file:///tmp/jetty.base/etc/test-keystore.p12,trustStore=file:///tmp/jetty.base/etc/test-keystore.p12]
2020-09-22 08:40:49.816:INFO :oejs.AbstractConnector:main: Started ServerConnector@2e1d27ba{SSL, (ssl, http/1.1)}{0.0.0.0:8443}
2020-09-22 08:40:49.828:INFO :oejs.Server:main: Started Server@2f177a4b{STARTING}[10.0.0-SNAPSHOT,sto=5000] @814ms
Note how Jetty is listening on port 8443 for the secure HTTP/1.1 protocol.
|
If you point your browser at This is normal because the certificate contained in |
Configuring HTTP/2
HTTP/2 is the successor of the HTTP/1.1 protocol, but it is quite different from HTTP/1.1: where HTTP/1.1 is a duplex, text-based protocol, HTTP/2 is a multiplex, binary protocol.
Because of these fundamental differences, a client and a server need to negotiate what version of the HTTP protocol they speak, based on what versions each side supports.
To ensure maximum compatibility, and reduce the possibility that an intermediary that only understands HTTP/1.1 will close the connection when receiving unrecognized HTTP/2 bytes, HTTP/2 is typically deployed over secure connections, using the TLS protocol to wrap HTTP/2.
| Browsers only support secure HTTP/2. |
The protocol negotiation is performed by the ALPN TLS extension: the client advertises the list of protocols it can speak, and the server communicates to the client the protocol chosen by the server.
For example, you can have a client that only supports HTTP/1.1 and a server that supports both HTTP/1.1 and HTTP/2:
Nowadays, it’s common that both clients and servers support HTTP/2, so servers prefer HTTP/2 as the protocol to speak:
When you configure a connector with the HTTP/2 protocol, you typically want to also configure the HTTP/1.1 protocol. The reason to configure both protocols is that you typically do not control the clients: for example an old browser that does not support HTTP/2, or a monitoring console that performs requests using HTTP/1.1, or a heartbeat service that performs a single HTTP/1.0 request to verify that the server is alive.
Secure vs Clear-Text HTTP/2
Deciding whether you want to configure Jetty with secure HTTP/2 or clear-text HTTP/2 depends on your use case.
You want to configure secure HTTP/2 when Jetty is exposed directly to browsers, because browsers only support secure HTTP/2.
You may configure clear-text HTTP/2 (mostly for performance reasons) if you offload TLS at a load balancer (for example, HAProxy) or at a reverse proxy (for example, nginx).
You may configure clear-text HTTP/2 (mostly for performance reasons) to call microservices deployed to different Jetty servers (although you may want to use secure HTTP/2 for confidentiality reasons).
Configuring Secure HTTP/2
When you enable secure HTTP/2 you typically want to enable also secure HTTP/1.1, for backwards compatibility reasons: in this way, old browsers or other clients that do not support HTTP/2 will be able to connect to your server.
You need to enable:
-
the
sslJetty module, which provides the secure connector and the keystore and TLS configuration -
the
http2Jetty module, which adds ALPN handling and adds the HTTP/2 protocol to the secured connector -
optionally, the
httpsJetty module, which adds the HTTP/1.1 protocol to the secured connector
Use the following command (issued from within the $JETTY_BASE directory):
$ java -jar $JETTY_HOME/start.jar --add-modules=ssl,http2,https
As when enabling the https Jetty module, you need a valid keystore (read this section to create your own keystore).
As a quick example, you can enable the test-keystore module, that provides a keystore containing a self-signed certificate:
$ java -jar $JETTY_HOME/start.jar --add-modules=test-keystore
Starting Jetty yields:
$ java -jar $JETTY_HOME/start.jar
2020-09-29 19:00:47.316:INFO :oejs.Server:main: jetty-10.0.0-SNAPSHOT; built: 2020-09-29T13:28:40.441Z; git: 9c0082610528a846b366ae26f4c74894579a8e48; jvm 15+36-1562
2020-09-29 19:00:47.528:INFO :oejus.SslContextFactory:main: x509=X509@7770f470(mykey,h=[localhost],w=[]) for Server@24313fcc[provider=null,keyStore=file:///tmp/jetty.base/etc/test-keystore.p12,trustStore=file:///tmp/jetty.base/etc/test-keystore.p12]
2020-09-29 19:00:47.621:INFO :oejs.AbstractConnector:main: Started ServerConnector@73700b80{SSL, (ssl, alpn, h2, http/1.1)}{0.0.0.0:8443}
2020-09-29 19:00:47.630:INFO :oejs.Server:main: Started Server@30ee2816{STARTING}[10.0.0-SNAPSHOT,sto=5000] @746ms
Note how Jetty is listening on port 8443 and the protocols supported are the sequence (ssl, alpn, h2, http/1.1).
The (ordered) list of protocols after alpn are the application protocols, in the example above (h2, http/1.1).
When a new connection is accepted by the connector, Jetty first interprets the TLS bytes, then it handles the ALPN negotiation knowing that the application protocols are (in order) h2 and then http/1.1.
You can customize the list of application protocols and the default protocol to use in case the ALPN negotiation fails by editing the alpn module properties.
The HTTP/2 protocol parameters can be configured by editing the http2 module properties.
Configuring Clear-Text HTTP/2
When you enable clear-text HTTP/2 you typically want to enable also clear-text HTTP/1.1, for backwards compatibility reasons and to allow clients to upgrade from HTTP/1.1 to HTTP/2.
You need to enable:
-
the
httpJetty module, which provides the clear-text connector and adds the HTTP/1.1 protocol to the clear-text connector -
the
http2cJetty module, which adds the HTTP/2 protocol to the clear-text connector
$ java -jar $JETTY_HOME/start.jar --add-modules=http,http2c
Starting Jetty yields:
$ java -jar $JETTY_HOME/start.jar
2020-09-30 09:18:36.322:INFO :oejs.Server:main: jetty-10.0.0-SNAPSHOT; built: 2020-09-29T22:40:09.015Z; git: ba5f91fe00a68804a586b7dd4e2520c8c948dcc8; jvm 15+36-1562
2020-09-30 09:18:36.349:INFO :oejs.AbstractConnector:main: Started ServerConnector@636be97c{HTTP/1.1, (http/1.1, h2c)}{0.0.0.0:8080}
2020-09-30 09:18:36.361:INFO :oejs.Server:main: Started Server@3c72f59f{STARTING}[10.0.0-SNAPSHOT,sto=5000] @526ms
Note how Jetty is listening on port 8080 and the protocols supported are HTTP/1.1 and h2c (i.e. clear-text HTTP/2).
With this configuration, browsers and client applications will be able to connect to port 8080 using:
-
HTTP/1.1 directly (e.g.
curl --http1.1 http://localhost:8080):
GET / HTTP/1.1 Host: localhost:8080
-
HTTP/1.1 with upgrade to HTTP/2 (e.g.
curl --http2 http://localhost:8080):
GET / HTTP/1.1 Host: localhost:8080 Connection: Upgrade, HTTP2-Settings Upgrade: h2c HTTP2-Settings:
-
HTTP/2 directly (e.g.
curl --http2-prior-knowledge http://localhost:8080):
50 52 49 20 2a 20 48 54 54 50 2f 32 2e 30 0d 0a 0d 0a 53 4d 0d 0a 0d 0a 00 00 12 04 00 00 00 00 00 00 03 00 00 00 64 00 04 40 00 00 00 00 02 00 00 00 00 00 00 1e 01 05 00 00 00 01 82 84 86 41 8a a0 e4 1d 13 9d 09 b8 f0 1e 07 7a 88 25 b6 50 c3 ab b8 f2 e0 53 03 2a 2f 2a
The HTTP/2 protocol parameters can be configured by editing the http2c module properties.
Configuring Secure Protocols
Secure protocols are normal protocols such as HTTP/1.1 or WebSocket that are wrapped by the TLS protocol. Any network protocol can be wrapped with TLS.
The https scheme used in URIs really means tls+http/1.1 and similarly the wss scheme used in URIs really means tls+websocket, etc.
Senders wrap the underlying protocol bytes (e.g. HTTP/1.1 bytes or WebSocket bytes) with the TLS protocol, while receivers first interpret the TLS protocol to obtain the underlying protocol bytes, and then interpret the wrapped bytes.
Secure protocols have a slightly more complicated configuration since they require to configure a keystore.
A keystore is a file on the file system that contains a private key and a public certificate, along with the certificate chain of the certificate authorities that issued the certificate. The private key, the public certificate and the certificate chain, but more generally the items present in a keystore, are typically referred to as "cryptographic material".
Keystores may encode the cryptographic material with different encodings, the most common being PKCS12, and are typically protected by a password.
After configuring the keystore path and keystore password, you may want to further customize the parameters of the TLS protocol, such as the minimum TLS protocol version, or the TLS algorithms, etc.
The ssl Jetty module allows you to configure a secure network connector — i.e. a connector configured with the TLS protocol, the keystore and the TLS parameters; if other modules require encryption, they declare a dependency on the ssl module.
It is the job of other Jetty modules to configure the wrapped protocol.
For example, it is the https module that configures the wrapped protocol to be HTTP/1.1.
Similarly, it is the http2 module that configures the wrapped protocol to be HTTP/2.
Recall from the section about modules, that only modules that are explicitly enabled get their module configuration file (*.ini) saved in $JETTY_BASE/start.d/, and you want $JETTY_BASE/start.d/ssl.ini to be present so that you can configure the connector properties, the keystore properties and the TLS properties.
Jetty Modules
TODO
Module bytebufferpool
The bytebufferpool module allows you to configure the server-wide ByteBuffer pool.
The module file is $JETTY_HOME/modules/bytebufferpool.mod:
# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html [description] Configures the ByteBufferPool used by ServerConnectors. [depends] logging [xml] etc/jetty-bytebufferpool.xml [ini-template] ### Server ByteBufferPool Configuration ## Minimum capacity to pool ByteBuffers #jetty.byteBufferPool.minCapacity=0 ## Maximum capacity to pool ByteBuffers #jetty.byteBufferPool.maxCapacity=65536 ## Capacity factor #jetty.byteBufferPool.factor=1024 ## Maximum queue length for each bucket (-1 for unbounded) #jetty.byteBufferPool.maxQueueLength=-1 ## Maximum heap memory retainable by the pool (-1 for unlimited) #jetty.byteBufferPool.maxHeapMemory=-1 ## Maximum direct memory retainable by the pool (-1 for unlimited) #jetty.byteBufferPool.maxDirectMemory=-1
Among the configurable properties, the most relevant are:
TODO
Module deploy
The deploy module provides the deployment feature through a DeploymentManager component that watches a directory for changes (see how to deploy web applications for more information).
Files or directories added in this monitored directory cause the DeploymentManager to deploy them as web applications; updating files already existing in this monitored directory cause the DeploymentManager to re-deploy the correspondent web application; removing files in this monitored directory cause the DeploymentManager to undeploy the correspondent web application (see also here for more information).
The module file is $JETTY_HOME/modules/deploy.mod:
[description]
Enables web application deployment from the $JETTY_BASE/webapps/ directory.
[depend]
webapp
[lib]
lib/jetty-deploy-${jetty.version}.jar
[files]
webapps/
[xml]
etc/jetty-deploy.xml
[ini-template]
# Monitored directory name (relative to $jetty.base)
# jetty.deploy.monitoredDir=webapps
# - OR -
# Monitored directory path (fully qualified)
# jetty.deploy.monitoredPath=/var/www/webapps
# Defaults Descriptor for all deployed webapps
# jetty.deploy.defaultsDescriptorPath=${jetty.base}/etc/webdefault.xml
# Monitored directory scan period (seconds)
# jetty.deploy.scanInterval=1
# Whether to extract *.war files
# jetty.deploy.extractWars=true
Among the configurable properties, the most relevant are:
-
jetty.deploy.monitoredDir, to change the name of the monitored directory. -
jetty.deploy.scanInterval, to change the scan period, that is how frequently theDeploymentManagerwakes up to scan the monitored directory for changes. Settingjetty.deploy.scanInterval=0disabled hot deployment so that only static deployment will be possible (see also here for more information).
Module http
The http module provides support for the clear-text HTTP/1.1 protocol and depends on the server module.
The module file is $JETTY_HOME/modules/http.mod:
# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html [description] Enables an HTTP connector on the server. By default HTTP/1 is support, but HTTP2C can be added to the connector by enabling the http2c module. [tags] connector http [depend] server [xml] etc/jetty-http.xml [ini-template] ### HTTP Connector Configuration ## Connector host/address to bind to # jetty.http.host=0.0.0.0 ## Connector port to listen on # jetty.http.port=8080 ## Connector idle timeout in milliseconds # jetty.http.idleTimeout=30000 ## Number of acceptors (-1 picks default based on number of cores) # jetty.http.acceptors=-1 ## Number of selectors (-1 picks default based on number of cores) # jetty.http.selectors=-1 ## ServerSocketChannel backlog (0 picks platform default) # jetty.http.acceptQueueSize=0 ## Thread priority delta to give to acceptor threads # jetty.http.acceptorPriorityDelta=0 ## The requested maximum length of the queue of incoming connections. # jetty.http.acceptQueueSize=0 ## Enable/disable the SO_REUSEADDR socket option. # jetty.http.reuseAddress=true ## Enable/disable TCP_NODELAY on accepted sockets. # jetty.http.acceptedTcpNoDelay=true ## The SO_RCVBUF option to set on accepted sockets. A value of -1 indicates that it is left to its default value. # jetty.http.acceptedReceiveBufferSize=-1 ## The SO_SNDBUF option to set on accepted sockets. A value of -1 indicates that it is left to its default value. # jetty.http.acceptedSendBufferSize=-1 ## Connect Timeout in milliseconds # jetty.http.connectTimeout=15000
Among the configurable properties, the most relevant are:
-
jetty.http.port, default8080, is the network port that Jetty listens to for clear-text HTTP/1.1 connections. -
jetty.http.idleTimeout, default30seconds, is the amount of time a connection can be idle (i.e. no bytes received and no bytes sent) until the server decides to close it to save resources. -
jetty.http.acceptors, default -1 (i.e. an accept heuristic decides the value based on the number of cores), is the number of threads that compete to accept connections. -
jetty.http.selectors, default -1 (i.e. a select heuristic decides the value based on the number of cores), is the number of NIO selectors (with an associated thread) that manage connections.
Configuration of Acceptors
Accepting connections is a blocking operation, so a thread is blocked in the accept() call until a connection is accepted, and other threads are blocked on the lock acquired just before the accept() call.
When the accepting thread accepts a connection, it performs a little processing of the just accepted connection, before forwarding it to other components.
During this little processing other connections may be established; if there is only one accepting thread, the newly established connections are waiting for the accepting thread to finish the processing of the previously accepted connection and call again accept().
Servers that manage a very high number of connections that may (naturally) come and go, or that handle inefficient protocols that open and close connections very frequently (such as HTTP/1.0) may benefit of an increased number of acceptor threads.
Configuration of Selectors
Performing a NIO select() call is a blocking operation, where the selecting thread is blocked in the select() call until at least one connection is ready to be processed for an I/O operation.
There are 4 I/O operations: ready to be accepted, ready to be connected, ready to be read and ready to be written.
A single NIO selector can manage thousands of connections, with the assumption that not many of them will be ready at the same time.
For a single NIO selector, the ratio between the average number of selected connections over the total number of connections for every select() call depends heavily on the protocol but also on the application.
Multiplexed protocols such as HTTP/2 tend to be busier than duplex protocols such as HTTP/1.1, leading to a higher ratio.
REST applications that exchange many little JSON messages tend to be busier than file server applications, leading to a higher ratio.
The higher the ratio, the higher the number of selectors you want to have, compatibly with the number of cores — there is no point in having 64 selector threads on a single core hardware.
Module server
The server module provides generic server support, and configures generic HTTP properties that apply to all HTTP protocols, the scheduler properties and the server specific properties.
The server module depends on the threadpool module, the bytebufferpool module and the logging module.
The module file is $JETTY_HOME/modules/server.mod:
# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
[description]
Enables the core Jetty server on the classpath.
[optional]
jvm
ext
resources
[depend]
threadpool
bytebufferpool
logging
[lib]
lib/jetty-servlet-api-4.0.*.jar
lib/jetty-http-${jetty.version}.jar
lib/jetty-server-${jetty.version}.jar
lib/jetty-xml-${jetty.version}.jar
lib/jetty-util-${jetty.version}.jar
lib/jetty-io-${jetty.version}.jar
[xml]
etc/jetty.xml
[ini-template]
### Common HTTP configuration
## Scheme to use to build URIs for secure redirects
# jetty.httpConfig.secureScheme=https
## Port to use to build URIs for secure redirects
# jetty.httpConfig.securePort=8443
## Response content buffer size (in bytes)
# jetty.httpConfig.outputBufferSize=32768
## Max response content write length that is buffered (in bytes)
# jetty.httpConfig.outputAggregationSize=8192
## Max request headers size (in bytes)
# jetty.httpConfig.requestHeaderSize=8192
## Max response headers size (in bytes)
# jetty.httpConfig.responseHeaderSize=8192
## Whether to send the Server: header
# jetty.httpConfig.sendServerVersion=true
## Whether to send the Date: header
# jetty.httpConfig.sendDateHeader=false
## Max per-connection header cache size (in nodes)
# jetty.httpConfig.headerCacheSize=1024
## Whether, for requests with content, delay dispatch until some content has arrived
# jetty.httpConfig.delayDispatchUntilContent=true
## Maximum number of error dispatches to prevent looping
# jetty.httpConfig.maxErrorDispatches=10
## HTTP Compliance: RFC7230, RFC7230_LEGACY, RFC2616, RFC2616_LEGACY, LEGACY
# jetty.httpConfig.compliance=RFC7230
## Cookie compliance mode for parsing request Cookie headers: RFC2965, RFC6265
# jetty.httpConfig.requestCookieCompliance=RFC6265
## Cookie compliance mode for generating response Set-Cookie: RFC2965, RFC6265
# jetty.httpConfig.responseCookieCompliance=RFC6265
## Relative Redirect Locations allowed
# jetty.httpConfig.relativeRedirectAllowed=false
### Server configuration
## Whether ctrl+c on the console gracefully stops the Jetty server
# jetty.server.stopAtShutdown=true
## Timeout in ms to apply when stopping the server gracefully
# jetty.server.stopTimeout=5000
## Dump the state of the Jetty server, components, and webapps after startup
# jetty.server.dumpAfterStart=false
## Dump the state of the Jetty server, components, and webapps before shutdown
# jetty.server.dumpBeforeStop=false
## Scheduler Configuration
# jetty.scheduler.name=
# jetty.scheduler.deamon=false
# jetty.scheduler.threads=-1
Among the configurable properties, the most relevant are:
TODO
Module threadpool
The threadpool module allows you to configure the server-wide thread pool.
The module file is $JETTY_HOME/modules/threadpool.mod:
# DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html [description] Enables and configures the Server thread pool. [depends] logging [xml] etc/jetty-threadpool.xml [ini-template] ### Server Thread Pool Configuration ## Minimum Number of Threads #jetty.threadPool.minThreads=10 ## Maximum Number of Threads #jetty.threadPool.maxThreads=200 ## Number of reserved threads (-1 for heuristic) #jetty.threadPool.reservedThreads=-1 ## Thread Idle Timeout (in milliseconds) #jetty.threadPool.idleTimeout=60000 ## Whether to Output a Detailed Dump #jetty.threadPool.detailedDump=false
Among the configurable properties, the most relevant are:
TODO
HTTP Session Management
HTTP sessions are a concept within the Servlet API which allow requests to store and retrieve information across the time a user spends in an application. Jetty offers a number of pluggable alternatives for managing and distributing/persisting sessions. Choosing the best alternative is an important consideration for every application as is the correct configuration to achieve optimum performance.
HTTP Session Overview
Terminology
Before diving into the specifics of how to plug-in and configure various alternative HTTP session management modules, let’s review some useful terminology:
- Session
-
is a means of retaining information across requests for a particular user. The Servlet Specification defines the semantics of sessions. Some of the most important characteristics of sessions is that they have a unique id and that their contents cannot be shared between different contexts (although the id can be): if a session is invalidated in one context, then all other sessions that share the same id in other contexts will also be invalidated. Sessions can expire or they can be explicitly invalidated.
- SessionIdManager
-
is responsible for allocating session ids. A Jetty server can have at most 1 SessionIdManager.
- HouseKeeper
-
is responsible for periodically orchestrating the removal of expired sessions. This process is referred to as "scavenging".
- SessionHandler
-
is responsible for managing the lifecycle of sessions. A context can have at most 1
SessionHandler. - SessionCache
-
is a L1 cache of in-use session objects. The
SessionCacheis used by theSessionHandler. - SessionDataStore
-
is responsible for all clustering/persistence operations on sessions. A
SessionCacheuses aSessionDataStoreas a backing store. - CachingSessionDataStore
-
is an L2 cache of session data. A
SessionCachecan use aCachingSessionDataStoreas its backing store.
More details on these concepts can be found in the Programming Guide.
|
|
Session Modules
There are a number of modules that offer pluggable alternatives for http session management. You can design how you want to cache and store http sessions by selecting alternative combinations of session modules.
For example, Jetty ships with two alternative implementations of the SessionCache:
-
one that caches sessions in memory:
session-cache-hash -
one that does not actually cache:
session-cache-null
There are at least 6 alternative implementations of the SessionDataStore that you can use to persist/distribute your http sessions:
-
file system storage:
session-store-file -
relational database storage:
session-store-jdbc -
NoSQL database storage:
session-store-mongo -
Google Cloud datastore storage:
session-store-gcloud -
Hazelcast:
session-store-hazelcast-remoteorsession-store-hazelcast-embedded -
Infinispan:
session-store-infinispan-remoteorsession-store-infinispan-embedded
| It is worth noting that if you do not configure any session modules, Jetty will still provide HTTP sessions that are cached in memory but are never persisted. |
The Base Session Module
The sessions module is the base module that all other session modules depend upon.
As such it will be transitively enabled if you enable any of the other session modules: you need to explicitly enable it if you wish to change any settings from their defaults.
Enabling the sessions module puts the $JETTY_HOME/etc/sessions/id-manager.xml file onto the execution path and generates a $JETTY_BASE/start.d/sessions.ini file.
The id-manager.xml file instantiates a DefaultSessionIdManager and HouseKeeper.
The former is used to generate and manage session ids whilst the latter is responsible for periodic scavenging of expired sessions.
Configuration
The $JETTY_BASE/start.d/sessions.ini file contains these configuration properties:
- jetty.sessionIdManager.workerName
-
This uniquely identifies the jetty server instance and is applied to the
SessionIdManager. You can either provide a value for this property, or you can allow Jetty to try and synthesize aworkerName- the latter option is only advisable in the case of a single, non-clustered deployment. There are two ways a defaultworkerNamecan be synthesized:-
if running on Google AppEngine, the
workerNamewill be formed by concatenating the values of the environment variablesJETTY_WORKER_INSTANCEandGAE_MODULE_INSTANCE -
otherwise, the
workerNamewill be formed by concatenating the environment variableJETTY_WORKER_INSTANCEand the literal0.
-
So, if you’re not running on Google AppEngine, and you haven’t configured one, the workerName will always be: node0.
If you have more than one Jetty instance, it is crucial that you configure the workerName differently for each instance.
|
- jetty.sessionScavengeInterval.seconds
-
This is the period in seconds between runs of the
HouseKeeper, responsible for orchestrating the removal of expired sessions. By default it will run approximately every 600 secs (ie 10 mins). As a rule of thumb, you should ensure that the scavenge interval is shorter than the<session-timeout>of your sessions to ensure that they are promptly scavenged. On the other hand, if you have a backend store configured for your sessions, scavenging too frequently can increase the load on it.
Don’t forget that the <session-timeout> is specified in web.xml in minutes and the value of the jetty.sessionScavengeInterval.seconds is in seconds.
|
Session Scavenging
The HouseKeeper is responsible for the periodic initiation of session scavenge cycles.
The jetty.sessionScavengeInterval.seconds property in $JETTY_BASE/start.d/sessions.ini controls the periodicity of the cycle.
|
The HouseKeeper semi-randomly adds an additional 10% to the configured |
A session whose expiry time has been exceeded is considered eligible for scavenging.
The session might be present in a SessionCache and/or present in the session persistence/clustering mechanism.
Scavenging occurs for all contexts on a server at every cycle.
The HouseKeeper sequentially asks the SessionHandler in each context to find and remove expired sessions.
The SessionHandler works with the SessionDataStore to evaluate candidates for expiry held in the SessionCache, and also to sweep the persistence mechanism to find expired sessions.
The sweep takes two forms: once per cycle the SessionDataStore searches for sessions for its own context that have expired; infrequently, the SessionDataStore will widen the search to expired sessions in all contexts.
The former finds sessions that are no longer in this context’s SessionCache, and using some heuristics, are unlikely to be in the SessionCache of the same context on another node either.
These sessions will be loaded and fully expired, meaning that HttpSessionListener.destroy() will be called for them.
The latter finds sessions that have not been disposed of by scavenge cycles on any other context/node.
As these will be sessions that expired a long time ago, and may not be appropriate to load by the context doing the scavenging, these are summarily deleted without HttpSessionListener.destroy() being called.
A combination of these sweeps should ensure that the persistence mechanism does not fill over time with expired sessions.
As aforementioned, the sweep period needs to be short enough to find expired sessions in a timely fashion, but not so often that it overloads the persistence mechanism.
Modules for HTTP Session Caching
In this section we will look at the alternatives for the SessionCache, i.e. the L1 cache of in-use session objects.
Jetty ships with 2 alternatives: an in-memory cache, and a null cache.
The latter does not actually do any caching of sessions, and can be useful if you either want to minimize your support for sessions, or you are in a clustered deployment without a sticky loadbalancer.
The scenarios go into more detail on this.
Caching in Memory
If you wish to change any of the default configuration values you should enable the session-cache-hash module.
The name "hash" harks back to historical Jetty session implementations, whereby sessions were kept in memory using a HashMap.
Configuration
The $JETTY_BASE/start.d/session-cache-hash.ini contains the following configurable properties:
- jetty.session.evictionPolicy
-
Integer, default -1. This controls whether session objects that are held in memory are subject to eviction from the cache. Eviction means that the session is removed from the cache. This can reduce the memory footprint of the cache and can be useful if you have a lot of sessions. Eviction is usually used in conjunction with a
SessionDataStorethat persists sessions. The eviction strategies and their corresponding values are:- -1 (NO EVICTION)
-
sessions are never evicted from the cache. The only way they leave are via expiration or invalidation.
- 0 (EVICT AFTER USE)
-
sessions are evicted from the cache as soon as the last active request for it finishes. The session will be passed to the
SessionDataStoreto be written out before eviction. - >= 1 (EVICT ON INACTIVITY)
-
any positive number is the time in seconds after which a session that is in the cache but has not experienced any activity will be evicted. Use the
jetty.session.saveOnInactiveEvictproperty to force a session write before eviction.
If you are not using one of the session store modules, ie one of the session-store-xxxxs, then sessions will be lost when the context is stopped, or the session is evicted.
|
- jetty.session.saveOnInactiveEvict
-
Boolean, default
false. This controls whether a session will be persisted to theSessionDataStoreif it is being evicted due to the EVICT ON INACTIVITY policy. Usually sessions will be written to theSessionDataStorewhenever the last simultaneous request exits the session. However, asSessionDataStorescan be configured to skip some writes (see the documentation for thesession-store-xxxmodule that you are using), this option is provided to ensure that the session will be written out.
| Be careful with this option, as in clustered scenarios it would be possible to "re-animate" a session that has actually been deleted by another node. |
- jetty.session.saveOnCreate
-
Boolean, default
false. Controls whether a session that is newly created will be immediately saved to theSessionDataStoreor lazily saved as the last request for the session exits. This can be useful if the request dispatches to another context and needs to re-use the same session id. - jetty.session.removeUnloadableSessions
-
Boolean, default
false. Controls whether the session cache should ask aSessionDataStoreto delete a session that cannot be restored - for example because it is corrupted. - jetty.session.flushOnResponseCommit
-
Boolean, default
false. If true, if a session is "dirty" - ie its attributes have changed - it will be written to theSessionDataStoreas the response is about to commit. This ensures that all subsequent requests whether to the same or different node will see the updated session data. If false, a dirty session will only be written to the backing store when the last simultaneous request for it leaves the session. - jetty.session.invalidateOnShutdown
-
Boolean, default
false. If true, when a context is shutdown, all sessions in the cache are invalidated and deleted both from the cache and from theSessionDataStore.
No Caching
You may need to use the session-cache-null module if your clustering setup does not have a sticky load balancer, or if you want absolutely minimal support for sessions.
If you enable this module, but you don’t enable a module that provides session persistence (ie one of the session-store-xxx modules), then sessions will neither be retained in memory nor persisted.
Configuration
The $JETTY_BASE/start.d/session-cache-null.ini contains the following configurable properties:
- jetty.session.saveOnCreate
-
Boolean, default
false. Controls whether a session that is newly created will be immediately saved to theSessionDataStoreor lazily saved as the last request for the session exits. This can be useful if the request dispatches to another context and needs to re-use the same session id. - jetty.session.removeUnloadableSessions
-
Boolean, default
false. Controls whether the session cache should ask aSessionDataStoreto delete a session that cannot be restored - for example because it is corrupted. - jetty.session.flushOnResponseCommit
-
Boolean, default
false. If true, if a session is "dirty" - ie its attributes have changed - it will be written to the backing store as the response is about to commit. This ensures that all subsequent requests whether to the same or different node will see the updated session data. If false, a dirty session will only be written to the backing store when the last simultaneous request for it leaves the session.
Modules for Persistent HTTP Sessions: File System
The session-store-file Jetty module supports persistent storage of session data in a filesystem.
| Persisting sessions to the local file system should never be used in a clustered environment. |
Enabling this module creates the $JETTY_BASE/sessions directory.
By default session data will be saved to this directory, one file representing each session.
File names follow this pattern:
[expiry]_[contextpath]_[virtualhost]_[id]
- expiry
-
This is the expiry time in milliseconds since the epoch.
- contextpath
-
This is the context path with any special characters, including
/, replaced by theunderscore character. For example, a context path of/catalogwould become_catalog. A context path of simply/becomes just_. - virtualhost
-
This is the first virtual host associated with the context and has the form of 4 digits separated by
.characters:[digit].[digit].[digit].[digit]. If there are no virtual hosts associated with a context, then0.0.0.0is used. - id
-
This is the unique id of the session.
Putting all of the above together as an example, a session with an id of node0ek3vx7x2y1e7pmi3z00uqj1k0 for the context with path /test with no virtual hosts and an expiry of 1599558193150 would have a file name of:
1599558193150__test_0.0.0.0_node0ek3vx7x2y1e7pmi3z00uqj1k0
Configuration
The $JETTY_BASE/start.d/sessions.ini file contains the following properties which may be modified to customise filesystem session storage:
- jetty.session.storeDir
-
The default is
$JETTY_BASE/sessions. This is a path that defines the location for storage of session files. - jetty.session.file.deleteUnrestorableFiles
-
Boolean, default
false. If set totrue, unreadable files will be deleted. This is useful to prevent repeated logging of the same error when the scavenger periodically (re-)attempts to load the corrupted information for a session in order to expire it. - jetty.session.gracePeriod.seconds
-
Integer, default 3600. Used during session scavenging. Multiples of this period are used to define how long ago a stored session must have expired before it should be scavenged.
- jetty.session.savePeriod.seconds
-
Integer, in seconds, default is
0. Whenever a session is accessed by a request, itslastAccessTimeandexpiryare updated. Even if your sessions are read-mostly, thelastAccessTimeandexpirywill always change. For heavily-used, read-mostly sessions you can save some time by skipping some writes for sessions for which only these fields have changed (ie no session attributes changed). The value of this property is used to skip writes for these kinds of sessions: the session will only be written out if the time since the last write exceeds the value of this property.
|
You should be careful in the use of this property in clustered environments: if you set too large a value for this property, the session may not be written out sufficiently often to update its |
Modules for Persistent HTTP Sessions: JDBC
Enabling the session-store-jdbc module configures Jetty to persist session data in a relational database.
Configuration
After enabling the module, the $JETTY_BASE/start.d/session-store-jdbc.ini file contains the following customizable properties:
- jetty.session.gracePeriod.seconds
-
Integer, default 3600. Used during session scavenging. Multiples of this period are used to define how long ago a stored session must have expired before it should be scavenged.
- jetty.session.savePeriod.seconds
-
Integer, in seconds, default is
0. Whenever a session is accessed by a request, itslastAccessTimeandexpiryare updated. Even if your sessions are read-mostly, thelastAccessTimeandexpirywill always change. For heavily-used, read-mostly sessions you can save some time by skipping some writes for sessions for which only these fields have changed (ie no session attributes changed). The value of this property is used to skip writes for these kinds of sessions: the session will only be written out if the time since the last write exceeds the value of this property.
|
You should be careful in the use of this property in clustered environments: if you set too large a value for this property, the session may not be written out sufficiently often to update its |
- db-connection-type
-
Default
datasource. Set to eitherdatasourceordriverdepending on the type of connection being used. Depending which you select, there are additional properties available:datasource-
- jetty.session.jdbc.datasourceName
-
Name of the remote datasource.
driver-
- jetty.session.jdbc.driverClass
-
Name of the JDBC driver that controls access to the remote database, such as
com.mysql.jdbc.Driver - jetty.session.jdbc.driverUrl
-
URL of the database which includes the driver type, host name and port, service name and any specific attributes unique to the database, such as a username. As an example, here is a mysql connection with the username appended:
jdbc:mysql://127.0.0.1:3306/sessions?user=sessionsadmin.
- jetty.session.jdbc.blobType
-
Optional. Default
bloborbyteafor Postgres. This is the keyword used by the particular database to identify the blob data type. If netiher default is suitable you can set this value explicitly. - jetty.session.jdbc.longType
-
Optional. Default
bigintornumber(20)for Oracle. This is the keyword used by the particular database to identify the long integer data type. Set this explicitly if neither of the default values is appropriate. - jetty.session.jdbc.stringType
-
Optional. Default
varchar. This is the keyword used by the particular database to identify character type. If the default is not suitable, you can set this value explicitly. - jetty.session.jdbc.schema.schemaName
- jetty.session.jdbc.schema.catalogName
-
Optional. The exact meaning of these two properties is dependent on your database vendor, but can broadly be described as further scoping for the session table name. See https://en.wikipedia.org/wiki/Database_schema and https://en.wikipedia.org/wiki/Database_catalog. These extra scoping names can come into play at startup time when Jetty determines if the session table already exists, or otherwise creates it on-the-fly. If you have employed either of these concepts when you pre-created the session table, or you want to ensure that Jetty uses them when it auto-creates the session table, then you have two options: either set them explicitly, or let Jetty infer them from a database connection (obtained using either a Datasource or Driver according to the
db-connection-typeyou have configured). To set them explicitly, uncomment and supply appropriate values for thejetty.session.jdbc.schema.schemaNameand/orjetty.session.jdbc.schema.catalogNameproperties. Alternatively, to allow Jetty to infer them from a database connection, use the special stringINFERREDinstead. If you leave them blank or commented out, then the sessions table will not be scoped by schema or catalog name. - jetty.session.jdbc.schema.table
-
Default
JettySessions. This is the name of the table in which session data is stored. - jetty.session.jdbc.schema.accessTimeColumn
-
Default
accessTime. This is the name of the column that stores the time - in ms since the epoch - at which a session was last accessed - jetty.session.jdbc.schema.contextPathColumn
-
Default
contextPath. This is the name of the column that stores thecontextPathof a session. - jetty.session.jdbc.schema.cookieTimeColumn
-
Default
cookieTime. This is the name of the column that stores the time - in ms since the epoch - that the cookie was last set for a session. - jetty.session.jdbc.schema.createTimeColumn
-
Default
createTime. This is the name of the column that stores the time - in ms since the epoch - at which a session was created. - jetty.session.jdbc.schema.expiryTimeColumn
-
Default
expiryTime. This is name of the column that stores - in ms since the epoch - the time at which a session will expire. - jetty.session.jdbc.schema.lastAccessTimeColumn
-
Default
lastAccessTime. This is the name of the column that stores the time - in ms since the epoch - that a session was previously accessed. - jetty.session.jdbc.schema.lastSavedTimeColumn
-
Default
lastSavedTime. This is the name of the column that stores the time - in ms since the epoch - at which a session was last written. - jetty.session.jdbc.schema.idColumn
-
Default
sessionId. This is the name of the column that stores the id of a session. - jetty.session.jdbc.schema.lastNodeColumn
-
Default
lastNode. This is the name of the column that stores theworkerNameof the last node to write a session. - jetty.session.jdbc.schema.virtualHostColumn
-
Default
virtualHost. This is the name of the column that stores the first virtual host of the context of a session. - jetty.session.jdbc.schema.maxIntervalColumn
-
Default
maxInterval. This is the name of the column that stores the interval - in ms - during which a session can be idle before being considered expired. - jetty.session.jdbc.schema.mapColumn
-
Default
map. This is the name of the column that stores the serialized attributes of a session.
Modules for Persistent HTTP Sessions: MongoDB
Enabling the session-store-mongo module configures Jetty to store session data in MongoDB.
Because MongoDB is not a technology provided by the Eclipse Foundation, you will be prompted to assent to the licenses of the external vendor (Apache in this case) during the install.
Jars needed by MongoDB are downloaded and stored into a directory named $JETTY_BASE/lib/nosql/.
If you want to use updated versions of the jar files automatically downloaded by Jetty, you can place them in the associated $JETTY_BASE/lib/ directory and use the --skip-file-validation=<module name> command line option to prevent errors when starting your server.
|
Configuration
The $JETTY_BASE/start.d/session-store-mongo.ini file contains these configurable properties:
- jetty.session.mongo.dbName
-
Default is "HttpSessions". This is the name of the database in MongoDB used to store the session collection.
- jetty.session.mongo.collectionName
-
Default is "jettySessions". This is the name of the collection in MongoDB used to store all of the sessions.
- The connection type-
-
You can connect to MongoDB either using a host/port combination, or a URI. By default, the host/port method is selected, but you can change this by commenting out the unwanted method, and uncommenting the other one.
- connection-type=address
-
Used when utilizing a direct connection to the MongoDB server.
- jetty.session.mongo.host
-
Host name or address for the remote MongoDB instance.
- jetty.session.mongo.port
-
Port number for the remote MongoDB instance.
- connection-type=uri
-
Used when utilizing MongoURI for secured connections.
- jetty.session.mongo.connectionString
-
The string defining the MongoURI value, such as
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]. More information on how to format the MongoURI string can be found in the official documentation for mongo.
|
You will only use one |
- jetty.session.gracePeriod.seconds
-
Integer, in seconds. Default 3600. Used during session scavenging. Multiples of this period are used to define how long ago a stored session must have expired before it should be scavenged.
- jetty.session.savePeriod.seconds
-
Integer, in seconds, default is
0. Whenever a session is accessed by a request, itslastAccessTimeandexpiryare updated. Even if your sessions are read-mostly, thelastAccessTimeandexpirywill always change. For heavily-used, read-mostly sessions you can save some time by skipping some writes for sessions for which only these fields have changed (ie no session attributes changed). The value of this property is used to skip writes for these kinds of sessions: the session will only be written out if the time since the last write exceeds the value of this property.
|
You should be careful in the use of this property in clustered environments: if you set too large a value for this property, the session may not be written out sufficiently often to update its |
Modules for Persistent HTTP Sessions: Infinispan
In order to persist/cluster sessions using Infinispan, Jetty needs to know how to contact Infinispan.
There are two options: a remote Infinispan instance, or an in-process Infinispan instance.
The former is referred to as "remote" Infinispan and the latter as "embedded" Infinispan.
If you wish Jetty to be able to scavenge expired sessions, you will also need to enable the appropriate infinispan-[remote|embedded]-query module.
Remote Infinispan Session Module
The session-store-infinispan-remote module configures Jetty to talk to an external Infinispan instance to store session data.
Because Infinispan is not a technology provided by the Eclipse Foundation, you will be prompted to assent to the licenses of the external vendor (Apache in this case).
Infinispan-specific jar files are download to the directory named $JETTY_BASE/lib/infinispan/.
In addition to adding these modules to the classpath of the server it also added several ini configuration files to the $JETTY_BASE/start.d directory.
If you have updated versions of the jar files automatically downloaded by Jetty, you can place them in the associated $JETTY_BASE/lib/ directory and use the --skip-file-validation=<module name> command line option to prevent errors when starting your server.
|
Configuration
The $JETTY_BASE/start.d/session-store-infinispan-remote.ini contains the following configurable properties:
- jetty.session.infinispan.remoteCacheName
-
Default
"sessions". This is the name of the cache in Infinispan where sessions will be stored. - jetty.session.infinispan.idleTimeout.seconds
-
Integer, in seconds, default
0. This is the amount of time, in seconds, that a session entry in Infinispan can be idle (ie neither read nor written) before Infinispan will delete its entry. Usually, you do not want to set a value for this, as you want Jetty to manage all session expiration (and call any HttpSessionListeners). You should enable the infinispan-remote-query to allow jetty to scavenge for expired sessions. If you do not, then there is the possibility that sessions can be left in Infinispan but no longer referenced by any Jetty node (so called "zombie" or "orphan" sessions), in which case you can use this feature to ensure their removal.
You should make sure that the number of seconds you specify is larger than the configured maxIdleTime for sessions.
|
- jetty.session.gracePeriod.seconds
-
Integer, default 3600. Used during session scavenging. Multiples of this period are used to define how long ago a stored session must have expired before it should be scavenged.
- jetty.session.savePeriod.seconds
-
Integer, in seconds, default is
0. Whenever a session is accessed by a request, itslastAccessTimeandexpiryare updated. Even if your sessions are read-mostly, thelastAccessTimeandexpirywill always change. For heavily-used, read-mostly sessions you can save some time by skipping some writes for sessions for which only these fields have changed (ie no session attributes changed). The value of this property is used to skip writes for these kinds of sessions: the session will only be written out if the time since the last write exceeds the value of this property.
|
You should be careful in the use of this property in clustered environments: if you set too large a value for this property, the session may not be written out sufficiently often to update its |
Remote Infinispan Query Module
The infinispan-remote-query module allows Jetty to scavenge expired sessions.
Note that this is an additional module, to be used in conjunction with the session-store-infinispan-remote module.
There are no configuration properties associated with this module.
Embedded Infinispan Session Module
Enabling the session-store-infinispan-embedded module runs an in-process instance of Infinispan.
Because Infinispan is not a technology provided by the Eclipse Foundation, you will be prompted to assent to the licenses of the external vendor (Apache in this case).
Infinispan-specific jar files will be downloaded and saved to a directory named $JETTY_BASE/lib/infinispan/.
If you have updated versions of the jar files automatically downloaded by Jetty, you can place them in the associated $JETTY_BASE/lib/ directory and use the --skip-file-validation=<module name> command line option to prevent errors when starting your server.
|
Configuration
The $JETTY_BASE/start.d/session-store-infinispan-embedded.ini contains the following configurable properties:
- jetty.session.infinispan.idleTimeout.seconds
-
Integer, in seconds, default
0. This is the amount of time, in seconds, that a session entry in Infinispan can be idle (ie neither read nor written) before Infinispan will delete its entry. Usually, you do not want to set a value for this, as you want Jetty to manage all session expiration (and call any HttpSessionListeners). You should enable the infinispan-embedded-query to allow Jetty to scavenge for expired sessions. If you do not, then there is the possibility that expired sessions can be left in Infinispan.
You should make sure that the number of seconds you specify is larger than the configured maxIdleTime for sessions.
|
- jetty.session.gracePeriod.seconds
-
Integer, default 3600. Used during session scavenging. Multiples of this period are used to define how long ago a stored session must have expired before it should be scavenged.
- jetty.session.savePeriod.seconds
-
Integer, in seconds, default is
0. Whenever a session is accessed by a request, itslastAccessTimeandexpiryare updated. Even if your sessions are read-mostly, thelastAccessTimeandexpirywill always change. For heavily-used, read-mostly sessions you can save some time by skipping some writes for sessions for which only these fields have changed (ie no session attributes changed). The value of this property is used to skip writes for these kinds of sessions: the session will only be written out if the time since the last write exceeds the value of this property.
|
Thorough consideration of the |
Embedded Infinispan Query Module
The infinispan-embedded-query module allows Jetty to scavenge expired sessions.
There are no configuration properties associated with this module.
Converting Session Format for Jetty-9.4.13
From Jetty-9.4.13 onwards, we have changed the format of the serialized session when using a remote cache (ie using hotrod). Prior to release 9.4.13 we used the default Infinispan serialization, however this was not able to store sufficient information to allow Jetty to properly deserialize session attributes in all circumstances. See issue https://github.com/eclipse/jetty.project/issues/2919 for more background.
We have provided a conversion program which will convert any sessions stored in Infinispan to the new format.
| We recommend that you backup your stored sessions before running the conversion program. |
How to use the converter:
java -cp jetty-servlet-api-4.0.2.jar:jetty-util-{VERSION}.jar:jetty-server-{VERSION}.jar:infinispan-remote-9.1.0.Final.jar:jetty-infinispan-{VERSION}.jar:[other classpath] org.eclipse.jetty.session.infinispan.InfinispanSessionLegacyConverter
Usage: InfinispanSessionLegacyConverter [-Dhost=127.0.0.1] [-Dverbose=true|false] <cache-name> [check]
- The classpath
-
Must contain the servlet-api, jetty-util, jetty-server, jetty-infinispan and infinispan-remote jars. If your sessions contain attributes that use application classes, you will also need to also put those classes onto the classpath. If your session has been authenticated, you may also need to include the jetty-security and jetty-http jars on the classpath.
- Parameters
-
When used with no arguments the usage message is printed. When used with the
cache-nameparameter the conversion is performed. When used with bothcache-nameandcheckparameters, sessions are checked for whether or not they are converted.- -Dhost
-
you can optionally provide a system property with the address of your remote Infinispan server. Defaults to the localhost.
- -Dverbose
-
defaults to false. If true, prints more comprehensive stacktrace information about failures. Useful to diagnose why a session is not converted.
- cache-name
-
the name of the remote cache containing your sessions. This is mandatory.
- check
-
the optional check command will verify sessions have been converted. Use it after doing the conversion.
To perform the conversion, run the InfinispanSessionLegacyConverter with just the cache-name, and optionally the host system property.
The following command will attempt to convert all sessions in the cached named my-remote-cache on the machine myhost, ensuring that application classes in the /my/custom/classes directory are on the classpath:
java -cp jetty-servlet-api-4.0.2.jar:jetty-util-{VERSION}.jar:jetty-server-{VERSION}.jar:infinispan-remote-9.1.0.Final.jar:jetty-infinispan-{VERSION}.jar:/my/custom/classes org.eclipse.jetty.session.infinispan.InfinispanSessionLegacyConverter -Dhost=myhost my-remote-cache
If the converter fails to convert a session, an error message and stacktrace will be printed and the conversion will abort. The failed session should be untouched, however it is prudent to take a backup of your cache before attempting the conversion.
Modules for Persistent HTTP Sessions: Hazelcast
Hazelcast can be used to cluster session information in one of two modes: either remote or embedded. Remote mode means that Hazelcast will create a client to talk to other instances, possibly on other nodes. Embedded mode means that Hazelcast will start a local instance and communicate with that.
Remote Hazelcast Clustering
Enabling the session-store-hazelcast-remote module allows jetty to communicate with a remote Hazelcast instance to cluster session data.
Because Hazelcast is not a technology provided by the Eclipse Foundation, you will be prompted to assent to the licenses of the external vendor (Apache in this case).
Hazelcast-specific jar files will be downloaded and saved to a directory named $JETTY_BASE/lib/hazelcast/.
If you have updated versions of the jar files automatically downloaded by Jetty, you can place them in the associated $JETTY_BASE/lib/ directory and use the --skip-file-validation=<module name> command line option to prevent errors when starting your server.
|
Configuration
The start.d/session-store-hazelcast-remote.ini contains a list of all the configurable options for the Hazelcast module:
- jetty.session.hazelcast.mapName
-
The default is "jetty-distributed-session-map". This is the name of the Map in Hazelcast where sessions will be stored.
- jetty.session.hazelcast.onlyClient
-
Boolean, default
true. The Hazelcast instance will be configured in client mode. - jetty.session.hazelcast.configurationLocation
-
Optional. This is the path to an external Hazelcast xml configuration file.
- jetty.session.hazelcast.useQueries
-
Boolean, default
false. Iftrue, Jetty will use Hazelcast queries to find sessions to scavenge. Iffalsesessions that are not currently in a session cache cannot be scavenged, and will need to be removed by some external process. - jetty.session.hazelcast.addresses
-
Optional. These are the addresses of remote Hazelcast instances with which to communicate.
- jetty.session.gracePeriod.seconds
-
Integer, in seconds. Default 3600. Used during session scavenging. Multiples of this period are used to define how long ago a stored session must have expired before it should be scavenged.
- jetty.session.savePeriod.seconds
-
Integer, in seconds, default is
0. Whenever a session is accessed by a request, itslastAccessTimeandexpiryare updated. Even if your sessions are read-mostly, thelastAccessTimeandexpirywill always change. For heavily-used, read-mostly sessions you can save some time by skipping some writes for sessions for which only these fields have changed (ie no session attributes changed). The value of this property is used to skip writes for these kinds of sessions: the session will only be written out if the time since the last write exceeds the value of this property.
|
You should be careful in the use of this property in clustered environments: if you set too large a value for this property, the session may not be written out sufficiently often to update its |
| Be aware that if your session attributes contain classes from inside your webapp (or Jetty classes) then you will need to put these classes onto the classpath of all of your Hazelcast instances. |
Embedded Hazelcast Clustering
This will run an in-process instance of Hazelcast.
This can be useful for example during testing.
To enable this you enable the session-store-hazelcast-embedded module.
Because Hazelcast is not a technology provided by the Eclipse Foundation, you will be prompted to assent to the licenses of the external vendor (Apache in this case).
Hazelcast-specific jar files will be downloaded to a directory named $JETTY_BASE/lib/hazelcast/.
Configuration
The $JETTY_BASE/start.d/start.d/session-store-hazelcast-embedded.ini contains a list of all the configurable options for the Hazelcast module:
- jetty.session.hazelcast.mapName
-
The default is "jetty-distributed-session-map". This is the name of the Map in Hazelcast where sessions will be stored. jetty.session.hazelcast.hazelcastInstanceName Default is "JETTY_DISTRIBUTED_SESSION_INSTANCE". This is the unique name of the Hazelcast instance that will be created.
- jetty.session.hazelcast.configurationLocation
-
Optional. This is the path to an external Hazelcast xml configuration file.
- jetty.session.hazelcast.useQueries
-
Boolean, default
false'. If `true, Jetty will use Hazelcast queries to find expired sessions to scavenge. Iffalsesessions that are not currently in a session cache cannot be scavenged, and will need to be removed by some external process. - jetty.session.gracePeriod.seconds
-
Integer, in seconds. Default 3600. Used during session scavenging. Multiples of this period are used to define how long ago a stored session must have expired before it should be scavenged.
- jetty.session.savePeriod.seconds
-
Integer, in seconds, default is
0. Whenever a session is accessed by a request, itslastAccessTimeandexpiryare updated. Even if your sessions are read-mostly, thelastAccessTimeandexpirywill always change. For heavily-used, read-mostly sessions you can save some time by skipping some writes for sessions for which only these fields have changed (ie no session attributes changed). The value of this property is used to skip writes for these kinds of sessions: the session will only be written out if the time since the last write exceeds the value of this property.
|
You should be careful in the use of this property in clustered environments: if you set too large a value for this property, the session may not be written out sufficiently often to update its |
| If your session attributes contain classes from inside your webapp (or jetty classes) then you will need to put these classes onto the classpath of all of your hazelcast instances. In the case of embedded hazelcast, as it is started before your webapp, it will NOT have access to your webapp’s classes - you will need to extract these classes and put them onto the jetty server’s classpath. |
Modules for Persistent HTTP Sessions: Google Cloud DataStore
Jetty can store http session information into GCloud by enabling the session-store-gcloud module.
Preparation
You will first need to create a project and enable the Google Cloud api: https://cloud.google.com/docs/authentication#preparation. Take note of the project id that you create in this step as you need to supply it in later steps.
Communicating with GCloudDataStore
When Running Jetty Outside of Google Infrastructure
Before running Jetty, you will need to choose one of the following methods to set up the local environment to enable remote GCloud DataStore communications.
-
Using the GCloud SDK:
-
Ensure you have the GCloud SDK installed: https://cloud.google.com/sdk/?hl=en
-
Use the GCloud tool to set up the project you created in the preparation step:
gcloud config set project PROJECT_ID -
Use the GCloud tool to authenticate a google account associated with the project created in the preparation step:
gcloud auth login ACCOUNT
-
-
Using environment variables
-
Define the environment variable
GCLOUD_PROJECTwith the project id you created in the preparation step. -
Generate a JSON service account key and then define the environment variable
GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/key.json
-
When Running Jetty Inside of Google Infrastructure
The Google deployment tools will automatically configure the project and authentication information for you.
Configuring Indexes for Session Data
Using some special, composite indexes can speed up session search operations, although it may make write operations slower.
By default, indexes will not be used.
In order to use them, you will need to manually upload a file that defines the indexes.
This file is named index.yaml and you can find it in your distribution in $JETTY_BASE/etc/sessions/gcloud/index.yaml.
Follow the instructions here to upload the pre-generated index.yaml file.
Communicating with the GCloudDataStore Emulator
To enable communication using the GCloud Emulator:
-
Ensure you have the GCloud SDK installed: https://cloud.google.com/sdk/?hl=en
-
Follow the instructions here on how to start the GCloud datastore emulator, and how to propagate the environment variables that it creates to the terminal in which you run Jetty.
Enabling the Google Cloud DataStore Module
The session-store-gcloud module provides GCloud support for storing session data.
Because the Google Cloud DataStore is not a technology provided by the Eclipse Foundation, when enabling the module you will be prompted to assent to the licenses of the external vendor.
As GCloud requires certain Java Commons Logging features to work correctly, Jetty routes these through SLF4J by transitively enabling the jcl-slf4j module during installation.
Therefore, you will also need to enable one of the SLF4J implementation modules.
You can either choose one ahead of time and enable it at the same time as the session-store-gcloud module, or you can just enable session-store-gcloud module and it will print out a list of available SLF4J implementations.
You can then choose one and enable it.
If you want to use updated versions of the jar files automatically downloaded during the module enablement, you can place them in the associated $JETTY_BASE/lib/ directory and use the --skip-file-validation=<module name> command line option to prevent errors when starting your server.
|
Configuration
The $JETTY_BASE/start.d/session-store-gcloud.ini file contains all of the configurable properties for the session-store-gcloud module:
- jetty.session.gcloud.maxRetries
-
Integer. Default 5. Maximum number of retries to connect to GCloud DataStore to write a session.
- jetty.session.gcloud.backoffMs
-
Integer in milliseconds. Default 1000. Number of milliseconds between successive attempts to connect to the GCloud DataStore to write a session.
- jetty.session.gracePeriod.seconds
-
Integer, in seconds. Default 3600. Used during session scavenging. Multiples of this period are used to define how long ago a stored session must have expired before it should be scavenged.
- jetty.session.savePeriod.seconds
-
Integer, in seconds, default is
0. Whenever a session is accessed by a request, itslastAccessTimeandexpiryare updated. Even if your sessions are read-mostly, thelastAccessTimeandexpirywill always change. For heavily-used, read-mostly sessions you can save some time by skipping some writes for sessions for which only these fields have changed (ie no session attributes changed). The value of this property is used to skip writes for these kinds of sessions: the session will only be written out if the time since the last write exceeds the value of this property.
|
You should be careful in the use of this property in clustered environments: if you set too large a value for this property, the session may not be written out sufficiently often to update its |
- jetty.session.gcloud.namespace
-
Optional. Sets the namespace for GCloud Datastore to use. If set, partitions the visibility of session data between webapps, which is helpful for multi-tenant deployments. More information can be found here.
- Configuration of the stored session object and its fields names-
-
You should very rarely, if ever, need to change these defaults.
- jetty.session.gcloud.model.kind
-
The default is "GCloudSession". This is the type of the object that is stored in GCloud.
- jetty.session.gcloud.model.id
-
The default is "id". This is the session id.
- jetty.session.gcloud.model.contextPath
-
The default is "contextPath". This is the canonicalized context path of the context to which the session belongs.
- jetty.session.gcloud.model.vhost
-
The default is "vhost". This is the canonicalized virtual host of the context to which the session belongs.
- jetty.session.gcloud.model.accessed
-
The default is "accessed". This is the current access time of the session.
- jetty.session.gcloud.model.lastAccessed
-
The default is "lastAccessed". This is the last access time of the session.
- jetty.session.gcloud.model.createTime
-
The default is "createTime". This is the time, in ms since the epoch, at which the session was created.
- jetty.session.gcloud.model.cookieSetTime
-
The default is "cookieSetTime". This is the time at which the session cookie was last set.
- jetty.session.gcloud.model.lastNode
-
The default is "lastNode". This is the
workerNameof the last node to manage the session. - jetty.session.gcloud.model.expiry
-
The default is "expiry". This is the time, in ms since the epoch, at which the session will expire.
- jetty.session.gcloud.model.maxInactive
-
The default is "maxInactive". This is the session timeout in ms.
- jetty.session.gcloud.model.attributes
-
The default is "attributes". This is a map of all the session attributes.
Modules for Persistent HTTP Sessions: The L2 Session Data Cache
If your chosen persistence technology is slow, it can be helpful to locally cache the session data.
The CachingSessionDataStore is a special type of SessionDataStore that locally caches session data, which makes reads faster. It writes-through to your chosen type of SessionDataStore when session data changes.
MemcachedSessionDataMap
The MemcachedSessionDataMap uses memcached to perform caching of SessionData.
To enable it with the Jetty distribution, enable the session-store-cache module, along with your chosen session-store-xxxx module.
Configuration
The $JETTY_BASE/start.d/session-store-cache.ini contains the following configurable properties:
- jetty.session.memcached.host
-
Default value is
localhost. This is the host on which the memcached server resides. - jetty.session.memcached.port
-
Default value is
11211. This is the port on which the memcached server is listening. - jetty.session.memcached.expirySec
-
Default value
0. This is the length of time in seconds that an item can remain in the memcached cache, where 0 indicates indefinitely. - jetty.session.memcached.heartbeats
-
Default value
true. Whether the memcached system should generate heartbeats.
Session Scenarios
Minimizing Support for Sessions
The standard support for webapps in Jetty will use sessions cached in memory, but not persisted/clustered, with a scavenge for expired sessions that occurs every 10 minutes. If you wish to pare back support for sessions because you know your app doesn’t use them (or use JSPs that use them), then you can do the following:
-
enable the base sessions module and configure the scavenge interval to 0 to prevent scavenging
-
enable the null session cache module to prevent sessions being cached in memory
If you wish to do any further minimization, you should consult the Programming Guide.
Clustering with a Sticky Load Balancer
Preferably, your cluster will utilize a sticky load balancer.
This will route requests for the same session to the same Jetty instance.
In this case, the DefaultSessionCache can be used to keep in-use session objects in memory.
You can fine-tune the cache by controlling how long session objects remain in memory with the eviction policy settings.
If you have a large number of sessions or very large session objects, then you may want to manage your memory allocation by controlling the amount of time session objects spend in the cache.
The EVICT_ON_SESSION_EXIT eviction policy will remove a session object from the cache as soon as the last simultaneous request referencing it exits.
Alternatively, the EVICT_ON_INACTIVITY policy will remove a session object from the cache after a configurable amount of time has passed without a request referencing it.
If your sessions are very long lived and infrequently referenced, you might use the EVICT_ON_INACTIVITY_POLICY to control the size of the cache.
If your sessions are small, or relatively few or stable in number or they are read-mostly, then you might select the NEVER_EVICT policy.
With this policy, session objects will remain in the cache until they either expire or are explicitly invalidated.
If you have a high likelihood of simultaneous requests for the same session object, then the EVICT_ON_SESSION_EXIT policy will ensure the session object stays in the cache as long as it is needed.
Clustering Without a Sticky Load Balancer
Without a sticky load balancer requests for the same session may arrive on any node in the cluster.
This means it is likely that the copy of the session object in any SessionCache is likely to be out-of-date, as the session was probably last accessed on a different node.
In this case, your choices are to use either the NullSessionCache or to de-tune the DefaultSessionCache.
If you use the NullSessionCache all session object caching is avoided.
This means that every time a request references a session it must be read in from persistent storage.
It also means that there can be no sharing of session objects for multiple requests for the same session: each will have their own independent session object.
Furthermore, the outcome of session writes are indeterminate because the Servlet Specification does not mandate ACID transactions for sessions.
If you use the DefaultSessionCache, there is a risk that the caches on some nodes will contain out-of-date session information as simultaneous requests for the same session are scattered over the cluster.
To mitigate this somewhat you can use the EVICT_ON_SESSION_EXIT eviction policy: this will ensure that the session is removed from the cache as soon as the last simultaneous request for it exits.
Again, due to the lack of session transactionality, the ordering outcome of write operations cannot be guaranteed.
As the session is cached while at least one request is accessing it, it is possible for multiple simultaneous requests to share the same session object.
Handling Corrupted or Unreadable Session Data
For various reasons it might not be possible for the SessionDataStore to re-read a stored session.
One scenario is that the session stores a serialized object in its attributes, and after a re-deployment there in an incompatible class change.
Setting the $JETTY_BASE/start.d/session-cache-hash.ini or $JETTY_BASE/start.d/session-cache-null.ini property jetty.session.removeUnloadableSessions to true will allow the unreadable session to be removed from persistent storage.
This can be useful for preventing the scavenger from continually generating errors on the same expired, but un-readable session.
Jetty XML
The Jetty XML format is a straightforward mapping of XML elements to Java APIs so that any object can be instantiated and getters, setters, and methods can be called.
The Jetty XML format is very similar to that of frameworks like Spring or Plexus, although it predates all of them and it’s typically more powerful as it can invoke any Java API.
The Jetty XML format is used in Jetty modules to create the Jetty server components, as well as in Jetty XML context files to configure web applications, but it can be used to call any Java API.
Jetty XML Syntax
The Jetty XML syntax defines XML element that allow you to call any Java API and that allow you to interact in a simpler way with the Jetty module system and the Jetty deploy system.
The Jetty XML elements define attributes such as id, name, class, etc. that may be replaced by correspondent elements, so that these XML documents are equivalent:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure>
<Get id="stderr" class="java.lang.System" name="err">
<Call name="println" arg="HELLO" />
</Get>
</Configure>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure>
<Get>
<Id>stderr</Id>
<Name>err</Name>
<Class>java.lang.System</Class>
<Call>
<Name>println</Name>
<Arg>HELLO</Arg>
</Call>
</Get>
</Configure>
The version using attributes is typically shorter and nicer to read, but sometimes the attribute value cannot be a literal string (for example, it could be the value of a system property) and that’s where elements gives you the required flexibility.
<Configure>
Element Configure must be the root element of the XML document.
The following Jetty XML creates an empty String and assigns it the id mystring:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="mystring" class="java.lang.String" />
This is equivalent to the following Java code:
var mystring = new String();
If an object with the id mystring already exists, then it is not created again but rather just referenced.
Typically the <Configure> element is used to configure a Server instance or ContextHandler subclasses such as WebAppContext that represent web applications.
<Arg>
Element Arg is used to pass arguments to constructors and method calls.
The following example creates a minimal Jetty Server:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.server.Server">
<Arg type="int">8080</Arg>
</Configure>
Arguments may have a type attribute that explicitly performs type coercion.
Arguments may also have a name attribute, which is matched with the corresponding Java annotation in the source class, that helps to identify arguments:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.server.Server">
<Arg name="port" type="int">8080</Arg>
</Configure>
<New>
Element <New> creates a new object of the type specified by the mandatory class attribute.
A sequence of Arg elements, that must be contiguous and before other elements, may be present to specify the constructor arguments.
Within element <New> the newly created object is in scope and may be the implicit target of other, nested, elements.
The following example creates an ArrayList:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure>
<New id="mylist" class="java.util.ArrayList">
<Arg type="int">16</Arg>
</New>
</Configure>
This is equivalent to the following Java code:
var mylist = new ArrayList(16);
<Call>
Element <Call> invokes a method specified by the mandatory name attribute.
A sequence of Arg elements, that must be contiguous and before other elements, may be present to specify the method arguments.
Within element <Call> the return value, if the return type is not void, is in scope and may be the implicit target of other, nested, elements.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure>
<New class="java.util.ArrayList">
<Call name="listIterator">
<Arg type="int">0</Arg>
</Call>
<Call name="next" />
</New>
</Configure>
This is equivalent to the following Java code:
new ArrayList().listIterator(0).next();
It is possible to call static methods by specifying the class attribute:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure>
<Call id="myhost" name="getByName" class="java.net.InetAddress">
<Arg>jdk.java.net</Arg>
</Call>
</Configure>
This is equivalent to the following Java code:
var myhost = InetAddress.getByName("jdk.java.net");
<Get>
Element <Get> retrieves the value of a JavaBean property specified by the mandatory name attribute.
If the JavaBean property is foo (or Foo), <Get> first attempts to invoke method getFoo(); failing that, attempts to retrieve the value from field foo (or Foo).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="server" class="org.eclipse.jetty.server.Server">
<!-- Invokes getter method server.getVersion() -->
<Get id="version" name="version" />
<!-- Gets the System.err field -->
<Get class="java.lang.System" name="err">
<Call name="println">
<Arg>Jetty</Arg>
</Call>
</Get>
</Configure>
<Set>
Element <Set> stores the value of a JavaBean property specified by the mandatory name attribute.
If the JavaBean property is foo (or Foo), <Set> first attempts to invoke method setFoo(…) with the value in the scope as argument; failing that, attempts to store the value in the scope to field foo (or Foo).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="server" class="org.eclipse.jetty.server.Server">
<!-- The value in the <Set> scope is the string "true" -->
<Set name="dryRun">true</Set>
<!-- The value in the <Set> scope is the instance created by <New> -->
<Set name="requestLog">
<New class="org.eclipse.jetty.server.CustomRequestLog" />
</Set>
</Configure>
<Map> and <Entry>
Element <Map> allows the creation of a new java.util.Map implementation, specified by the class attribute — by default a HashMap.
The map entries are specified with a sequence of <Entry> elements, each with exactly 2 <Item> elements, for example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure>
<Map class="java.util.concurrent.ConcurrentHashMap">
<Entry>
<Item>host</Item>
<Item>
<Call class="java.net.InetAddress" name="getByName">
<Arg>localhost</Arg>
</Call>
</Item>
</Entry>
</Map>
</Configure>
<Put>
Element <Put> is a convenience element that puts a key/value pair into objects that implement java.util.Map.
You can only specify the key value via the name attribute, so the key can only be a literal string (for keys that are not literal strings, use the <Call> element).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure>
<New class="java.util.Properties">
<Put name="host">
<Call class="java.net.InetAddress" name="getByName">
<Arg>localhost</Arg>
</Call>
</Put>
</New>
</Configure>
<Array> and <Item>
Element <Array> creates a new array, whose component type may be specified by the type attribute.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure>
<Array type="java.lang.Object">
<Item /> <!-- null -->
<Item>literalString</Item>
<Item type="String"></Item> <!-- empty string -->
<Item type="Double">1.0D</Item>
<Item>
<New class="java.lang.Exception" />
</Item>
</Array>
</Configure>
<Ref>
Element <Ref> allows you to reference an object via the refid attribute`, putting it into scope so that nested elements can operate on it.
You must give a unique id attribute to the objects you want to reference.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<!-- The Jetty Server has id="server" -->
<Configure id="server" class="org.eclipse.jetty.server.Server">
<Get class="java.lang.System" name="err">
<!-- Here the System.err field is in scope, but you
want to operate on the server to get its version -->
<Ref refid="server">
<!-- Store the server version under id="myversion" -->
<Get id="myversion" name="version" />
</Ref>
<Call name="println">
<!-- Reference the server version stored above -->
<Arg>Server version is: <Ref refid="myversion" /></Arg>
</Call>
</Get>
</Configure>
<Property>
Element <Property> retrieves the value of the Jetty module property specified by the name attribute, and it is mostly used when creating custom Jetty modules or when using Jetty context XML files.
The deprecated attribute allows you to specify a comma separated list of old, deprecated, property names for backward compatibility.
The default attribute allows you to specify a default value for the property, if it has not been explicitly defined.
For example, you may want to configure the context path of your web application in this way:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">
<Property name="com.myapps.mywiki.context.path" default="/wiki" />
</Set>
<Set name="war">/opt/myapps/mywiki.war</Set>
</Configure>
The contextPath value is resolved by looking for the Jetty module property com.myapps.mywiki.context.path; if this property is not set, then the default value of /wiki is used.
<SystemProperty>
Element <SystemProperty> retrieves the value of the JVM system property specified by the name attribute, via System.getProperty(…).
The deprecated attribute allows you to specify a comma separated list of old, deprecated, system property names for backward compatibility.
The default attribute allows you to specify a default value for the system property value, if it has not been explicitly defined.
The following example creates a minimal Jetty Server that listens on a port specified by the com.acme.http.port system property:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="server" class="org.eclipse.jetty.server.Server">
<Arg type="int">
<SystemProperty name="com.acme.http.port" default="8080" />
</Arg>
</Configure>
<Env>
Element <Env> retrieves the value of the environment variable specified by the name attribute, via System.getenv(…).
The deprecated attribute allows you to specify a comma separated list of old, deprecated, environment variable names for backward compatibility.
The default attribute allows you to specify a default value for the environment variable value, if it has not been explicitly defined.
The following example creates a minimal Jetty Server that listens on a port specified by the COM_ACME_HTTP_PORT environment variable:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="server" class="org.eclipse.jetty.server.Server">
<Arg type="int">
<Env name="COM_ACME_HTTP_PORT" default="8080" />
</Arg>
</Configure>
Type Coercion
Elements that have the type attribute explicitly perform the type coercion of the string value present in the XML document to the Java type specified by the type attribute.
Supported types are the following:
-
all primitive types and their boxed equivalents, for example
type="int"but alsotype="Integer"(short form) andtype="java.lang.Integer"(fully qualified form) -
java.lang.String, in both short form and fully qualified form -
java.net.URL, in both short form and fully qualified form -
java.net.InetAddress, in both short form and fully qualified form
Scopes
Elements that create new objects or that return a value create a scope. Within these elements there may be nested elements that will operate on that scope, i.e. on the new object or returned value.
The following example illustrates how scopes work:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure id="server" class="org.eclipse.jetty.server.Server">
<Arg type="int">8080</Arg>
<!-- Here the Server object has been created and is in scope -->
<!-- Calls the setter on the Server object that is in scope -->
<Set name="stopTimeout">5000</Set>
<!-- Creates a new object -->
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<!-- Here the HttpConfiguration just created is in a nested scope -->
<!-- Calls the setter on the HttpConfiguration object that is in scope -->
<Set name="secureScheme">https</Set>
</New>
<!-- Calls the getter on the Server object that is in scope -->
<Get name="ThreadPool">
<!-- Here the ThreadPool object returned by the getter is in a nested scope -->
<!-- Calls the setter on the ThreadPool object that is in scope -->
<Set name="maxThreads" type="int">256</Set>
</Get>
<!-- Gets the System.err field -->
<Get class="java.lang.System" name="err">
<!-- Here the System.err object is in scope -->
<!-- Equivalent to: var myversion = server.getVersion() -->
<Ref refid="server">
<!-- Here the "server" object is in scope -->
<Get id="myversion" name="version" />
</Ref>
<!-- Calls println() on the System.err object -->
<Call name="println">
<Arg>Server version is: <Ref refid="myversion" /></Arg>
</Call>
</Get>
</Configure>