blob: 538887268d70f403fac64637c510d2b3168cdbb0 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.10">
<title>Eclipse Jetty: Operations Guide</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="./asciidoctor.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body class="article toc2 toc-left">
<div id="header">
<h1>Eclipse Jetty: Operations Guide</h1>
<div class="details">
<span id="author" class="author">Jetty Developers</span><br>
<span id="email" class="email"><a href="mailto:jetty-dev@eclipse.org">jetty-dev@eclipse.org</a></span><br>
<span id="revnumber">version 11.0.0,</span>
<span id="revdate">2020-12-02</span>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Operations Guide</div>
<ul class="sectlevel1">
<li><a href="#og-intro">Eclipse Jetty Operations Guide</a>
<ul class="sectlevel2">
<li><a href="#og-introduction">Introduction</a></li>
<li><a href="#og-eclipse-jetty-features">Eclipse Jetty Features</a></li>
<li><a href="#og-eclipse-jetty-how-tos">Eclipse Jetty How-Tos</a></li>
<li><a href="#og-begin">Introduction to Eclipse Jetty</a>
<ul class="sectlevel3">
<li><a href="#og-quick-jetty-setup">Quick Jetty Setup</a></li>
<li><a href="#og-begin-download">Downloading Eclipse Jetty</a></li>
<li><a href="#og-begin-install">Installing Eclipse Jetty</a></li>
<li><a href="#og-begin-arch">Eclipse Jetty Architecture Overview</a>
<ul class="sectlevel4">
<li><a href="#og-begin-arch-modules">Eclipse Jetty Architecture: Modules</a></li>
<li><a href="#og-begin-arch-jetty-base">Eclipse Jetty Architecture: <code>$JETTY_BASE</code></a></li>
<li><a href="#base-vs-home-resolution">Eclipse Jetty Architecture: <code>$JETTY_HOME</code> and <code>$JETTY_BASE</code> Configuration Resolution</a></li>
</ul>
</li>
<li><a href="#og-begin-start">Starting Eclipse Jetty</a></li>
<li><a href="#og-begin-deploy">Deploying Web Applications to Eclipse Jetty</a>
<ul class="sectlevel4">
<li><a href="#og-begin-deploy-war">Deploying Standard *.war Web Applications</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#og-start-details">Starting Eclipse Jetty: Details</a></li>
<li><a href="#og-start-jar">Using start.jar</a>
<ul class="sectlevel3">
<li><a href="#executing-startjar">Executing start.jar</a></li>
<li><a href="#og-start-jar-command-line-options">start.jar Command Line Options</a>
<ul class="sectlevel4">
<li><a href="#og-command-line-options">Command Line Options</a></li>
<li><a href="#og-debug-and-start-logging">Debug and Start Logging</a></li>
<li><a href="#og-module-management">Module Management</a></li>
<li><a href="#og-startup-shutdown-command-line">Startup / Shutdown Command Line</a></li>
<li><a href="#og-advanced-commands">Advanced Commands</a></li>
</ul>
</li>
<li><a href="#og-shaded-start-jar">Shaded Start.jar</a></li>
<li><a href="#og-start-jar-without-exec-or-forking">Start.jar without exec or forking.</a></li>
</ul>
</li>
<li><a href="#og-deploy">Customizing Web Application Deployment</a>
<ul class="sectlevel3">
<li><a href="#og-deploy-hot-static">Hot vs Static Deployment</a></li>
<li><a href="#og-deploy-rules">Deployment Rules</a></li>
<li><a href="#og-deploy-jetty">Deploying Jetty Context XML Files</a></li>
<li><a href="#og-deploy-jndi">Configuring JNDI Entries</a></li>
<li><a href="#og-deploy-virtual-hosts">Configuring Virtual Hosts</a>
<ul class="sectlevel4">
<li><a href="#og-deploy-virtual-hosts-names">Virtual Host Names</a></li>
<li><a href="#og-deploy-virtual-hosts-config">Virtual Hosts Configuration</a></li>
<li><a href="#og-deploy-virtual-hosts-same-context">Same Context Path, Different Virtual Hosts</a></li>
<li><a href="#og-deploy-virtual-hosts-port">Different Port, Different Web Application</a></li>
</ul>
</li>
<li><a href="#og-deploy-extract-war">Configuring <code>*.war</code> File Extraction</a></li>
<li><a href="#og-deploy-jetty-override-web-xml">Overriding <code>web.xml</code></a></li>
<li><a href="#og-deploy-init-params">Configuring <code>init-param</code>s</a></li>
</ul>
</li>
<li><a href="#og-protocols">Configuring Eclipse Jetty Connectors and Protocols</a>
<ul class="sectlevel3">
<li><a href="#og-protocols-http">Configuring Clear-Text HTTP/1.1</a></li>
<li><a href="#og-protocols-https">Configuring Secure HTTP/1.1</a></li>
<li><a href="#og-protocols-http2">Configuring HTTP/2</a></li>
<li><a href="#og-secure-vs-clear-text-http2">Secure vs Clear-Text HTTP/2</a></li>
<li><a href="#og-protocols-http2s">Configuring Secure HTTP/2</a></li>
<li><a href="#og-protocols-http2c">Configuring Clear-Text HTTP/2</a></li>
<li><a href="#og-protocols-ssl">Configuring Secure Protocols</a>
<ul class="sectlevel4">
<li><a href="#og-protocols-ssl-customize">Customizing KeyStore and TLS Configuration</a></li>
<li><a href="#og-protocols-ssl-renew">Renewing the Certificates</a></li>
<li><a href="#og-protocols-ssl-reload">Watching and Reloading the KeyStore</a></li>
<li><a href="#og-protocols-ssl-conscrypt">Using Conscrypt as TLS Provider</a></li>
<li><a href="#og-protocols-ssl-sni">Configuring SNI</a></li>
</ul>
</li>
<li><a href="#og-protocols-proxy">Configuring Eclipse Jetty Behind a Load Balancer or Reverse Proxy</a>
<ul class="sectlevel4">
<li><a href="#og-protocols-proxy-forwarded">Configuring Jetty for the Forwarded Header</a></li>
<li><a href="#og-protocols-proxy-protocol">Configuring Jetty for the Proxy Protocol</a></li>
<li><a href="#og-protocols-proxy-haproxy">Configuring HAProxy and Jetty for HTTP/1.1 and HTTP/2</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#og-keystore">Configuring KeyStores</a>
<ul class="sectlevel3">
<li><a href="#og-keystore-create">Creating a KeyStore</a></li>
<li><a href="#og-keystore-csr">Creating a Certificate Signing Request</a></li>
<li><a href="#og-keystore-csr-import">Importing the Signed Certificate</a></li>
<li><a href="#og-keystore-client-authn">Creating a KeyStore for Client Certificate Authentication</a></li>
<li><a href="#og-modules">Jetty Modules</a></li>
<li><a href="#og-module-bytebufferpool">Module <code>bytebufferpool</code></a></li>
<li><a href="#og-module-deploy">Module <code>deploy</code></a></li>
<li><a href="#og-module-http">Module <code>http</code></a>
<ul class="sectlevel4">
<li><a href="#og-module-http-acceptors">Configuration of Acceptors</a></li>
<li><a href="#og-module-http-selectors">Configuration of Selectors</a></li>
</ul>
</li>
<li><a href="#og-module-http2">Module <code>http2</code></a></li>
<li><a href="#og-module-http2c">Module <code>http2c</code></a></li>
<li><a href="#og-module-http-forwarded">Module <code>http-forwarded</code></a></li>
<li><a href="#og-module-https">Module <code>https</code></a></li>
<li><a href="#og-module-server">Module <code>server</code></a></li>
<li><a href="#og-module-ssl">Module <code>ssl</code></a>
<ul class="sectlevel4">
<li><a href="#og-module-ssl-connector">Secure Connector Properties</a></li>
<li><a href="#og-module-ssl-keystore-tls">KeyStore Properties and TLS Properties</a></li>
</ul>
</li>
<li><a href="#og-module-ssl-reload">Module <code>ssl-reload</code></a></li>
<li><a href="#og-module-test-keystore">Module <code>test-keystore</code></a></li>
<li><a href="#og-module-threadpool">Module <code>threadpool</code></a></li>
</ul>
</li>
<li><a href="#og-xml">Jetty XML</a>
<ul class="sectlevel3">
<li><a href="#og-xml-syntax">Jetty XML Syntax</a>
<ul class="sectlevel4">
<li><a href="#og-xml-syntax-configure"><code>&lt;Configure&gt;</code></a></li>
<li><a href="#og-xml-syntax-arg"><code>&lt;Arg&gt;</code></a></li>
<li><a href="#og-xml-syntax-new"><code>&lt;New&gt;</code></a></li>
<li><a href="#og-xml-syntax-call"><code>&lt;Call&gt;</code></a></li>
<li><a href="#og-xml-syntax-get"><code>&lt;Get&gt;</code></a></li>
<li><a href="#og-xml-syntax-set"><code>&lt;Set&gt;</code></a></li>
<li><a href="#og-xml-syntax-map"><code>&lt;Map&gt;</code> and <code>&lt;Entry&gt;</code></a></li>
<li><a href="#og-xml-syntax-put"><code>&lt;Put&gt;</code></a></li>
<li><a href="#og-xml-syntax-array"><code>&lt;Array&gt;</code> and <code>&lt;Item&gt;</code></a></li>
<li><a href="#og-xml-syntax-ref"><code>&lt;Ref&gt;</code></a></li>
<li><a href="#og-xml-syntax-property"><code>&lt;Property&gt;</code></a></li>
<li><a href="#og-xml-syntax-system-property"><code>&lt;SystemProperty&gt;</code></a></li>
<li><a href="#og-xml-syntax-env"><code>&lt;Env&gt;</code></a></li>
<li><a href="#og-xml-syntax-types">Type Coercion</a></li>
<li><a href="#og-xml-syntax-scope">Scopes</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#og-sessions">HTTP Session Management</a>
<ul class="sectlevel3">
<li><a href="#og-session-overview">HTTP Session Overview</a>
<ul class="sectlevel4">
<li><a href="#og-terminology">Terminology</a></li>
<li><a href="#og-session-modules">Session Modules</a></li>
</ul>
</li>
<li><a href="#og-session-base">The Base Session Module</a>
<ul class="sectlevel4">
<li><a href="#og-configuration">Configuration</a></li>
<li><a href="#og-session-base-scavenge">Session Scavenging</a></li>
</ul>
</li>
<li><a href="#og-session-cache">Modules for HTTP Session Caching</a>
<ul class="sectlevel4">
<li><a href="#og-session-cache-hash">Caching in Memory</a></li>
<li><a href="#og-session-cache-null">No Caching</a></li>
</ul>
</li>
<li><a href="#og-session-filesystem">Modules for Persistent HTTP Sessions: File System</a>
<ul class="sectlevel4">
<li><a href="#og-configuration-4">Configuration</a></li>
</ul>
</li>
<li><a href="#og-session-jdbc">Modules for Persistent HTTP Sessions: JDBC</a>
<ul class="sectlevel4">
<li><a href="#og-configuration-5">Configuration</a></li>
</ul>
</li>
<li><a href="#og-session-mongo">Modules for Persistent HTTP Sessions: MongoDB</a>
<ul class="sectlevel4">
<li><a href="#og-configuration-6">Configuration</a></li>
</ul>
</li>
<li><a href="#og-session-infinispan">Modules for Persistent HTTP Sessions: Infinispan</a>
<ul class="sectlevel4">
<li><a href="#og-session-infinispan-remote">Remote Infinispan Session Module</a></li>
<li><a href="#og-session-infinispan-remote-query">Remote Infinispan Query Module</a></li>
<li><a href="#og-session-infinispan-embedded">Embedded Infinispan Session Module</a></li>
<li><a href="#og-session-infinispan-embedded-query">Embedded Infinispan Query Module</a></li>
<li><a href="#og-converting-session-format-for-jetty-9-4-13">Converting Session Format for Jetty-9.4.13</a></li>
</ul>
</li>
<li><a href="#og-session-hazelcast">Modules for Persistent HTTP Sessions: Hazelcast</a>
<ul class="sectlevel4">
<li><a href="#og-session-hazelcast-remote">Remote Hazelcast Clustering</a></li>
<li><a href="#og-session-hazelcast-embedded">Embedded Hazelcast Clustering</a></li>
</ul>
</li>
<li><a href="#og-session-gcloud">Modules for Persistent HTTP Sessions: Google Cloud DataStore</a>
<ul class="sectlevel4">
<li><a href="#og-preparation">Preparation</a></li>
<li><a href="#og-communicating-with-gclouddatastore">Communicating with GCloudDataStore</a></li>
<li><a href="#og-configuring-indexes-for-session-data">Configuring Indexes for Session Data</a></li>
<li><a href="#og-communicating-with-the-gclouddatastore-emulator">Communicating with the GCloudDataStore Emulator</a></li>
<li><a href="#og-enabling-the-google-cloud-datastore-module">Enabling the Google Cloud DataStore Module</a></li>
</ul>
</li>
<li><a href="#og-configuration-11">Configuration</a></li>
<li><a href="#og-session-memcached">Modules for Persistent HTTP Sessions: The L2 Session Data Cache</a>
<ul class="sectlevel4">
<li><a href="#og-memcachedsessiondatamap">MemcachedSessionDataMap</a></li>
</ul>
</li>
<li><a href="#og-session-usecases">Session Scenarios</a>
<ul class="sectlevel4">
<li><a href="#og-minimizing-support-for-sessions">Minimizing Support for Sessions</a></li>
<li><a href="#og-clustering-with-a-sticky-load-balancer">Clustering with a Sticky Load Balancer</a></li>
<li><a href="#og-clustering-without-a-sticky-load-balancer">Clustering Without a Sticky Load Balancer</a></li>
<li><a href="#og-handling-corrupted-or-unreadable-session-data">Handling Corrupted or Unreadable Session Data</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#og-quickstart">Faster Web Application Deployment</a>
<ul class="sectlevel3">
<li><a href="#og-enabling">Enabling</a></li>
</ul>
</li>
<li><a href="#og-annotations">Annotations</a>
<ul class="sectlevel3">
<li><a href="#og-annotations-scanning">Annotation Scanning</a>
<ul class="sectlevel4">
<li><a href="#og-the-container-classpath">The container classpath</a></li>
<li><a href="#og-the-webapp-classpath">The webapp classpath</a></li>
<li><a href="#og-multi-threading">Multi-threading</a></li>
</ul>
</li>
<li><a href="#og-annotations-scis">ServletContainerInitializers</a>
<ul class="sectlevel4">
<li><a href="#og-exclusions">Exclusions</a></li>
<li><a href="#og-ordering">Ordering</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#og-jsp">Java Server Pages</a>
<ul class="sectlevel4">
<li><a href="#og-configuration-of-the-jsp-servlet">Configuration of the JSP servlet</a></li>
</ul>
</li>
<li><a href="#og-javaserver-pages-standard-tag-libraries">JavaServer Pages Standard Tag Libraries</a></li>
<li><a href="#og-javaserver-faces-taglibs">JavaServer Faces Taglibs</a></li>
<li><a href="#og-jndi">JNDI</a>
<ul class="sectlevel3">
<li><a href="#og-declaring-resources">Declaring resources</a>
<ul class="sectlevel4">
<li><a href="#og-jndi-env">org.eclipse.jetty.plus.jndi.EnvEntry</a></li>
<li><a href="#og-jndi-resource">org.eclipse.jetty.plus.jndi.Resource</a></li>
<li><a href="#og-jndi-tx">org.eclipse.jetty.plus.jndi.Transaction</a></li>
<li><a href="#og-jndi-link">org.eclipse.jetty.plus.jndi.Link</a></li>
<li><a href="#og-jndi-xml">Jetty XML files</a></li>
<li><a href="#og-jndi-scope">Resource scoping</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#og-jaas">JAAS</a>
<ul class="sectlevel3">
<li><a href="#og-jaas-configuration">Configuration</a>
<ul class="sectlevel4">
<li><a href="#og-jaas-module">The <code>jaas</code> module</a></li>
<li><a href="#og-jaas-webapp">Configure the webapp for JAAS</a></li>
<li><a href="#og-jaas-loginconf">Configure JAAS</a></li>
</ul>
</li>
<li><a href="#og-jaas-loginmodules">Provided LoginModules</a>
<ul class="sectlevel4">
<li><a href="#og-jdbcloginmodule">JDBCLoginModule</a></li>
<li><a href="#og-datasourceloginmodule">DataSourceLoginModule</a></li>
<li><a href="#og-propertyfileloginmodule">PropertyFileLoginModule</a></li>
<li><a href="#og-ldaploginmodule">LdapLoginModule</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#og-jmx">Eclipse Jetty Monitoring &amp; Management</a>
<ul class="sectlevel3">
<li><a href="#og-jmx-local">Enabling Local JMX Support</a></li>
<li><a href="#og-jmx-remote">Enabling Remote JMX Support</a>
<ul class="sectlevel4">
<li><a href="#og-jmx-remote-ssh-tunnel">Remote JMX Access with Port Forwarding via SSH Tunnel</a></li>
<li><a href="#og-jmx-remote-auth">Remote JMX Access Authentication &amp; Authorization</a></li>
<li><a href="#og-jmx-remote-secure">Securing Remote JMX Access with TLS</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#og-troubleshooting">Eclipse Jetty Troubleshooting</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<div class="sect1">
<h2 id="og-intro"><a class="anchor" href="#og-intro"></a><a class="link" href="#og-intro">Eclipse Jetty Operations Guide</a></h2>
<div class="sectionbody">
<div class="paragraph">
<p>The Eclipse Jetty Operations Guide targets sysops, devops, and developers who want to install Eclipse Jetty as a standalone server to deploy web applications.</p>
</div>
<div class="sect2">
<h3 id="og-introduction"><a class="anchor" href="#og-introduction"></a><a class="link" href="#og-introduction">Introduction</a></h3>
<div class="paragraph">
<p>If you are new to Eclipse Jetty, read <a href="#og-begin">here</a> to download, install, start and deploy web applications to Jetty.</p>
</div>
</div>
<div class="sect2">
<h3 id="og-eclipse-jetty-features"><a class="anchor" href="#og-eclipse-jetty-features"></a><a class="link" href="#og-eclipse-jetty-features">Eclipse Jetty Features</a></h3>
<div class="paragraph">
<p>If you know Eclipse Jetty already, jump to a feature:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#og-sessions">HTTP Session Caching and Clustering</a></p>
</li>
<li>
<p><a href="#og-protocols-http2">HTTP/2 Support</a></p>
</li>
<li>
<p><a href="#og-annotations">Annotations</a></p>
</li>
<li>
<p><a href="#og-quickstart">Faster Web Application Deployment</a></p>
</li>
<li>
<p><a href="#og-jaas">JAAS</a></p>
</li>
<li>
<p><a href="#og-jndi">JNDI</a></p>
</li>
<li>
<p><a href="#og-jsp">JSP</a></p>
</li>
<li>
<p><a href="#og-jmx">Monitoring &amp; Management</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>TODO</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Jetty Overview</p>
</li>
<li>
<p>Jetty Modules</p>
</li>
<li>
<p>Rewrite Modules</p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="og-eclipse-jetty-how-tos"><a class="anchor" href="#og-eclipse-jetty-how-tos"></a><a class="link" href="#og-eclipse-jetty-how-tos">Eclipse Jetty How-Tos</a></h3>
<div class="ulist">
<ul>
<li>
<p><a href="#og-protocols-http">Configure Clear-Text HTTP/1.1</a></p>
</li>
<li>
<p><a href="#og-protocols-https">Configure Secure HTTP/1.1 (https)</a></p>
</li>
<li>
<p><a href="#og-protocols-http2c">Configure Clear-Text HTTP/2</a></p>
</li>
<li>
<p><a href="#og-protocols-http2s">Configure Secure HTTP/2</a></p>
</li>
<li>
<p><a href="#og-protocols-proxy">Configure Jetty Behind a Load Balancer or Reverse Proxy</a></p>
</li>
<li>
<p><a href="#og-troubleshooting">Troubleshooting</a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="og-begin"><a class="anchor" href="#og-begin"></a><a class="link" href="#og-begin">Introduction to Eclipse Jetty</a></h3>
<div class="paragraph">
<p>This section will get you started with Eclipse Jetty.</p>
</div>
<div class="sect3">
<h4 id="og-quick-jetty-setup"><a class="anchor" href="#og-quick-jetty-setup"></a><a class="link" href="#og-quick-jetty-setup">Quick Jetty Setup</a></h4>
<div class="paragraph">
<p>Jetty is distributed in an artifact that expands in a directory called <code>$JETTY_HOME</code>, which should not be modified.</p>
</div>
<div class="paragraph">
<p>Configuration for Jetty is typically done in one (or more) other directories called <code>$JETTY_BASE</code>.</p>
</div>
<div class="paragraph">
<p>The following commands can be used to setup a <code>$JETTY_BASE</code> directory that supports deployment of <code>*.war</code> files and a clear-text HTTP connector:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ 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</pre>
</div>
</div>
<div class="paragraph">
<p>This will create a <code>$JETTY_BASE/start.d/</code> directory and other directories that contain the configuration of the server, including the <code>$JETTY_BASE/webapps/</code> directory, in which standard <code>*.war</code> files can be deployed.</p>
</div>
<div class="paragraph">
<p>To deploy Jetty&#8217;s demo web applications, run this command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=demo</pre>
</div>
</div>
<div class="paragraph">
<p>Now you can start the Jetty server with:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar</pre>
</div>
</div>
<div class="paragraph">
<p>Point your browser at <code>http://localhost:8080</code> to see the web applications deployed in Jetty.</p>
</div>
<div class="paragraph">
<p>The Jetty server can be stopped with <code>ctrl-c</code> in the terminal window.</p>
</div>
<div class="paragraph">
<p>The following sections will guide you in details about downloading, installing and starting Jetty, as well as deploying your web applications to Jetty.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-begin-download"><a class="anchor" href="#og-begin-download"></a><a class="link" href="#og-begin-download">Downloading Eclipse Jetty</a></h4>
<div class="paragraph">
<p>The Eclipse Jetty distribution is available for download from <a href="https://www.eclipse.org/jetty/download.html" class="bare">https://www.eclipse.org/jetty/download.html</a></p>
</div>
<div class="paragraph">
<p>The Eclipse Jetty distribution is available in both <code>zip</code> and <code>gzip</code> formats; download the one most appropriate for your system, typically <code>zip</code> for Windows and <code>gzip</code> for other operating systems.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-begin-install"><a class="anchor" href="#og-begin-install"></a><a class="link" href="#og-begin-install">Installing Eclipse Jetty</a></h4>
<div class="paragraph">
<p>After the download, unpacking Eclipse Jetty will extract the files into a directory called <code>jetty-home-VERSION</code>, where <code>VERSION</code> is the version that you downloaded, for example <code>10.0.0</code>, so that the directory is called <code>jetty-home-10.0.0</code>.</p>
</div>
<div class="paragraph">
<p>Unpack Eclipse Jetty compressed file in a convenient location, for example under <code>/opt</code>.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
For Windows users, you should unpack Jetty to a path that does not contain spaces.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The rest of the instructions in this documentation will refer to this location as <code>$JETTY_HOME</code>, or <code>${jetty.home}</code>.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
It is important that <strong>only</strong> 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 <strong>not</strong> suitable for production as they may contain security flaws or incomplete/non-functioning feature sets.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>If you are new to Jetty, you should read the <a href="#og-begin-arch">Jetty architecture section below</a> to become familiar with the terms used in this documentation.
Otherwise, you can jump to the <a href="#og-begin-start">section on starting Jetty</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-begin-arch"><a class="anchor" href="#og-begin-arch"></a><a class="link" href="#og-begin-arch">Eclipse Jetty Architecture Overview</a></h4>
<div class="paragraph">
<p>There are two main concepts on which the Eclipse Jetty standalone server is based:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The <a href="#og-begin-arch-modules">Jetty <em>module</em> system</a>, that provides the Jetty features</p>
</li>
<li>
<p>The <a href="#og-begin-arch-jetty-base"><code>$JETTY_BASE</code> directory</a>, that provides a place where you configure the modules, and therefore the features you need for your web applications</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>After installing Jetty, you will want to set up a <a href="#og-begin-arch-jetty-base"><code>$JETTY_BASE</code> directory</a> where you configure <a href="#og-begin-arch-modules">Jetty modules</a>.</p>
</div>
<div class="sect4">
<h5 id="og-begin-arch-modules"><a class="anchor" href="#og-begin-arch-modules"></a><a class="link" href="#og-begin-arch-modules">Eclipse Jetty Architecture: Modules</a></h5>
<div class="paragraph">
<p>The Jetty standalone server is made of components that are assembled together, configured and started to provide different features.</p>
</div>
<div class="paragraph">
<p>A Jetty <em>module</em> is made of one or more components that work together to provide typically one feature, although they may provide more than one feature.</p>
</div>
<div class="paragraph">
<p>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.
What you can do in Java code to assemble Jetty components can be done using Jetty modules.</p>
</div>
<div class="paragraph">
<p>A Jetty module may be dependent on other Jetty modules: for example, the <code>http</code> Jetty module depends on the <code>server</code> Jetty module which in turn depends on the <code>threadpool</code> and <code>logging</code> Jetty modules.</p>
</div>
<div class="paragraph">
<p>Every feature in a Jetty server is enabled by enabling the corresponding Jetty module(s).</p>
</div>
<div class="paragraph">
<p>For example, if you enable only the <code>http</code> 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. <code>https</code>) requests, it will not be able to process WebSocket, or HTTP/2 or any other protocol because the correspondent modules have not been enabled.</p>
</div>
<div class="paragraph">
<p>You can even start a Jetty server <em>without</em> listening on a network port&#8201;&#8212;&#8201;for example because you have enabled a custom module you wrote that provides the features you need.</p>
</div>
<div class="paragraph">
<p>This allows the Jetty standalone server to be as small as necessary: modules that are not enabled are not loaded, don&#8217;t waste memory, and you don&#8217;t risk a client using a module that you did not know was even there.</p>
</div>
<div class="paragraph">
<p>For more detailed information about the Jetty module system, see <a href="#og-modules">this section</a>.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-begin-arch-jetty-base"><a class="anchor" href="#og-begin-arch-jetty-base"></a><a class="link" href="#og-begin-arch-jetty-base">Eclipse Jetty Architecture: <code>$JETTY_BASE</code></a></h5>
<div class="paragraph">
<p>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 <code>${jetty.home}</code>), and the customizations for your specific environment(s) (known as <code>${jetty.base}</code>).
In addition to easy management of multiple server instances, is allows for quick, drop-in upgrades of Jetty.
There should always only be <strong>one</strong> Jetty Home (per version of Jetty), but there can be multiple Jetty Base directories that reference it.</p>
</div>
<div class="paragraph">
<p>This separation between <code>$JETTY_HOME</code> and <code>$JETTY_BASE</code> allows upgrades without affecting your web applications.
<code>$JETTY_HOME</code> contains the Jetty runtime and libraries and the default configuration, while a <code>$JETTY_BASE</code> contains your web applications and any override of the default configuration.</p>
</div>
<div class="paragraph">
<p>For example, with the <code>$JETTY_HOME</code> installation the default value for the network port for clear-text HTTP is <code>8080</code>.
However, you want that port to be <code>6060</code>, because you are behind a load balancer that is configured to forward to the backend on port <code>6060</code>.</p>
</div>
<div class="paragraph">
<p>Instead, you want to configure the clear-text HTTP port in your <code>$JETTY_BASE</code>.
When you upgrade Jetty, you will upgrade only files in <code>$JETTY_HOME</code>, and all the configuration in <code>$JETTY_BASE</code> will remain unchanged.</p>
</div>
<div class="paragraph">
<p>Installing the Jetty runtime and libraries in <code>$JETTY_HOME</code> also allows you to leverage file system permissions: <code>$JETTY_HOME</code> may be owned by an administrator user (so that only administrators can upgrade it), while <code>$JETTY_BASE</code> directories may be owned by a less privileged user.</p>
</div>
<div class="paragraph">
<p>If you had changed the default configuration in <code>$JETTY_HOME</code>, when you upgrade Jetty, say from version <code>10.0.0</code> to version <code>10.0.1</code>, your change would be lost.
Maintaining all the changes in <code>$JETTY_HOME</code>, and having to reconfigure these with each upgrade results in a massive commitment of time and effort.</p>
</div>
<div class="paragraph">
<p>To recap:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>$JETTY_BASE</code></dt>
<dd>
<div class="ulist">
<ul>
<li>
<p>This is the location for your configurations and customizations to the Jetty distribution.</p>
</li>
</ul>
</div>
</dd>
<dt class="hdlist1"><code>$JETTY_HOME</code></dt>
<dd>
<div class="ulist">
<ul>
<li>
<p>This is the location for the Jetty distribution binaries, default XML IoC configurations, and default module definitions.</p>
</li>
</ul>
</div>
</dd>
</dl>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
Jetty Home should always be treated as a standard of truth.
All configuration modifications, changes and additions should <strong>always</strong> be made in the appropriate Jetty Base directory.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect4">
<h5 id="base-vs-home-resolution"><a class="anchor" href="#base-vs-home-resolution"></a><a class="link" href="#base-vs-home-resolution">Eclipse Jetty Architecture: <code>$JETTY_HOME</code> and <code>$JETTY_BASE</code> Configuration Resolution</a></h5>
<div class="paragraph">
<p>Potential configuration is resolved from these 2 directory locations.
When Jetty starts up in processes configuration from them as follows:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Check Jetty Base First</dt>
<dd>
<p>If the referenced configuration exists, relative to the defined Jetty base, it is used.</p>
</dd>
<dt class="hdlist1">Check Jetty Home Second</dt>
<dd>
<p>If the referenced configuration exists, relative to the defined Jetty home, it is used.</p>
</dd>
<dt class="hdlist1">Use java.io.File(String pathname) Logic</dt>
<dd>
<p>Lastly, use the reference as a <code>java.io.File(String pathname)</code> 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).</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-begin-start"><a class="anchor" href="#og-begin-start"></a><a class="link" href="#og-begin-start">Starting Eclipse Jetty</a></h4>
<div class="paragraph">
<p>Eclipse Jetty as a standalone server has no graphical user interface, so configuring and running the server is done from the command line.</p>
</div>
<div class="paragraph">
<p>Recall from the <a href="#og-begin-arch">Eclipse Jetty standalone server architecture section</a> that Jetty is based on <a href="#og-modules">modules</a>, that provides features, and on <a href="#og-begin-arch-jetty-base"><code>$JETTY_BASE</code></a>, the place where you configure which module (and therefore which feature) you want to enable, and where you configure module parameters.</p>
</div>
<div class="paragraph">
<p>Jetty is started by executing <code>$JETTY_HOME/start.jar</code>, but first we need to create a <code>$JETTY_BASE</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ JETTY_BASE=/path/to/jetty.base
$ cd $JETTY_BASE
$ java -jar $JETTY_HOME/start.jar</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>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</pre>
</div>
</div>
<div class="paragraph">
<p>The error is normal, since the <code>$JETTY_BASE</code> you just created is empty and therefore there is no configuration to use to assemble the Jetty server.</p>
</div>
<div class="paragraph">
<p>However, it shows that <code>start.jar</code> takes parameters, whose details can be found in <a href="#og-start-jar">this section</a>.</p>
</div>
<div class="paragraph">
<p>You can explore what modules are available out of the box via:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --list-modules=*</pre>
</div>
</div>
<div class="paragraph">
<p>Try to enable the <code>http</code> module (see also <a href="#og-protocols-http">this section</a> for additional information):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=http</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>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</pre>
</div>
</div>
<div class="paragraph">
<p>Now you can start Jetty:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>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, <mark>(http/1.1)}{0.0.0.0:8080}</mark>
2020-09-11 15:35:17.496:INFO :oejs.Server:main: Started Server@44821a96{STARTING}[10.0.0-SNAPSHOT,sto=5000] @553ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note how Jetty is listening on port <code>8080</code> for clear-text HTTP/1.1 connections.</p>
</div>
<div class="paragraph">
<p>After having enabled the <code>http</code> module, the <code>$JETTY_BASE</code> directory looks like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>JETTY_BASE
├── resources
│ └── jetty-logging.properties <i class="conum" data-value="1"></i><b>(1)</b>
└── start.d <i class="conum" data-value="2"></i><b>(2)</b>
└── http.ini <i class="conum" data-value="3"></i><b>(3)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The <code>resources/jetty-logging.properties</code> file has been created because the <code>http</code> modules depends on the <code>server</code> module, which in turn depends on the <code>logging</code> module; the <code>logging</code> module created this file that can be configured to control the server logging level.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The <code>start.d/</code> directory contains the configuration files for the modules.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>The <code>start.d/http.ini</code> file is the <code>http</code> module configuration file, where you can specify values for the <code>http</code> module properties.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>In the <code>http.ini</code> file you can find the following content (among other content):</p>
</div>
<div class="listingblock">
<div class="title">http.ini</div>
<div class="content">
<pre class="highlight"><code>--module=http <i class="conum" data-value="1"></i><b>(1)</b>
# jetty.http.port=8080 <i class="conum" data-value="2"></i><b>(2)</b>
...</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This line enables the <code>http</code> module and should not be modified.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>This line is commented out and specifies the default value for the module property <code>jetty.http.port</code>, which is the network port that listens for clear-text HTTP connections.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>You can change the module property <code>jetty.http.port</code> value directly from the command line:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar jetty.http.port=9999</pre>
</div>
</div>
<div class="paragraph">
<p>To make this change persistent, you can edit the <code>http.ini</code> file, uncomment the module property <code>jetty.http.port</code> and change its value to <code>9999</code>:</p>
</div>
<div class="listingblock">
<div class="title">http.ini</div>
<div class="content">
<pre>--module=http
jetty.http.port=9999
...</pre>
</div>
</div>
<div class="paragraph">
<p>If you restart Jetty, the new value will be used:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>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, <mark>(http/1.1)}{0.0.0.0:9999}</mark>
2020-09-11 15:35:17.496:INFO :oejs.Server:main: Started Server@44821a96{STARTING}[10.0.0-SNAPSHOT,sto=5000] @553ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note how Jetty is now listening on port <code>9999</code> for clear-text HTTP/1.1 connections.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
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 <a href="#og-protocols">this section</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The Jetty server is now up and running, but it has no web applications deployed, so it just replies with <code>404 Not Found</code> to every request.
It is time to <a href="#og-begin-deploy">deploy your web applications</a> to Jetty.</p>
</div>
<div class="paragraph">
<p>For more detailed information about the Jetty start system, you can read the <a href="#og-start-details">Jetty start system</a> section.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-begin-deploy"><a class="anchor" href="#og-begin-deploy"></a><a class="link" href="#og-begin-deploy">Deploying Web Applications to Eclipse Jetty</a></h4>
<div class="paragraph">
<p>For the purpose of deploying web applications to Jetty, there are two types of resources that can be deployed:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Standard Web Application Archives, in the form of <code>*.war</code> files or <code>*.war</code> directories, defined by the Servlet specification.
Their deployment is described in <a href="#og-begin-deploy-war">this section</a>.</p>
</li>
<li>
<p>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 <a href="#og-deploy">this section</a>.</p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="og-begin-deploy-war"><a class="anchor" href="#og-begin-deploy-war"></a><a class="link" href="#og-begin-deploy-war">Deploying Standard *.war Web Applications</a></h5>
<div class="paragraph">
<p>A standard Servlet web application is packaged in either a <code>*.war</code> file or in a directory with the structure of a <code>*.war</code> file.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Recall that the structure of a <code>*.war</code> file is as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>mywebapp.war
├── index.html <i class="conum" data-value="1"></i><b>(1)</b>
└── WEB-INF <i class="conum" data-value="2"></i><b>(2)</b>
├── classes/ <i class="conum" data-value="3"></i><b>(3)</b>
├── lib/ <i class="conum" data-value="4"></i><b>(4)</b>
└── web.xml <i class="conum" data-value="5"></i><b>(5)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Publicly accessible resources such as <code>*.html</code>, <code>*.jsp</code>, <code>*.css</code>, <code>*.js</code> files, etc. are placed in <code>*.war</code> or in sub-directories of the <code>*.war</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td><code>WEB-INF</code> is a special directory used to store anything related to the web application that must not be publicly accessible, but may be accessed by other resources.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td><code>WEB-INF/classes</code> stores the web application compiled <code>*.class</code> files</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td><code>WEB-INF/classes</code> stores the web application <code>*.jar</code> files</td>
</tr>
<tr>
<td><i class="conum" data-value="5"></i><b>5</b></td>
<td><code>WEB-INF/web.xml</code> is the web application deployment descriptor defines the components and the configuration of your web application.</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To deploy a standard web application, you need to enable the <code>deploy</code> module (see the <code>deploy</code> module complete definition <a href="#og-module-deploy">here</a>).</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=deploy</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>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</pre>
</div>
</div>
<div class="paragraph">
<p>The <code>deploy</code> module creates the <code>$JETTY_BASE/webapps</code> directory, the directory where <code>*.war</code> files or <code>*.war</code> directories should be copied so that Jetty can deploy them.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The <code>deploy</code> module only provides the feature of deploying web applications.</p>
</div>
<div class="paragraph">
<p>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 <a href="#og-protocols">section about protocols</a> for further information.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Now you need to copy a web application to the <code>$JETTY_BASE/webapps</code> directory:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>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</pre>
</div>
</div>
<div class="paragraph">
<p>The <code>$JETTY_BASE</code> directory is now:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$JETTY_BASE
├── resources
│ └── jetty-logging.properties
├── start.d
│ ├── deploy.ini
│ └── http.ini
└── webapps
└── test.war</pre>
</div>
</div>
<div class="paragraph">
<p>Now start Jetty:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>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-11.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</pre>
</div>
</div>
<div class="paragraph">
<p>Now you can access the web application by pointing your browser to <code>http://localhost:8080/test</code>.</p>
</div>
<div class="paragraph">
<p>If you want to customize the deployment of your web application, for example by specifying a <code>contextPath</code> different from the file/directory name, or by specifying JNDI entries, or by specifying virtual hosts, etc. read <a href="#og-deploy">this section</a>.</p>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-start-details"><a class="anchor" href="#og-start-details"></a><a class="link" href="#og-start-details">Starting Eclipse Jetty: Details</a></h3>
</div>
<div class="sect2">
<h3 id="og-start-jar"><a class="anchor" href="#og-start-jar"></a><a class="link" href="#og-start-jar">Using start.jar</a></h3>
<div class="paragraph">
<p>TODO: review in light of Jetty 10</p>
</div>
<div class="paragraph">
<p>The most basic way of starting the Jetty standalone server is to execute the <code>start.jar</code> from a base directory containing
the configuration of jetty:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>[] mkdir /var/jetty-base
[] cd /var/jetty-base
[] java -jar $JETTY_HOME/start.jar
ERROR : No enabled jetty modules found!
...</pre>
</div>
</div>
<div class="paragraph">
<p>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. You use start.jar to configure the modules:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>[] java -jar $JETTY_HOME/start.jar --add-module=http
...
INFO : http initialized in ${jetty.base}/start.d/http.ini
...
[] java -jar $JETTY_HOME/start.jar
2020-12-02 09:31:45.563:INFO :oejs.Server:main: jetty-10.0.0; built: 2020-11-30T14:38:10.953Z; git: cac070fdb134df192252e99653d99d7c3fb91b87; jvm 15.0.1+9
2020-12-02 09:31:45.601:INFO :oejs.AbstractConnector:main: Started ServerConnector@3eb7fc54{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2020-12-02 09:31:45.615:INFO :oejs.Server:main: Started Server@55a561cf{STARTING}[10.0.0,sto=5000] @760ms</pre>
</div>
</div>
<div class="paragraph">
<p>At its most basic, you configure Jetty from two elements:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>A set of libraries and directories that make up the server classpath.</p>
</li>
<li>
<p>A set of Jetty XML configuration files (IoC style) that establish how to build the Jetty server and its components.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>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).</p>
</div>
<div class="paragraph">
<p>Jetty Startup Features include:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>A separation of the Jetty distribution binaries in <code>${jetty.home}</code> and the environment specific configurations (and binaries) found in <code>${jetty.base}</code> (detailed in <a href="#startup-jetty-base-and-jetty-home">Managing Jetty Base and Jetty Home.</a>)</p>
</li>
<li>
<p>You can enable a set of libraries and XML configuration files via the newly introduced <a href="#startup-modules">module system.</a></p>
</li>
<li>
<p>All of the pre-built XML configuration files shipped in Jetty are now parameterized with properties that you can specify in your <code>${jetty.base}/start.ini</code> (demonstrated in <a href="#quick-start-configure">Quick Start Configuration</a>).</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>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.</p>
</div>
<div class="paragraph">
<p>For example, if you use the <code>${jetty.base}</code> 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 <code>${jetty.base}</code>, and in the future, just upgrade your <code>${jetty.home}</code> directory with a new Jetty distribution.</p>
</div>
<div class="sect3">
<h4 id="executing-startjar"><a class="anchor" href="#executing-startjar"></a><a class="link" href="#executing-startjar">Executing start.jar</a></h4>
<div class="paragraph">
<p>When executed <code>start.jar</code> performs the following actions:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Loads and parses all INIs found in <code>${jetty.base}/start.d/*.ini</code> as command line arguments.</p>
</li>
<li>
<p>Loads and parses <code>${jetty.base}/start.ini</code> as command line arguments.</p>
<div class="ulist">
<ul>
<li>
<p>Please see <a href="#start-vs-startd">Start.ini vs. Start.d</a> for more information on the difference between these.</p>
</li>
</ul>
</div>
</li>
<li>
<p>Parses actual command line arguments used to execute <code>start.jar</code> itself.</p>
</li>
<li>
<p>Resolves any XML configuration files, modules, and libraries using base vs. home resolution steps:</p>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Checks whether file exists as relative reference to <code>${jetty.base}.</code></p>
</li>
<li>
<p>Checks whether file exists as relative reference to <code>${jetty.home}.</code></p>
</li>
<li>
<p>Uses default behavior of <code>java.io.File</code> (Relative to <code>System.getProperty</code> ("user.dir") and then as absolute file system path).</p>
</li>
</ol>
</div>
</li>
<li>
<p>Loads any dependent modules (merges XXNK, library, and properties results with active command line).</p>
</li>
<li>
<p>Builds out server classpath.</p>
</li>
<li>
<p>Determines run mode as one of:</p>
<div class="ulist">
<ul>
<li>
<p>Shows informational command line options and exit.</p>
</li>
<li>
<p>Executes Jetty normally, waits for Jetty to stop.</p>
</li>
<li>
<p>Executes a forked JVM to run Jetty in, waits for forked JVM to exit.</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="og-start-jar-command-line-options"><a class="anchor" href="#og-start-jar-command-line-options"></a><a class="link" href="#og-start-jar-command-line-options">start.jar Command Line Options</a></h4>
<div class="sect4">
<h5 id="og-command-line-options"><a class="anchor" href="#og-command-line-options"></a><a class="link" href="#og-command-line-options">Command Line Options</a></h5>
<div class="dlist">
<dl>
<dt class="hdlist1">--help</dt>
<dd>
<p>Obtains the current list of command line options and some basic usage help.</p>
</dd>
<dt class="hdlist1">--version</dt>
<dd>
<p>Shows the list of server classpath entries, and prints version information found for each entry.</p>
</dd>
<dt class="hdlist1">--list-classpath</dt>
<dd>
<p>Similar to --version, shows the server classpath.</p>
</dd>
<dt class="hdlist1">--list-config</dt>
<dd>
<p>Lists the resolved configuration that will start Jetty.</p>
<div class="ulist">
<ul>
<li>
<p>Java environment</p>
</li>
<li>
<p>Jetty environment</p>
</li>
<li>
<p>JVM arguments</p>
</li>
<li>
<p>Properties</p>
</li>
<li>
<p>Server classpath</p>
</li>
<li>
<p>Server XML configuration files</p>
</li>
</ul>
</div>
</dd>
<dt class="hdlist1">--dry-run</dt>
<dd>
<p>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:</p>
</dd>
</dl>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar start.jar --dry-run &gt; jetty.sh
$ . jetty.sh</pre>
</div>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">--dry-run=&lt;parts&gt;</dt>
<dd>
<p>Print specific parts of the command line. The parts are a comma separated list of:</p>
<div class="ulist">
<ul>
<li>
<p>"java" - the JVM to run</p>
</li>
<li>
<p>"opts" - the JVM options (eg -D and -X flags)</p>
</li>
<li>
<p>"path" - the JVM class path or JPMS modules options</p>
</li>
<li>
<p>"main" - the main class to run</p>
</li>
<li>
<p>"args" - the arguments passed to the main class</p>
</li>
</ul>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>It is possible to decompose the start command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ 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</pre>
</div>
</div>
<div class="paragraph">
<p>Alternatively to create an args file for java:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar start.jar --dry-run=opts,path,main,args &gt; /tmp/args
$ java @/tmp/args</pre>
</div>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">--exec</dt>
<dd>
<p>Forces the start to use a forked instance of java to run Jetty.
Some modules include <code>--exec</code> in order to set java command line options.
Some start options, such as <code>--jpms</code> also imply <code>--exec</code></p>
</dd>
<dt class="hdlist1">--exec-properties=&lt;filename&gt;</dt>
<dd>
<p>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.</p>
</dd>
<dt class="hdlist1">--commands=&lt;filename&gt;</dt>
<dd>
<p>Instructs <code>start.jar</code> to use each line of the specified file as arguments on the command line.</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="og-debug-and-start-logging"><a class="anchor" href="#og-debug-and-start-logging"></a><a class="link" href="#og-debug-and-start-logging">Debug and Start Logging</a></h5>
<div class="dlist">
<dl>
<dt class="hdlist1">--debug</dt>
<dd>
<p>Enables debugging output of the startup procedure.</p>
<div class="paragraph">
<p><strong>Note</strong>: This does not set up debug logging for Jetty itself.
For information on logging, please see the section on <a href="#configuring-jetty-logging">Configuring Jetty Logging.</a>]</p>
</div>
</dd>
<dt class="hdlist1">--start-log-file=&lt;filename&gt;</dt>
<dd>
<p>Sends all startup output to the filename specified.
Filename is relative to <code>${jetty.base}</code>.
This is useful for capturing startup issues where the Jetty-specific logger has not yet kicked in due to a possible startup configuration error.</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="og-module-management"><a class="anchor" href="#og-module-management"></a><a class="link" href="#og-module-management">Module Management</a></h5>
<div class="dlist">
<dl>
<dt class="hdlist1">--list-modules</dt>
<dd>
<p>Lists all the modules defined by the system.
Looks for module files using the <a href="#startup-base-and-home">normal <code>${jetty.base}</code> and <code>${jetty.home}</code> resolution logic</a>.
Also lists enabled state based on information present on the command line, and all active startup INI files.</p>
</dd>
<dt class="hdlist1">--list-modules=&lt;tag&gt;(,&lt;tag&gt;)*</dt>
<dd>
<p>List modules by <a href="#startup-modules">tag.</a>
Use '*' for all tags.
Prefix a tag with '-' to exclude the tag.
The special tag "internal" is always excluded unless it is explicitly included.</p>
</dd>
<dt class="hdlist1">--list-all-modules</dt>
<dd>
<p>List all modules.</p>
</dd>
<dt class="hdlist1">--module=&lt;name&gt;,(&lt;name&gt;)*</dt>
<dd>
<p>Enables one or more modules by name (use <code>--list-modules</code> to 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 <code>${jetty.base}/start.ini.</code></p>
</dd>
<dt class="hdlist1">--add-to-start=&lt;name&gt;,(&lt;name&gt;)*</dt>
<dd>
<p>Enables a module by appending lines to the <code>${jetty.base}/start.ini</code> file.
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 <code>-add-to-start</code> command, such as in the following example:</p>
<div class="listingblock">
<div class="content">
<pre>$ java -jar start.jar --add-to-start=http jetty.http.port=8379 jetty.http.host=1.2.3.4</pre>
</div>
</div>
<div class="paragraph">
<p>Doing this will uncomment the property in the associated .ini file and set it to the value specified.</p>
</div>
</dd>
<dt class="hdlist1">--update-ini</dt>
<dd>
<p>Used to update a specified property or properties that exist in an existing .ini file.
Jetty scans the command line, <code>${jetty.base}</code> and <code>${jetty.home}</code> for .ini files that have the specified property and update it accordingly.</p>
<div class="listingblock">
<div class="content">
<pre>[my-base]$ java -jar /path/to/jetty-home/start.jar --update-ini jetty.http.port=8417
ConfigSource &lt;command-line&gt;
ConfigSource ${jetty.base}
INFO : http property updated jetty.http.port=8417
INFO : http updated ${jetty.base}/start.d/http.ini
ConfigSource ${jetty.home}</pre>
</div>
</div>
</dd>
<dt class="hdlist1">--create-startd</dt>
<dd>
<p>Creates a <code>${jetty.base}/start.d/</code> directory.
If a <code>${jetty.base}/start.ini</code> file already exists, it is copied to the <code>${jetty.base}/start.d</code> directory.</p>
</dd>
</dl>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>With respect to <code>start.ini</code> and <code>start.d/<strong>.ini</code> files, only *one</strong> of these methods should be implemented.
Mixing a <code>start.ini</code> with module specific ini files in the <code>{$jetty.base}/start.d</code> directory can lead to server issues unless great care is taken.
Please see <a href="#start-vs-startd">Start.ini vs. Start.d</a> for more information.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">--write-module-graph=&lt;filename&gt;</dt>
<dd>
<p>Advanced feature: Creates a graphviz <a href="http://graphviz.org/content/dot-language">dot file</a> of the module graph as it exists for the active <code>${jetty.base}</code>.</p>
<div class="listingblock">
<div class="content">
<pre># 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</pre>
</div>
</div>
<div class="paragraph">
<p>See <a href="http://graphviz.org/">graphviz.org</a> for details on how to post-process this dotty file into the output best suited for your needs.</p>
</div>
</dd>
<dt class="hdlist1">--create-files</dt>
<dd>
<p>Create any missing files that are required by initialized modules.
This may download a file from the network if the module provides a URL.</p>
</dd>
<dt class="hdlist1">--skip-file-validation=&lt;modulename&gt;(,&lt;modulename)*</dt>
<dd>
<p>Disable the [files] section validation of content in the <code>${jetty.base}</code> directory for a specific module.
Useful for modules that have downloadable content that is being overridden with alternatives in the <code>${jetty.base}`</code> directory.</p>
</dd>
</dl>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<i class="fa icon-caution" title="Caution"></i>
</td>
<td class="content">
This advanced option is for administrators that fully understand the configuration of their <code>${jetty.base}</code> and are willing to forego some of the safety checks built into the jetty-start mechanism.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">--approve-all-licenses</dt>
<dd>
<p>Approve all license questions.
Useful for enabling modules from a script that does not require user interaction.</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="og-startup-shutdown-command-line"><a class="anchor" href="#og-startup-shutdown-command-line"></a><a class="link" href="#og-startup-shutdown-command-line">Startup / Shutdown Command Line</a></h5>
<div class="dlist">
<dl>
<dt class="hdlist1">--stop</dt>
<dd>
<p>Sends a stop signal to the running Jetty instance.</p>
<div class="paragraph">
<p>Note: The server must have been started with various stop properties for this to work.</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">STOP.PORT=&lt;number&gt;</dt>
<dd>
<p>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.</p>
<div class="paragraph">
<p>Required for <code>--stop</code> to function.</p>
</div>
</dd>
<dt class="hdlist1">STOP.KEY=&lt;alphanumeric&gt;</dt>
<dd>
<p>The passphrase defined to stop the server.</p>
<div class="paragraph">
<p>Required for <code>--stop</code> to function.</p>
</div>
</dd>
<dt class="hdlist1">STOP.WAIT=&lt;number&gt;</dt>
<dd>
<p>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.</p>
<div class="paragraph">
<p>If the time specified elapses, without a confirmation of server stop, then the <code>--stop</code> command exits with a non-zero return code.</p>
</div>
</dd>
</dl>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>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 <code>STOP.PORT</code> and <code>STOP.KEY</code> (or <code>-DSTOP.PORT=</code> and <code>-DSTOP.KEY=</code>, respectively, which will set these as system parameters) parameters as arguments to the <code>start.jar</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>&gt; java -jar ${JETTY_HOME}/start.jar STOP.PORT=1234 STOP.KEY=secretpassword</pre>
</div>
</div>
<div class="paragraph">
<p>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 <a href="#jetty-maven-plugin">jetty-maven-plugin</a>, the <a href="#jetty-ant">jetty-ant plugin</a>, or a custom class to accomplish this.
Here&#8217;s how to use the Jetty distribution, leveraging <code>start.jar</code>, to perform a stop:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>&gt; java -jar start.jar STOP.PORT=8181 STOP.KEY=abc123 --stop</pre>
</div>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
To perform a graceful shutdown of Jetty, the <code>stats</code> <a href="#startup-modules">module</a> <strong>must</strong> be enabled.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
</div>
<div class="sect4">
<h5 id="og-advanced-commands"><a class="anchor" href="#og-advanced-commands"></a><a class="link" href="#og-advanced-commands">Advanced Commands</a></h5>
<div class="dlist">
<dl>
<dt class="hdlist1">--lib=&lt;classpath&gt;</dt>
<dd>
<p>Add arbitrary classpath entries to the the server classpath.</p>
</dd>
<dt class="hdlist1">--include-jetty-dir=&lt;path&gt;</dt>
<dd>
<p>Include an extra Jetty directory to use as a source for configuration details.
This directory behaves similarly to <code>${jetty.base}</code> but sits at a layer between <code>${jetty.base}</code> and <code>${jetty.home}</code>.
This allows for some complex hierarchies of configuration details.</p>
</dd>
<dt class="hdlist1">--download=&lt;http-uri&gt;|&lt;location&gt;</dt>
<dd>
<p>If the file does not exist at the given location, download it from the given http URI.
Note: location is always relative to <code>${jetty.base}</code>.
You might need to escape the slash "\|" to use this on some environments.</p>
</dd>
<dt class="hdlist1">maven.repo.uri=[url]</dt>
<dd>
<p>The url to use to download Maven dependencies.
Default is <a href="https://repo1.maven.org/maven2/" class="bare">https://repo1.maven.org/maven2/</a>.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-shaded-start-jar"><a class="anchor" href="#og-shaded-start-jar"></a><a class="link" href="#og-shaded-start-jar">Shaded Start.jar</a></h4>
<div class="paragraph">
<p>If you have a need for a shaded version of <code>start.jar</code> (such as for Gradle), you can achieve this via a Maven dependency.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;dependency&gt;
&lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
&lt;artifactId&gt;jetty-start&lt;/artifactId&gt;
&lt;version&gt;{VERSION}&lt;/version&gt;
&lt;classifier&gt;shaded&lt;/classifier&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-start-jar-without-exec-or-forking"><a class="anchor" href="#og-start-jar-without-exec-or-forking"></a><a class="link" href="#og-start-jar-without-exec-or-forking">Start.jar without exec or forking.</a></h4>
<div class="paragraph">
<p>Some Jetty modules include the <code>--exec</code> option so that java command line options can be set.
Also some <code>start.jar</code> options (eg. <code>--jpms</code>) include an implicit <code>--exec</code>.
To start jetty without forking a new JVM instance from the start JVM, the <code>--dry-run</code> option can be used to generate a command line:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ CMD=$(java -jar start.jar --dry-run)
$ $CMD</pre>
</div>
</div>
<div class="paragraph">
<p>It is possible to decompose the start command so that it can be modified:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ 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</pre>
</div>
</div>
<div class="paragraph">
<p>Alternatively to create an args file for java:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar start.jar --dry-run=opts,path,main,args &gt; /tmp/args
$ java @/tmp/args</pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-deploy"><a class="anchor" href="#og-deploy"></a><a class="link" href="#og-deploy">Customizing Web Application Deployment</a></h3>
<div class="paragraph">
<p>Most of the times you want to be able to customize the deployment of your web applications, for example by changing the <code>contextPath</code>, or by adding JNDI entries, or by configuring virtual hosts, etc.</p>
</div>
<div class="paragraph">
<p>The customization is performed by the <a href="#og-module-deploy"><code>deploy</code> module</a> by processing <a href="#og-deploy-jetty">Jetty context XML files</a>.</p>
</div>
<div class="paragraph">
<p>The <code>deploy</code> module contains the <code>DeploymentManager</code> component that scans the <code>$JETTY_BASE/webapps</code> directory for changes, following the deployment rules described in <a href="#og-deploy-rules">this section</a>.</p>
</div>
<div class="sect3">
<h4 id="og-deploy-hot-static"><a class="anchor" href="#og-deploy-hot-static"></a><a class="link" href="#og-deploy-hot-static">Hot vs Static Deployment</a></h4>
<div class="paragraph">
<p>The <code>DeploymentManager</code> scans the <code>$JETTY_BASE/webapps</code> directory for changes every <code>N</code> seconds, where <code>N</code> is configured via the <code>jetty.deploy.scanInterval</code> property.</p>
</div>
<div class="paragraph">
<p>By default, the scan interval is <code>1</code> second, which means that <em>hot</em> deployment is enabled: if a file is added/changed/removed from the <code>$JETTY_BASE/webapps</code> directory, the <code>DeploymentManager</code> will notice the change and respectively deploy/redeploy/undeploy the web application.</p>
</div>
<div class="paragraph">
<p>Setting the scan interval to <code>0</code> means that <em>static</em> deployment is enabled, and the <code>DeploymentManager</code> will not scan the <code>$JETTY_BASE/webapps</code> directory for changes.
This means that to deploy/redeploy/undeploy a web application you will need to stop and restart Jetty.</p>
</div>
<div class="paragraph">
<p>The following command line disables <em>hot</em> deployment by specifying the <code>jetty.deploy.scanInterval</code> property on the command line, and therefore only for this particular run:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar jetty.deploy.scanInterval=0</pre>
</div>
</div>
<div class="paragraph">
<p>To make <em>static</em> deployment persistent, you need to edit the <code>deploy</code> module configuration file, <code>$JETTY_BASE/start.d/deploy.ini</code>, uncomment the module property <code>jetty.deploy.scanInterval</code> and change its value to <code>0</code>:</p>
</div>
<div class="listingblock">
<div class="title">deploy.ini</div>
<div class="content">
<pre class="highlight"><code>--module=deploy
<mark>jetty.deploy.scanInterval=0</mark>
...</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-deploy-rules"><a class="anchor" href="#og-deploy-rules"></a><a class="link" href="#og-deploy-rules">Deployment Rules</a></h4>
<div class="paragraph">
<p><em>Adding</em> a <code>*.war</code> file, a <code>*.war</code> directory, a Jetty context XML file or a normal directory to <code>$JETTY_BASE/webapps</code> causes the <code>DeploymentManager</code> to deploy the new web application.</p>
</div>
<div class="paragraph">
<p><em>Updating</em> a <code>*.war</code> file or a Jetty context XML file causes the <code>DeploymentManager</code> to redeploy the web application, which means that the Jetty context component representing the web application is stopped, then reconfigured, and then restarted.</p>
</div>
<div class="paragraph">
<p><em>Removing</em> a <code>*.war</code> file, a <code>*.war</code> directory, a Jetty context XML file or a normal directory from <code>$JETTY_BASE/webapps</code> causes the <code>DeploymentManager</code> to undeploy the web application, which means that the Jetty context component representing the web application is stopped and removed from the Jetty server.</p>
</div>
<div class="paragraph">
<p>When a file or directory is added to <code>$JETTY_BASE/webapps</code>, the <code>DeploymentManager</code> derives the web application <code>contextPath</code> from the file or directory name, with the following rules:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>If the directory name is, for example, <code>mywebapp/</code>, it is deployed as a standard web application if it contains a <code>WEB-INF/</code> subdirectory, otherwise it is deployed as a web application of static content.
The <code>contextPath</code> would be <code>/mywebapp</code> (that is, the web application is reachable at <code>http://localhost:8080/mywebapp/</code>).</p>
</li>
<li>
<p>If the directory name is <code>ROOT</code>, case insensitive, the <code>contextPath</code> is <code>/</code> (that is, the web application is reachable at <code>http://localhost:8080/</code>).</p>
</li>
<li>
<p>If the directory name ends with <code>.d</code>, for example <code>config.d/</code>, it is ignored, although it may be referenced to configure other web applications (for example to store common files).</p>
</li>
<li>
<p>If the <code>*.war</code> file name is, for example, <code>mywebapp.war</code>, it is deployed as a standard web application with the context path <code>/mywebapp</code> (that is, the web application is reachable at <code>http://localhost:8080/mywebapp/</code>).</p>
</li>
<li>
<p>If the file name is <code>ROOT.war</code>, case insensitive, the <code>contextPath</code> is <code>/</code> (that is, the web application is reachable at <code>http://localhost:8080/</code>).</p>
</li>
<li>
<p>If both the <code>mywebapp.war</code> file and the <code>mywebapp/</code> directory exist, only the file is deployed.
This allows the directory with the same name to be the <code>*.war</code> file unpack location and avoid that the web application is deployed twice.</p>
</li>
<li>
<p>A <a href="#og-deploy-jetty">Jetty context XML file</a> named <code>mywebapp.xml</code> is deployed as a web application by processing the directives contained in the XML file itself, which must set the <code>contextPath</code>.</p>
</li>
<li>
<p>If both <code>mywebapp.xml</code> and <code>mywebapp.war</code> exist, only the XML file is deployed.
This allows the XML file to reference the <code>*.war</code> file and avoid that the web application is deployed twice.</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="og-deploy-jetty"><a class="anchor" href="#og-deploy-jetty"></a><a class="link" href="#og-deploy-jetty">Deploying Jetty Context XML Files</a></h4>
<div class="paragraph">
<p>A Jetty context XML file is a <a href="#og-xml">Jetty XML file</a> that allows you to customize the deployment of web applications.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Recall that the <code>DeploymentManager</code> component of the Jetty <code>deploy</code> module <a href="#og-deploy-rules">gives priority</a> to Jetty context XML files over <code>*.war</code> files or directories.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To deploy a web application using a Jetty context XML file, simply place the file in the <code>$JETTY_BASE/webapps</code> directory.</p>
</div>
<div class="paragraph">
<p>A simple Jetty context XML file, for example named <code>wiki.xml</code> is the following:</p>
</div>
<div class="listingblock">
<div class="title">wiki.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Set name="contextPath"&gt;/wiki&lt;/Set&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;Set name="war"&gt;/opt/myapps/myapp.war&lt;/Set&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Configures a <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a>, which is the Jetty component that represents a standard Servlet web application.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Specifies the web application <code>contextPath</code>, which may be different from the <code>*.war</code> file name.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Specifies the file system path of the <code>*.war</code> file.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The <code>$JETTY_BASE</code> directory would look like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$JETTY_BASE
├── resources
│ └── jetty-logging.properties
├── start.d
│ ├── deploy.ini
│ └── http.ini
└── webapps
└── wiki.xml</pre>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
The <code>*.war</code> file may be placed anywhere in the file system and does not need to be placed in the <code>$JETTY_BASE/webapps</code> directory.
</td>
</tr>
</table>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
If you place both the Jetty context XML file <em>and</em> the <code>*.war</code> file in the <code>$JETTY_BASE/webapps</code> directory, remember that they must have the same file name, for example <code>wiki.xml</code> and <code>wiki.war</code>, so that the <code>DeploymentManager</code> deploys the web application only once using the Jetty context XML file (and not the <code>*.war</code> file).
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>You can use the features of <a href="#og-xml">Jetty XML files</a> to avoid to hard-code file system paths or other configurations in your Jetty context XML files, for example by using system properties:</p>
</div>
<div class="listingblock">
<div class="title">wiki.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/wiki&lt;/Set&gt;
&lt;Set name="war"&gt;&lt;SystemProperty name="myapps.dir"/&gt;/myapp.war&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note how the <code>*.war</code> file path is now obtained by resolving the system property <code>myapps.dir</code> that you can specify on the command line when you start Jetty:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar -Dmyapps.dir=/opt/myapps</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-deploy-jndi"><a class="anchor" href="#og-deploy-jndi"></a><a class="link" href="#og-deploy-jndi">Configuring JNDI Entries</a></h4>
<div class="paragraph">
<p>A web application may <em>reference</em> a JNDI entry, such as a JDBC <code>DataSource</code> from the web application <code>web.xml</code> file.
The JNDI entry must be <em>defined</em> in a <a href="#og-jndi-xml">Jetty XML file</a>, for example a context XML like so:</p>
</div>
<div class="listingblock">
<div class="title">mywebapp.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/mywebapp&lt;/Set&gt;
&lt;Set name="war"&gt;/opt/webapps/mywebapp.war&lt;/Set&gt;
<mark>&nbsp;&nbsp;&lt;New class="org.eclipse.jetty.plus.jndi.Resource"&gt;
&lt;Arg&gt;&lt;Ref refid="wac"/&gt;&lt;/Arg&gt;
&lt;Arg&gt;jdbc/myds&lt;/Arg&gt;
&lt;Arg&gt;
&lt;New class="com.mysql.cj.jdbc.MysqlConnectionPoolDataSource"&gt;
&lt;Set name="url"&gt;jdbc:mysql://localhost:3306/databasename&lt;/Set&gt;
&lt;Set name="user"&gt;user&lt;/Set&gt;
&lt;Set name="password"&gt;password&lt;/Set&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;/New&gt;</mark>
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>For more information and examples on how to use JNDI in Jetty, refer to the <a href="#og-jndi">JNDI</a> feature section.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Class <code>com.mysql.cj.jdbc.MysqlConnectionPoolDataSource</code> is present in the MySQL JDBC driver file, <code>mysql-connector-java-&lt;version&gt;.jar</code>, which must be available on the server&#8217;s classpath .</p>
</div>
<div class="paragraph">
<p>If the class is instead present <em>within</em> the web application, then the JNDI entry must be declared in a <code>WEB-INF/jetty-env.xml</code> file - see the <a href="#og-jndi">JNDI</a> feature section for more information and examples.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="og-deploy-virtual-hosts"><a class="anchor" href="#og-deploy-virtual-hosts"></a><a class="link" href="#og-deploy-virtual-hosts">Configuring Virtual Hosts</a></h4>
<div class="paragraph">
<p>A <em>virtual host</em> 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.</p>
</div>
<div class="paragraph">
<p>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.</p>
</div>
<div class="paragraph">
<p>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 <code>http://domain.biz/</code>, and the second web application available at <code>http://hobby.net/</code>.</p>
</div>
<div class="paragraph">
<p>Another typical case is when you want to use different subdomains for different web application, for example a project website is at <code>http://project.org/</code> and the project documentation is at <code>http://docs.project.org</code>.</p>
</div>
<div class="paragraph">
<p>Virtual hosts can be used with any context that is a subclass of <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/server/handler/ContextHandler.html">ContextHandler</a>.</p>
</div>
<div class="sect4">
<h5 id="og-deploy-virtual-hosts-names"><a class="anchor" href="#og-deploy-virtual-hosts-names"></a><a class="link" href="#og-deploy-virtual-hosts-names">Virtual Host Names</a></h5>
<div class="paragraph">
<p>Jetty supports the following variants to be specified as virtual host names:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>www.hostname.com</code></dt>
<dd>
<p>A fully qualified domain name. It is important to list all variants as a site may receive traffic for both <code>www.hostname.com</code> and <code>hostname.com</code>.</p>
</dd>
<dt class="hdlist1"><code>*.hostname.com</code></dt>
<dd>
<p>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.</p>
</dd>
<dt class="hdlist1"><code>10.0.0.2</code></dt>
<dd>
<p>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.</p>
</dd>
<dt class="hdlist1"><code>@ConnectorName</code></dt>
<dd>
<p>A Jetty <code>ServerConnector</code> name to indicate that a web application should handle requests received on the <code>ServerConnector</code> with that name, and therefore received on a specific IP port.
A <code>ServerConnector</code> name can be set via <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/server/AbstractConnector.html#setName(java.lang.String)" class="bare">http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/server/AbstractConnector.html#setName(java.lang.String)</a>.</p>
</dd>
<dt class="hdlist1"><code>www.√integral.com</code></dt>
<dd>
<p>Non-ASCII and <a href="https://en.wikipedia.org/wiki/Internationalized_domain_name">IDN</a> domain names can be set as virtual hosts using <a href="https://en.wikipedia.org/wiki/Punycode">Puny Code</a> equivalents that may be obtained from a <a href="https://www.punycoder.com/">Punycode/IDN converters</a>.
For example if the non-ASCII domain name <code>www.√integral.com</code> is given to a browser, then the browser will make a request that uses the domain name <code>www.xn&#8212;&#8203;integral-7g7d.com</code>, which is the name that should be added as the virtual host name.</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="og-deploy-virtual-hosts-config"><a class="anchor" href="#og-deploy-virtual-hosts-config"></a><a class="link" href="#og-deploy-virtual-hosts-config">Virtual Hosts Configuration</a></h5>
<div class="paragraph">
<p>If you have a web application <code>mywebapp.war</code> you can configure its virtual hosts in this way:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/mywebapp&lt;/Set&gt;
&lt;Set name="war"&gt;/opt/webapps/mywebapp.war&lt;/Set&gt;
&lt;Set name="virtualHosts"&gt;
&lt;Array type="java.lang.String"&gt;
&lt;Item&gt;mywebapp.com&lt;/Item&gt;
&lt;Item&gt;www.mywebapp.com&lt;/Item&gt;
&lt;Item&gt;mywebapp.net&lt;/Item&gt;
&lt;Item&gt;www.mywebapp.net&lt;/Item&gt;
&lt;/Array&gt;
&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Your web application will be available at:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>http://mywebapp.com/mywebapp</code></p>
</li>
<li>
<p><code>http://www.mywebapp.com/mywebapp</code></p>
</li>
<li>
<p><code>http://mywebapp.net/mywebapp</code></p>
</li>
<li>
<p><code>http://www.mywebapp.net/mywebapp</code></p>
</li>
</ul>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>You configured the <code>contextPath</code> of your web application to <code>/mywebapp</code>.</p>
</div>
<div class="paragraph">
<p>As such, a request to <code>http://mywebapp.com/other</code> will not match your web application because the <code>contextPath</code> does not match.</p>
</div>
<div class="paragraph">
<p>Likewise, a request to <code>http://other.com/mywebapp</code> will not match your web application because the virtual host does not match.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="og-deploy-virtual-hosts-same-context"><a class="anchor" href="#og-deploy-virtual-hosts-same-context"></a><a class="link" href="#og-deploy-virtual-hosts-same-context">Same Context Path, Different Virtual Hosts</a></h5>
<div class="paragraph">
<p>If you want to deploy different web applications to the same context path, typically the root context path <code>/</code>, you must use virtual hosts to differentiate among web applications.</p>
</div>
<div class="paragraph">
<p>You have <code>domain.war</code> that you want to deploy at <code>http://domain.biz/</code> and <code>hobby.war</code> that you want to deploy at <code>http://hobby.net</code>.</p>
</div>
<div class="paragraph">
<p>To achieve this, you simply use the same context path of <code>/</code> for each of your webapps, while specifying different virtual hosts for each of your webapps:</p>
</div>
<div class="listingblock">
<div class="title">domain.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/&lt;/Set&gt;
&lt;Set name="war"&gt;/opt/webapps/domain.war&lt;/Set&gt;
&lt;Set name="virtualHosts"&gt;
&lt;Array type="java.lang.String"&gt;
&lt;Item&gt;domain.biz&lt;/Item&gt;
&lt;/Array&gt;
&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">hobby.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/&lt;/Set&gt;
&lt;Set name="war"&gt;/opt/webapps/hobby.war&lt;/Set&gt;
&lt;Set name="virtualHosts"&gt;
&lt;Array type="java.lang.String"&gt;
&lt;Item&gt;hobby.net&lt;/Item&gt;
&lt;/Array&gt;
&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-deploy-virtual-hosts-port"><a class="anchor" href="#og-deploy-virtual-hosts-port"></a><a class="link" href="#og-deploy-virtual-hosts-port">Different Port, Different Web Application</a></h5>
<div class="paragraph">
<p>Sometimes it is required to serve different web applications from different IP ports, and therefore from different <code>ServerConnector</code>s.</p>
</div>
<div class="paragraph">
<p>For example, you want requests to <code>http://localhost:8080/</code> to be served by one web application, but requests to <code>http://localhost:9090/</code> to be served by another web application.</p>
</div>
<div class="paragraph">
<p>This configuration may be useful when Jetty sits behind a load balancer.</p>
</div>
<div class="paragraph">
<p>In this case, you want to <a href="#og-protocols">configure multiple connectors</a>, each with a different name, and then reference the connector name in the web application virtual host configuration:</p>
</div>
<div class="listingblock">
<div class="title">domain.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/&lt;/Set&gt;
&lt;Set name="war"&gt;/opt/webapps/domain.war&lt;/Set&gt;
&lt;Set name="virtualHosts"&gt;
&lt;Array type="java.lang.String"&gt;
&lt;Item&gt;@port8080&lt;/Item&gt;
&lt;/Array&gt;
&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="listingblock">
<div class="title">hobby.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/&lt;/Set&gt;
&lt;Set name="war"&gt;/opt/webapps/hobby.war&lt;/Set&gt;
&lt;Set name="virtualHosts"&gt;
&lt;Array type="java.lang.String"&gt;
&lt;Item&gt;@port9090&lt;/Item&gt;
&lt;/Array&gt;
&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Web application <code>domain.war</code> has a virtual host of <code>@port8080</code>, where <code>port8080</code> is the name of a Jetty connector.</p>
</div>
<div class="paragraph">
<p>Likewise, web application <code>hobby.war</code> has a virtual host of <code>@port9090</code>, where <code>port9090</code> is the name of another Jetty connector.</p>
</div>
<div class="paragraph">
<p>See <a href="#og-protocols">this section</a> for further information about how to configure connectors.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-deploy-extract-war"><a class="anchor" href="#og-deploy-extract-war"></a><a class="link" href="#og-deploy-extract-war">Configuring <code>*.war</code> File Extraction</a></h4>
<div class="paragraph">
<p>By default, <code>*.war</code> 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 <code>*.war</code> file, for performance reasons.</p>
</div>
<div class="paragraph">
<p>If you do not want Jetty to extract the <code>*.war</code> files, you can disable this feature, for example:</p>
</div>
<div class="listingblock">
<div class="title">mywebapp.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/mywebapp&lt;/Set&gt;
&lt;Set name="war"&gt;/opt/webapps/mywebapp.war&lt;/Set&gt;
&lt;Set name="extractWAR"&gt;false&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-deploy-jetty-override-web-xml"><a class="anchor" href="#og-deploy-jetty-override-web-xml"></a><a class="link" href="#og-deploy-jetty-override-web-xml">Overriding <code>web.xml</code></a></h4>
<div class="paragraph">
<p>You can configure an additional <code>web.xml</code> that complements the <code>web.xml</code> file that is present in the web application <code>*.war</code> file.
This additional <code>web.xml</code> is processed <em>after</em> the <code>*.war</code> file <code>web.xml</code>.
This allows you to add host specific configuration or server specific configuration without having to extract the web application <code>web.xml</code>, modify it, and repackage it in the <code>*.war</code> file.</p>
</div>
<div class="listingblock">
<div class="title">mywebapp.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;/mywebapp&lt;/Set&gt;
&lt;Set name="war"&gt;/opt/webapps/mywebapp.war&lt;/Set&gt;
&lt;Set name="overrideDescriptor"&gt;/opt/webapps/mywebapp-web.xml&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The format of the additional <code>web.xml</code> is exactly the same as a standard <code>web.xml</code> file, for example:</p>
</div>
<div class="listingblock">
<div class="title">mywebapp-web.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;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"&gt;
&lt;servlet&gt;
&lt;servlet-name&gt;my-servlet&lt;/servlet-name&gt;
&lt;init-param&gt;
&lt;param-name&gt;host&lt;/param-name&gt;
&lt;param-value&gt;192.168.0.13&lt;/param-value&gt;
&lt;/init-param&gt;
&lt;/servlet&gt;
&lt;/web-app&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>In the example above, you configured the <code>my-servlet</code> Servlet (defined in the web application <code>web.xml</code>), adding a host specific <code>init-param</code> with the IP address of the host.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-deploy-init-params"><a class="anchor" href="#og-deploy-init-params"></a><a class="link" href="#og-deploy-init-params">Configuring <code>init-param</code>s</a></h4>
<div class="paragraph">
<p>TODO</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-protocols"><a class="anchor" href="#og-protocols"></a><a class="link" href="#og-protocols">Configuring Eclipse Jetty Connectors and Protocols</a></h3>
<div class="paragraph">
<p>Connectors are the network components through which Jetty accepts incoming network connections.</p>
</div>
<div class="paragraph">
<p>Each connector listens on a network port and can be configured with <code>ConnectionFactory</code> components that <em>understand</em> one or more network protocols.</p>
</div>
<div class="paragraph">
<p>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 <code>HttpServletRequest</code> object) that are then processed by applications.
Conversely, an abstract object (for example an <code>HttpServletResponse</code>) is converted into the correspondent outgoing network bytes (the bytes that represent an HTTP/1.1 response).</p>
</div>
<div class="paragraph">
<p>Like other Jetty components, connectors are enabled and configured by enabling and configuring the correspondent Jetty module.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
Recall that you must always issue the commands to enable Jetty modules from within the <code>$JETTY_BASE</code> directory, and that the Jetty module configuration files are in the <code>$JETTY_BASE/start.d/</code> directory.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>You can obtain the list of connector-related modules in this way:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --list-modules=connector</pre>
</div>
</div>
<div class="sect3">
<h4 id="og-protocols-http"><a class="anchor" href="#og-protocols-http"></a><a class="link" href="#og-protocols-http">Configuring Clear-Text HTTP/1.1</a></h4>
<div class="paragraph">
<p>Clear text HTTP/1.1 is enabled with the <code>http</code> Jetty module with the following command (issued from within the <code>$JETTY_BASE</code> directory):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=http</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>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</pre>
</div>
</div>
<div class="paragraph">
<p>After having enabled the <code>http</code> module, the <code>$JETTY_BASE</code> directory looks like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>JETTY_BASE
├── resources
│ └── jetty-logging.properties
└── start.d
└── <mark>http.ini</mark></code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>http.ini</code> file is the file that you want to edit to configure network and protocol parameters&#8201;&#8212;&#8201;for more details see <a href="#og-module-http">this section</a>.</p>
</div>
<div class="paragraph">
<p>Note that the <code>http</code> Jetty module depends on the <code>server</code> Jetty module.</p>
</div>
<div class="paragraph">
<p>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 <code>server</code> module configuration file.</p>
</div>
<div class="paragraph">
<p>You can force the creation of the <code>server.ini</code> file via:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=server</pre>
</div>
</div>
<div class="paragraph">
<p>Now the <code>$JETTY_BASE</code> directory looks like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>JETTY_BASE
├── resources
│ └── jetty-logging.properties
└── start.d
├── http.ini
└── server.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now you can edit the <code>server.ini</code> file&#8201;&#8212;&#8201;for more details see <a href="#og-module-server">this section</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-protocols-https"><a class="anchor" href="#og-protocols-https"></a><a class="link" href="#og-protocols-https">Configuring Secure HTTP/1.1</a></h4>
<div class="paragraph">
<p>Secure HTTP/1.1 is enabled with both the <code>ssl</code> and <code>https</code> Jetty modules with the following command (issued from within the <code>$JETTY_BASE</code> directory):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-modules=ssl,https</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>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</pre>
</div>
</div>
<div class="paragraph">
<p>The command above enables the <code>ssl</code> module, that provides the secure network connector, the KeyStore configuration and TLS configuration&#8201;&#8212;&#8201;for more details see <a href="#og-protocols-ssl">this section</a>.
Then, the <a href="#og-module-https"><code>https</code> module</a> adds HTTP/1.1 as the protocol secured by TLS.</p>
</div>
<div class="paragraph">
<p>The <code>$JETTY_BASE</code> directory looks like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>$JETTY_BASE
├── resources
│ └── jetty-logging.properties
└── start.d
├── https.ini
└── ssl.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note that the KeyStore file is missing, because you have to provide one with the cryptographic material you want (read <a href="#og-keystore">this section</a> to create your own KeyStore).
You need to configure these two properties by editing <code>ssl.ini</code>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>jetty.sslContext.keyStorePath</code></p>
</li>
<li>
<p><code>jetty.sslContext.keyStorePassword</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>As a quick example, you can enable the <a href="#og-module-test-keystore"><code>test-keystore</code> module</a>, that provides a KeyStore containing a self-signed certificate:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-modules=test-keystore</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>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</pre>
</div>
</div>
<div class="paragraph">
<p>The <code>$JETTY_BASE</code> directory is now:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>├── etc
│ └── <mark>test-keystore.p12</mark>
├── resources
│ └── jetty-logging.properties
└── start.d
├── https.ini
├── ssl.ini
└── test-keystore.ini</code></pre>
</div>
</div>
<div class="paragraph">
<p>Starting Jetty yields:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>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<mark>{SSL, (ssl, http/1.1)}{0.0.0.0:8443}</mark>
2020-09-22 08:40:49.828:INFO :oejs.Server:main: Started Server@2f177a4b{STARTING}[10.0.0-SNAPSHOT,sto=5000] @814ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note how Jetty is listening on port <code>8443</code> for the secure HTTP/1.1 protocol.</p>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>If you point your browser at <code>https://localhost:8443/</code> you will get a warning from the browser about a "potential security risk ahead", or that "your connection is not private", or similar message depending on the browser.</p>
</div>
<div class="paragraph">
<p>This is normal because the certificate contained in <code>test-keystore.p12</code> is self-signed&#8201;&#8212;&#8201;and as such not signed by a recognized certificate authority&#8201;&#8212;&#8201;and therefore browsers do not trust it.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="og-protocols-http2"><a class="anchor" href="#og-protocols-http2"></a><a class="link" href="#og-protocols-http2">Configuring HTTP/2</a></h4>
<div class="paragraph">
<p><a href="https://tools.ietf.org/html/rfc7540">HTTP/2</a> 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.</p>
</div>
<div class="paragraph">
<p>Because of these fundamental differences, a client and a server need to <em>negotiate</em> what version of the HTTP protocol they speak, based on what versions each side supports.</p>
</div>
<div class="paragraph">
<p>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.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
Browsers only support secure HTTP/2.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The protocol negotiation is performed by the <a href="https://tools.ietf.org/html/rfc7301">ALPN TLS extension</a>: the client advertises the list of protocols it can speak, and the server communicates to the client the protocol chosen by the server.</p>
</div>
<div class="paragraph">
<p>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:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="diag-e2488cc783b3434076c5a44ee7f19a2b.png" alt="Diagram" width="384" height="423">
</div>
</div>
<div class="paragraph">
<p>Nowadays, it&#8217;s common that both clients and servers support HTTP/2, so servers prefer HTTP/2 as the protocol to speak:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="diag-8a7fb4bb9c84453a4bf01a24558e8026.png" alt="Diagram" width="421" height="423">
</div>
</div>
<div class="paragraph">
<p>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.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-secure-vs-clear-text-http2"><a class="anchor" href="#og-secure-vs-clear-text-http2"></a><a class="link" href="#og-secure-vs-clear-text-http2">Secure vs Clear-Text HTTP/2</a></h4>
<div class="paragraph">
<p>Deciding whether you want to configure Jetty with <a href="#og-protocols-http2s">secure HTTP/2</a> or <a href="#og-protocols-http2c">clear-text HTTP/2</a> depends on your use case.</p>
</div>
<div class="paragraph">
<p>You want to configure secure HTTP/2 when Jetty is exposed directly to browsers, because browsers only support secure HTTP/2.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="diag-7387dfbb6f9fb9cfa951a697aca488a8.png" alt="Diagram" width="140" height="290">
</div>
</div>
<div class="paragraph">
<p>You may configure clear-text HTTP/2 (mostly for performance reasons) if you offload TLS at a load balancer (for example, <a href="https://haproxy.org/">HAProxy</a>) or at a reverse proxy (for example, <a href="https://nginx.org/">nginx</a>).</p>
</div>
<div class="imageblock">
<div class="content">
<img src="diag-70817cc5c7137abc9759cdcd3edbb658.png" alt="Diagram" width="225" height="403">
</div>
</div>
<div class="paragraph">
<p>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).</p>
</div>
<div class="imageblock">
<div class="content">
<img src="diag-2830e38460d606111888c5df2a645163.png" alt="Diagram" width="336" height="629">
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-protocols-http2s"><a class="anchor" href="#og-protocols-http2s"></a><a class="link" href="#og-protocols-http2s">Configuring Secure HTTP/2</a></h4>
<div class="paragraph">
<p>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.</p>
</div>
<div class="paragraph">
<p>You need to enable:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>the <code>ssl</code> Jetty module, which provides the secure connector and the KeyStore and TLS configuration</p>
</li>
<li>
<p>the <code>http2</code> Jetty module, which adds ALPN handling and adds the HTTP/2 protocol to the secured connector</p>
</li>
<li>
<p>optionally, the <code>https</code> Jetty module, which adds the HTTP/1.1 protocol to the secured connector</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Use the following command (issued from within the <code>$JETTY_BASE</code> directory):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-modules=ssl,http2,https</pre>
</div>
</div>
<div class="paragraph">
<p>As when enabling the <code>https</code> Jetty module, you need a valid KeyStore (read <a href="#og-keystore">this section</a> to create your own KeyStore).</p>
</div>
<div class="paragraph">
<p>As a quick example, you can enable the <a href="#og-module-test-keystore"><code>test-keystore</code> module</a>, that provides a KeyStore containing a self-signed certificate:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-modules=test-keystore</pre>
</div>
</div>
<div class="paragraph">
<p>Starting Jetty yields:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>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<mark>{SSL, (ssl, alpn, h2, http/1.1)}{0.0.0.0:8443}</mark>
2020-09-29 19:00:47.630:INFO :oejs.Server:main: Started Server@30ee2816{STARTING}[10.0.0-SNAPSHOT,sto=5000] @746ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note how Jetty is listening on port <code>8443</code> and the protocols supported are the sequence <code>(ssl, alpn, h2, http/1.1)</code>.</p>
</div>
<div class="paragraph">
<p>The (ordered) list of protocols after <code>alpn</code> are the <em>application protocols</em>, in the example above <code>(h2, http/1.1)</code>.</p>
</div>
<div class="paragraph">
<p>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) <code>h2</code> and then <code>http/1.1</code>.</p>
</div>
<div class="paragraph">
<p>You can customize the list of application protocols and the default protocol to use in case the ALPN negotiation fails by editing the <a href="#og-module-alpn"><code>alpn</code> module</a> properties.</p>
</div>
<div class="paragraph">
<p>The HTTP/2 protocol parameters can be configured by editing the <a href="#og-module-http2"><code>http2</code> module</a> properties.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-protocols-http2c"><a class="anchor" href="#og-protocols-http2c"></a><a class="link" href="#og-protocols-http2c">Configuring Clear-Text HTTP/2</a></h4>
<div class="paragraph">
<p>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 <a href="https://tools.ietf.org/html/rfc7540#section-3.2">upgrade</a> from HTTP/1.1 to HTTP/2.</p>
</div>
<div class="paragraph">
<p>You need to enable:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>the <code>http</code> Jetty module, which provides the clear-text connector and adds the HTTP/1.1 protocol to the clear-text connector</p>
</li>
<li>
<p>the <code>http2c</code> Jetty module, which adds the HTTP/2 protocol to the clear-text connector</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-modules=http,http2c</pre>
</div>
</div>
<div class="paragraph">
<p>Starting Jetty yields:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>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<mark>{HTTP/1.1, (http/1.1, h2c)}{0.0.0.0:8080}</mark>
2020-09-30 09:18:36.361:INFO :oejs.Server:main: Started Server@3c72f59f{STARTING}[10.0.0-SNAPSHOT,sto=5000] @526ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note how Jetty is listening on port <code>8080</code> and the protocols supported are HTTP/1.1 and <code>h2c</code> (i.e. clear-text HTTP/2).</p>
</div>
<div class="paragraph">
<p>With this configuration, browsers and client applications will be able to connect to port <code>8080</code> using:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>HTTP/1.1 directly (e.g. <code>curl --http1.1 http://localhost:8080</code>):</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre>GET / HTTP/1.1
Host: localhost:8080</pre>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>HTTP/1.1 with upgrade to HTTP/2 (e.g. <code>curl --http2 http://localhost:8080</code>):</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre>GET / HTTP/1.1
Host: localhost:8080
Connection: Upgrade, HTTP2-Settings
Upgrade: h2c
HTTP2-Settings:</pre>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>HTTP/2 directly (e.g. <code>curl --http2-prior-knowledge http://localhost:8080</code>):</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre>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</pre>
</div>
</div>
<div class="paragraph">
<p>The HTTP/2 protocol parameters can be configured by editing the <a href="#og-module-http2c"><code>http2c</code> module</a> properties.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-protocols-ssl"><a class="anchor" href="#og-protocols-ssl"></a><a class="link" href="#og-protocols-ssl">Configuring Secure Protocols</a></h4>
<div class="paragraph">
<p>Secure protocols are normal protocols such as HTTP/1.1, HTTP/2 or WebSocket that are wrapped by the <a href="https://en.wikipedia.org/wiki/Transport_Layer_Security">TLS protocol</a>.
Any network protocol can be wrapped with TLS.</p>
</div>
<div class="paragraph">
<p>The <code>https</code> scheme used in URIs really means <code>tls+http/1.1</code> (or <code>tls+http/2</code>) and similarly the <code>wss</code> scheme used in URIs really means <code>tls+websocket</code>, etc.
Senders wrap the underlying protocol bytes (e.g. HTTP 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.</p>
</div>
<div class="paragraph">
<p>The <a href="#og-module-ssl"><code>ssl</code> Jetty module</a> allows you to configure a secure network connector; if other modules require encryption, they declare a dependency on the <code>ssl</code> module.</p>
</div>
<div class="paragraph">
<p>It is the job of other Jetty modules to configure the wrapped protocol.
For example, it is the <a href="#og-protocols-https"><code>https</code> module</a> that configures the wrapped protocol to be HTTP/1.1.
Similarly, it is the <a href="#og-protocols-http2"><code>http2</code> module</a> that configures the wrapped protocol to be HTTP/2.
If you enable <em>both</em> the <code>https</code> and the <code>http2</code> module, you will have a single secure connector that will be able to interpret both HTTP/1.1 and HTTP/2.</p>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
Recall from the <a href="#og-modules">section about modules</a>, that only modules that are explicitly enabled get their module configuration file (<code>*.ini</code>) saved in <code>$JETTY_BASE/start.d/</code>, and you want <code>$JETTY_BASE/start.d/ssl.ini</code> to be present so that you can configure the connector properties, the KeyStore properties and the TLS properties.
</td>
</tr>
</table>
</div>
<div class="sect4">
<h5 id="og-protocols-ssl-customize"><a class="anchor" href="#og-protocols-ssl-customize"></a><a class="link" href="#og-protocols-ssl-customize">Customizing KeyStore and TLS Configuration</a></h5>
<div class="paragraph">
<p>Secure protocols have a slightly more complicated configuration since they require to configure a <em>KeyStore</em>.
Refer to the <a href="#og-keystore">KeyStore section</a> for more information about how to create and manage a KeyStore.</p>
</div>
<div class="paragraph">
<p>For simple cases, you only need to configure the KeyStore path and KeyStore password as explained in <a href="#og-module-ssl-keystore-tls">this section</a>.</p>
</div>
<div class="paragraph">
<p>For more advanced configuration you may want to configure the TLS protocol versions, or the ciphers to include/exclude, etc.
The correct way of doing this is to create a custom <a href="#og-xml">Jetty XML file</a> and reference it in <code>$JETTY_BASE/start.d/ssl.ini</code>:</p>
</div>
<div class="listingblock">
<div class="title">ssl.ini</div>
<div class="content">
<pre class="highlight"><code>jetty.sslContext.keyStorePassword=my_passwd! <i class="conum" data-value="1"></i><b>(1)</b>
etc/tls-config.xml <i class="conum" data-value="2"></i><b>(2)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Configures the <code>jetty.sslContext.keyStorePassword</code> property with the KeyStore password.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>References your newly created <code>$JETTY_BASE/etc/tls-config.xml</code>.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The <code>ssl.ini</code> file above only shows the lines that are not commented out (you can leave the lines that are commented unmodified for future reference).</p>
</div>
<div class="paragraph">
<p>You want to create the <code>$JETTY_BASE/etc/tls-config.xml</code> with the following template content:</p>
</div>
<div class="listingblock">
<div class="title">tls-config.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;Ref refid="sslContextFactory"&gt;
... <i class="conum" data-value="1"></i><b>(1)</b>
&lt;/Ref&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Here goes your advanced configuration.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The <code>tls-config.xml</code> file references the <code>sslContextFactory</code> component (created by the <code>ssl</code> Jetty module) that configures the KeyStore and TLS parameters, so that you can now call its APIs via XML, and you will have full flexibility for any advanced configuration you want (see below for few examples).</p>
</div>
<div class="paragraph">
<p>Refer to the <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/util/ssl/SslContextFactory.html">SslContextFactory javadocs</a> for the list of methods that you can call through the Jetty XML file.</p>
</div>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<i class="fa icon-caution" title="Caution"></i>
</td>
<td class="content">
Use module properties whenever possible, and only resort to use a Jetty XML file for advanced configuration that you cannot do using module properties.
</td>
</tr>
</table>
</div>
<div class="sect5">
<h6 id="og-protocols-ssl-customize-versions"><a class="anchor" href="#og-protocols-ssl-customize-versions"></a><a class="link" href="#og-protocols-ssl-customize-versions">Customizing TLS Protocol Versions</a></h6>
<div class="paragraph">
<p>By default, the SSL protocols (SSL, SSLv2, SSLv3, etc.) are already excluded because they are vulnerable.
To explicitly add the exclusion of TLSv1.0 and TLSv1.1 (that are also vulnerable&#8201;&#8212;&#8201;which leaves only TLSv1.2 and TLSv1.3 available), you want to use this XML:</p>
</div>
<div class="listingblock">
<div class="title">tls-config.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;Ref refid="sslContextFactory"&gt;
&lt;Call name="addExcludeProtocols"&gt;
&lt;Arg&gt;
&lt;Array type="String"&gt;
&lt;Item&gt;TLSv1.0&lt;/Item&gt;
&lt;Item&gt;TLSv1.1&lt;/Item&gt;
&lt;/Array&gt;
&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Ref&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect5">
<h6 id="og-protocols-ssl-customize-ciphers"><a class="anchor" href="#og-protocols-ssl-customize-ciphers"></a><a class="link" href="#og-protocols-ssl-customize-ciphers">Customizing TLS Ciphers</a></h6>
<div class="paragraph">
<p>You can precisely set the list of excluded ciphers, completely overriding Jetty&#8217;s default, with this XML:</p>
</div>
<div class="listingblock">
<div class="title">tls-config.xml</div>
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;Ref refid="sslContextFactory"&gt;
&lt;Set name="ExcludeCipherSuites"&gt;
&lt;Array type="String"&gt;
&lt;Item&gt;^TLS_RSA_.*$&lt;/Item&gt;
&lt;Item&gt;^.*_RSA_.*_(MD5|SHA|SHA1)$&lt;/Item&gt;
&lt;Item&gt;^.*_DHE_RSA_.*$&lt;/Item&gt;
&lt;Item&gt;SSL_RSA_WITH_DES_CBC_SHA&lt;/Item&gt;
&lt;Item&gt;SSL_DHE_RSA_WITH_DES_CBC_SHA&lt;/Item&gt;
&lt;Item&gt;SSL_DHE_DSS_WITH_DES_CBC_SHA&lt;/Item&gt;
&lt;Item&gt;SSL_RSA_EXPORT_WITH_RC4_40_MD5&lt;/Item&gt;
&lt;Item&gt;SSL_RSA_EXPORT_WITH_DES40_CBC_SHA&lt;/Item&gt;
&lt;Item&gt;SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA&lt;/Item&gt;
&lt;Item&gt;SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA&lt;/Item&gt;
&lt;/Array&gt;
&lt;/Set&gt;
&lt;/Ref&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note how each array item specifies a <em>regular expression</em> that matches multiple ciphers, or specifies a precise cipher to exclude.</p>
</div>
<div class="paragraph">
<p>You can choose to create multiple XML files, and reference them all from <code>$JETTY_BASE/start.d/ssl.ini</code>, or put all your custom configurations in a single XML file.</p>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-protocols-ssl-renew"><a class="anchor" href="#og-protocols-ssl-renew"></a><a class="link" href="#og-protocols-ssl-renew">Renewing the Certificates</a></h5>
<div class="paragraph">
<p>When you create a certificate, you must specify for how many days it is valid.</p>
</div>
<div class="paragraph">
<p>The typical validity is 90 days, and while this period may seem short, it has two advantages:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Reduces the risk in case of compromised/stolen keys.</p>
</li>
<li>
<p>Encourages automation, i.e. certificate renewal performed by automated tools (rather than manually) at scheduled times.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>To renew a certificate, you must go through the <a href="#og-keystore-create">same steps</a> you followed to create the certificate the first time, and then you can <a href="#og-protocols-ssl-reload">reload the KeyStore</a> without the need to stop Jetty.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-protocols-ssl-reload"><a class="anchor" href="#og-protocols-ssl-reload"></a><a class="link" href="#og-protocols-ssl-reload">Watching and Reloading the KeyStore</a></h5>
<div class="paragraph">
<p>Jetty can be configured to monitor the directory of the KeyStore file, and reload the <code>SslContextFactory</code> component if the KeyStore file changed.</p>
</div>
<div class="paragraph">
<p>This feature can be enabled by activating the <code>ssl-reload</code> Jetty module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=ssl-reload</pre>
</div>
</div>
<div class="paragraph">
<p>For more information about the configuration of the <code>ssl-reload</code> Jetty module, see <a href="#og-module-ssl-reload">this section</a>.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-protocols-ssl-conscrypt"><a class="anchor" href="#og-protocols-ssl-conscrypt"></a><a class="link" href="#og-protocols-ssl-conscrypt">Using Conscrypt as TLS Provider</a></h5>
<div class="paragraph">
<p>By default, the standard TLS provider that comes with the JDK is used.</p>
</div>
<div class="paragraph">
<p>The standard TLS provider from OpenJDK is implemented in Java (no native code), and its performance is not optimal, both in CPU usage and memory usage.</p>
</div>
<div class="paragraph">
<p>A faster alternative, implemented natively, is Google&#8217;s <a href="https://github.com/google/conscrypt/">Conscrypt</a>, which is built on <a href="https://boringssl.googlesource.com/boringssl/">BoringSSL</a>, which is Google&#8217;s fork of <a href="https://www.openssl.org/">OpenSSL</a>.</p>
</div>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<i class="fa icon-caution" title="Caution"></i>
</td>
<td class="content">
As Conscrypt eventually binds to a native library, there is a higher risk that a bug in Conscrypt or in the native library causes a JVM crash, while the Java implementation will not cause a JVM crash.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To use Conscrypt as the TLS provider just enable the <code>conscrypt</code> Jetty module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=conscrypt</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-protocols-ssl-sni"><a class="anchor" href="#og-protocols-ssl-sni"></a><a class="link" href="#og-protocols-ssl-sni">Configuring SNI</a></h5>
<div class="paragraph">
<p>Server Name Indication (SNI) is a TLS extension that clients send to indicate what domain they want to connect to during the initial TLS handshake.</p>
</div>
<div class="paragraph">
<p>Modern TLS clients (e.g. browsers) always send the SNI extension; however, older TLS clients may not send the SNI extension.</p>
</div>
<div class="paragraph">
<p>Being able to handle the SNI is important when you have <a href="#og-deploy-virtual-hosts">virtual hosts</a> and a KeyStore with multiple certificates, one for each domain.</p>
</div>
<div class="paragraph">
<p>For example, you have deployed over a secure connector two web applications, both at context path <code>/</code>, one at virtual host <code>one.com</code> and one at virtual host <code>two.net</code>.
The KeyStore contains two certificates, one for <code>one.com</code> and one for <code>two.net</code>.</p>
</div>
<div class="paragraph">
<p>There are three <code>ssl</code> module properties that control the SNI behavior on the server: one that works at the TLS level, and two that works at the HTTP level.</p>
</div>
<div class="paragraph">
<p>The property that works at the TLS level is:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>jetty.sslContext.sniRequired</code></dt>
<dd>
<p>Whether SNI is required at the TLS level, defaults to <code>false</code>.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Its behavior is explained by the following table:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 1. Behavior of the <code>jetty.sslContext.sniRequired</code> property</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>sniRequired=false</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>sniRequired=true</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>SNI = <code>null</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>client receives default certificate</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>client receives TLS failure</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>SNI = <code>wrong.org</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>client receives default certificate</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>client receives TLS failure</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>SNI = <code>one.com</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>client receives <code>one.com</code> certificate</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>client receives <code>one.com</code> certificate</p>
</div></div></td>
</tr>
</tbody>
</table>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The <em>default certificate</em> is the certificate returned by the TLS implementation in case there is no SNI match, and you should not rely on this certificate to be the same across Java vendors and versions, or Jetty versions, or TLS provider vendors and versions.</p>
</div>
<div class="paragraph">
<p>In the example above it could be either the <code>one.com</code> certificate or the <code>two.net</code> certificate.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>When <code>jetty.sslContext.sniRequired=true</code>, clients that don&#8217;t send a valid SNI receive a TLS failure, and their attempt to connect to the server fails.
The details of this failure may not be reported and could be difficult to figure out that the failure is related to an invalid SNI.</p>
</div>
<div class="paragraph">
<p>For this reason, other two properties are defined at the HTTP level, so that clients can received an HTTP 400 response with more details about what went wrong while trying to connect to the server:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>jetty.ssl.sniRequired</code></dt>
<dd>
<p>Whether SNI is required at the HTTP level, defaults to <code>false</code>.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Its behavior is similar to the <code>jetty.sslContext.sniRequired</code> property above, and is explained by the following table:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 2. Behavior of the <code>jetty.ssl.sniRequired</code> property</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>sniRequired=false</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>sniRequired=true</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>SNI = <code>null</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Accept</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Reject: 400 Bad Request</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>SNI = <code>wrong.org</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Accept</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Reject: 400 Bad Request</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>SNI = <code>one.com</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Accept</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Accept</p>
</div></div></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>When <code>jetty.ssl.sniRequired=true</code>, the SNI is matched against the certificate sent to the client, and only if there is a match the request is accepted.</p>
</div>
<div class="paragraph">
<p>When the request is accepted, there could be an additional check controlled by the following property:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>jetty.ssl.sniHostCheck</code></dt>
<dd>
<p>Whether the certificate sent to the client matches the <code>Host</code> header, defaults to <code>true</code>.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Its behavior is explained by the following table:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 3. Behavior of the <code>jetty.ssl.sniHostCheck</code> property</caption>
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>sniHostCheck=false</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><code>sniHostCheck=true</code></p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>certificate = <code>one.com</code><br>
<code>Host: wrong.org</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Accept</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Reject: 400 Bad Request</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>certificate = <code>one.com</code><br>
<code>Host: one.com</code></p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Accept</p>
</div></div></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>Accept</p>
</div></div></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>In the normal case with the default server configuration, for a TLS clients that sends SNI, and then sends an HTTP request with the correct <code>Host</code> header, Jetty will pick the correct certificate from the KeyStore based on the SNI received from the client, and accept the request.</p>
</div>
<div class="paragraph">
<p>Accepting the request does not mean that the request is responded with an HTTP 200 OK, but just that the request passed successfully the SNI checks and will be processed by the server.
If the request URI is for a resource that does not exist, the response will likely be a 404 Not Found.</p>
</div>
<div class="paragraph">
<p>You may modify the default values of the SNI properties if you want stricter control over old/broken TLS clients or bad HTTP requests.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-protocols-proxy"><a class="anchor" href="#og-protocols-proxy"></a><a class="link" href="#og-protocols-proxy">Configuring Eclipse Jetty Behind a Load Balancer or Reverse Proxy</a></h4>
<div class="paragraph">
<p>You may need to configure one or more Jetty instances behind an <em>intermediary</em>, typically a load balancer such as <a href="https://haproxy.org">HAProxy</a>, or a reverse proxy such as <a href="https://httpd.apache.org">Apache HTTP Server</a> or <a href="https://nginx.org">Nginx</a>.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="diag-9f323b812fd1edc8217715ca0c2ba8e9.png" alt="Diagram" width="253" height="414">
</div>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>HAProxy can communicate either HTTP/1.1 or HTTP/2 to backend servers such as Jetty.</p>
</div>
<div class="paragraph">
<p>Apache HTTP Server and Nginx can only speak HTTP/1.1 to backend servers such as Jetty, and have no plans to support HTTP/2 towards backend servers.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>In these setups, typically the proxy performs TLS offloading, and the communication with backend servers happens in clear-text.
It is possible, however, to configure the proxy so that all the bytes arriving from the client are tunnelled opaquely to the backend Jetty server (that therefore needs to perform the TLS offloading) and viceversa the bytes arriving from the Jetty server are tunnelled opaquely to the client.</p>
</div>
<div class="paragraph">
<p>Also in these setups, the TCP/IP connection terminating on the Jetty servers does not originate from the client, but from the proxy, so that the remote IP address and port number may be reported incorrectly in backend server logs, or worse applications may not work because they need to be able to differentiate different clients based on the client IP address.</p>
</div>
<div class="paragraph">
<p>For this reason, intermediaries typically implement at least one of several <em>de facto</em> standards to communicate information about the original client connection to the backend Jetty server.</p>
</div>
<div class="paragraph">
<p>Jetty supports two methods to process client information sent by intermediaries:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The <code>Forwarded</code> HTTP header, defined in <a href="https://tools.ietf.org/html/rfc7239">RFC 7239</a> and replacing the old <code>X-Forwarded-*</code> headers, defined in <a href="#og-protocols-proxy-forwarded">this section</a>.</p>
</li>
<li>
<p>The <a href="https://www.haproxy.org/download/2.2/doc/proxy-protocol.txt">Proxy Protocol</a>, defined in <a href="#og-protocols-proxy-protocol">this section</a>.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>In both methods, web applications that call <code>HttpServletRequest.getRemoteAddr()</code> will receive the remote client IP address as specified by the client information sent by the intermediary, not the physical IP address of TCP connection with the intermediary.
Likewise, <code>HttpServletRequest.getRemotePort()</code> will return the remote client IP port as specified by the client information sent by the intermediary, and <code>HttpServletRequest.isSecure()</code> will return whether the client made a secure request using the <code>https</code> scheme as specified by the client information sent by the intermediary.</p>
</div>
<div class="sect4">
<h5 id="og-protocols-proxy-forwarded"><a class="anchor" href="#og-protocols-proxy-forwarded"></a><a class="link" href="#og-protocols-proxy-forwarded">Configuring Jetty for the Forwarded Header</a></h5>
<div class="paragraph">
<p>The <code>Forwarded</code> HTTP header is added by the intermediary with information about the client and the client request, for example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>GET / HTTP/1.1
Host: domain.com
Forwarded: for=2.36.72.144:21216;proto=https</pre>
</div>
</div>
<div class="paragraph">
<p>In the example above, the intermediary added the <code>Forwarded</code> header specifying that the client remote address is <code>2.36.72.144:21216</code> and that the request was made with the <code>https</code> scheme.</p>
</div>
<div class="paragraph">
<p>Support for the <code>Forwarded</code> HTTP header (and its predecessor <code>X-Forwarded-*</code> headers) is enabled with the <code>http-forwarded</code> Jetty module with the following command (issued from within the <code>$JETTY_BASE</code> directory):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=http-forwarded</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>INFO : http-forwarded initialized in ${jetty.base}/start.d/http-forwarded.ini
INFO : Base directory was modified</pre>
</div>
</div>
<div class="paragraph">
<p>With the <code>http-forwarded</code> Jetty module enabled, Jetty interprets the <code>Forwarded</code> header and makes its information available to web applications via the standard Servlet APIs.</p>
</div>
<div class="paragraph">
<p>For further information about configuring the <code>http-forwarded</code> Jetty module, see <a href="#og-module-http-forwarded">this section</a>.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-protocols-proxy-protocol"><a class="anchor" href="#og-protocols-proxy-protocol"></a><a class="link" href="#og-protocols-proxy-protocol">Configuring Jetty for the Proxy Protocol</a></h5>
<div class="paragraph">
<p>The <a href="https://www.haproxy.org/download/2.2/doc/proxy-protocol.txt">Proxy Protocol</a> is the <em>de facto</em> standard, introduced by <a href="https://haproxy.org">HAProxy</a>, to communicate client information to backend servers via the TCP connection, rather than via HTTP headers.</p>
</div>
<div class="paragraph">
<p>The information about the client connection is sent as a small data frame on each newly established connection.
This mechanism is therefore independent of any protocol, so it can be used for TLS, HTTP/1.1, HTTP/2, etc.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>There are 2 versions of the proxy protocol: v1 and v2, both supported by Jetty.</p>
</div>
<div class="paragraph">
<p>Proxy protocol v1 is human readable, but it only carries information about the client TCP connection (IP address and IP port).</p>
</div>
<div class="paragraph">
<p>Proxy protocol v2 has a binary format, carries the information about the client TCP connection, and can carry additional arbitrary information encoded in pairs <code>(type, value)</code> where <code>type</code> is a single byte that indicates the value&#8217;s meaning, and <code>value</code> is a variable length byte array that can encode user-defined data.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Support for the proxy protocol can be enabled for the clear-text connector or for the secure connector (or both).</p>
</div>
<div class="paragraph">
<p>To enable proxy protocol support for the clear-text connector, enable the <code>proxy-protocol</code> Jetty module with the following command (issued from within the <code>$JETTY_BASE</code> directory):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=proxy-protocol</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>INFO : proxy-protocol initialized in ${jetty.base}/start.d/proxy-protocol.ini
INFO : Base directory was modified</pre>
</div>
</div>
<div class="paragraph">
<p>Starting Jetty yields:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>2020-10-12 18:44:25.246:INFO :oejs.Server:main: jetty-10.0.0-SNAPSHOT; built: 2020-10-12T13:49:35.796Z; git: 1cd15e8d85feb308527c3df560734fc2ca1bc13c; jvm 15+36-1562
2020-10-12 18:44:25.267:INFO :oejdp.ScanningAppProvider:main: Deployment monitor [file:///tmp/jetty.base/webapps/]
2020-10-12 18:44:25.276:INFO :oejs.AbstractConnector:main: Started ServerConnector@7a8c8dcf{[proxy], <mark>([proxy], http/1.1)</mark>}{0.0.0.0:8080}
2020-10-12 18:44:25.285:INFO :oejs.Server:main: Started Server@5c5eefef{STARTING}[10.0.0-SNAPSHOT,sto=5000] @486ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note how in the example above the list of protocols for the clear-text connector is first <code>proxy</code> and then <code>http/1.1</code>.
For every new TCP connection, Jetty first interprets the proxy protocol bytes with the client information; after this initial proxy protocol processing, Jetty interprets the incoming bytes as HTTP/1.1 bytes.</p>
</div>
<div class="paragraph">
<p>Similarly, to enable proxy protocol support for the secure connector, enable the <code>proxy-protocol-ssl</code> Jetty module with the following command (issued from within the <code>$JETTY_BASE</code> directory):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=proxy-protocol-ssl</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre>INFO : proxy-protocol-ssl initialized in ${jetty.base}/start.d/proxy-protocol-ssl.ini
INFO : Base directory was modified</pre>
</div>
</div>
<div class="paragraph">
<p>Starting Jetty yields:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar</pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>2020-10-12 19:09:38.397:INFO :oejs.Server:main: jetty-10.0.0-SNAPSHOT; built: 2020-10-12T13:49:35.796Z; git: 1cd15e8d85feb308527c3df560734fc2ca1bc13c; jvm 15+36-1562
2020-10-12 19:09:38.417:INFO :oejdp.ScanningAppProvider:main: Deployment monitor [file:///tmp/jetty.base/webapps/]
2020-10-12 19:09:38.605:INFO :oejus.SslContextFactory:main: x509=X509@4a7f959b(mykey,h=[localhost],w=[]) for Server@5403f35f[provider=null,keyStore=file:///tmp/jetty.base/etc/test-keystore.p12,trustStore=file:///tmp/jetty.base/etc/test-keystore.p12]
2020-10-12 19:09:38.697:INFO :oejs.AbstractConnector:main: Started ServerConnector@5afa3c9{[proxy], <mark>([proxy], ssl, http/1.1)</mark>}{0.0.0.0:8443}
2020-10-12 19:09:38.705:INFO :oejs.Server:main: Started Server@54d9d12d{STARTING}[10.0.0-SNAPSHOT,sto=5000] @785ms</code></pre>
</div>
</div>
<div class="paragraph">
<p>Note how in the example above the list of protocols for the secure connector is first <code>proxy</code>, then <code>ssl</code> and then <code>http/1.1</code>.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-protocols-proxy-haproxy"><a class="anchor" href="#og-protocols-proxy-haproxy"></a><a class="link" href="#og-protocols-proxy-haproxy">Configuring HAProxy and Jetty for HTTP/1.1 and HTTP/2</a></h5>
<div class="paragraph">
<p><a href="https://haproxy.org">HAProxy</a> is an open source solution that offers load balancing and proxying for TCP and HTTP based application, and can be used as a replacement for Apache or Nginx when these are used as reverse proxies.</p>
</div>
<div class="paragraph">
<p>The deployment proposed here has HAProxy playing the role that Apache and Nginx usually do: to perform the TLS offloading (that is, decrypt incoming bytes and encrypt outgoing bytes) and then forwarding the now clear-text traffic to a backend Jetty server, speaking either HTTP/1.1 or HTTP/2.
Since HAProxy&#8217;s TLS offloading is based on OpenSSL, it is much more efficient than the Java implementation shipped with OpenJDK.</p>
</div>
<div class="paragraph">
<p>After you have installed HAProxy on your system, you want to configure it so that it can perform TLS offloading.</p>
</div>
<div class="paragraph">
<p>HAProxy will need a single file containing the X509 certificates and the private key, all in <a href="https://en.wikipedia.org/wiki/X.509">PEM format</a>, with the following order:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>The site certificate; this certificate&#8217;s Common Name refers to the site domain (for example: CN=*.webtide.com) and is signed by Certificate Authority #1.</p>
</li>
<li>
<p>The Certificate Authority #1 certificate; this certificate may be signed by Certificate Authority #2.</p>
</li>
<li>
<p>The Certificate Authority #2 certificate; this certificate may be signed by Certificate Authority #3; and so on until the Root Certificate Authority.</p>
</li>
<li>
<p>The Root Certificate Authority certificate.</p>
</li>
<li>
<p>The private key corresponding to the site certificate.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Refer to the <a href="#og-keystore">section about KeyStores</a> for more information about generating the required certificates and private key.</p>
</div>
<div class="paragraph">
<p>Now you can create the HAProxy configuration file (in Linux it&#8217;s typically `/etc/haproxy/haproxy.cfg).
This is a minimal configuration:</p>
</div>
<div class="listingblock">
<div class="title">haproxy.cfg</div>
<div class="content">
<pre class="highlight"><code>global
tune.ssl.default-dh-param 1024
defaults
timeout connect 10000ms
timeout client 60000ms
timeout server 60000ms
frontend fe_http <i class="conum" data-value="1"></i><b>(1)</b>
mode http
bind *:80
# Redirect to https
redirect scheme https code 301
frontend fe_https <i class="conum" data-value="2"></i><b>(2)</b>
mode tcp
bind *:443 ssl no-sslv3 crt /path/to/domain.pem ciphers TLSv1.2 alpn h2,http/1.1
default_backend be_http
backend be_http <i class="conum" data-value="3"></i><b>(3)</b>
mode tcp
server domain 127.0.0.1:8282 send-proxy-v2</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The <code>fe_http</code> front-end accepts connections on port 80 and redirects them to use the <code>https</code> scheme.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The <code>fe_https</code> front-end accepts connections on port 443, and it is where the TLS decryption/encryption happens.
You must specify the path to the PEM file containing the TLS key material (the <code>crt /path/to/domain.pem</code> part), the ciphers that are suitable for HTTP/2 (<code>ciphers TLSv1.2</code>), and the ALPN protocols supported (<code>alpn h2,http/1.1</code>).
This front-end then forwards the now decrypted bytes to the backend in <code>mode tcp</code>.
The <code>mode tcp</code> says that HAProxy will not try to interpret the bytes but instead opaquely forwards them to the backend.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>The <code>be_http</code> backend will forward (again in <code>mode tcp</code>) the clear-text bytes to a Jetty connector that talks clear-text HTTP/2 and HTTP/1.1 on port 8282.
The <code>send-proxy-v2</code> directive sends the proxy protocol v2 bytes to the backend server.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>On the Jetty side, you need to enable the following modules:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-modules=proxy-protocol,http2c,http,deploy</pre>
</div>
</div>
<div class="paragraph">
<p>You need to specify the host (<code>127.0.0.1</code>) and port (<code>8282</code>) you have configured in HAProxy when you start Jetty:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar jetty.http.host=127.0.0.1 jetty.http.port=8282</pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>You want the Jetty connector that listens on port <code>8282</code> to be available only to HAProxy, and not to remote clients.</p>
</div>
<div class="paragraph">
<p>For this reason, you want to specify the <code>jetty.http.host</code> property on the command line (or in <code>$JETTY_BASE/start.d/http.ini</code> to make this setting persistent) to bind the Jetty connector only on the loopback interface (<code>127.0.0.1</code>), making it available to HAProxy but not to remote clients.</p>
</div>
<div class="paragraph">
<p>If your Jetty instance runs on a different machine and/or on a different (sub)network, you may want to adjust both the back-end section of the HAProxy configuration file and the <code>jetty.http.host</code> property to match accordingly.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>With this configuration for HAProxy and Jetty, browsers supporting HTTP/2 will connect to HAProxy, which will decrypt the traffic and send it to Jetty.
Likewise, HTTP/1.1 clients will connect to HAProxy, which will decrypt the traffic and send it to Jetty.</p>
</div>
<div class="paragraph">
<p>The Jetty connector, configured with the <code>http2c</code> and the <code>http</code> modules is able to distinguish whether the incoming bytes are HTTP/2 or HTTP/1.1 and will handle the request accordingly.</p>
</div>
<div class="paragraph">
<p>The response is relayed back to HAProxy, which will encrypt it and send it back to the remote client.</p>
</div>
<div class="paragraph">
<p>This configuration offers you efficient TLS offloading, HTTP/2 support and transparent fallback to HTTP/1.1 for clients that don&#8217;t support HTTP/1.1.</p>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-keystore"><a class="anchor" href="#og-keystore"></a><a class="link" href="#og-keystore">Configuring KeyStores</a></h3>
<div class="paragraph">
<p>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".</p>
</div>
<div class="paragraph">
<p>Keystores may encode the cryptographic material with different encodings, the most common being <a href="https://en.wikipedia.org/wiki/PKCS_12">PKCS12</a>, and are typically protected by a password.</p>
</div>
<div class="paragraph">
<p>Refer to the <a href="#og-protocols-ssl">secure protocols section</a> for more information about how to configure a secure connector using a KeyStore.</p>
</div>
<div class="sect3">
<h4 id="og-keystore-create"><a class="anchor" href="#og-keystore-create"></a><a class="link" href="#og-keystore-create">Creating a KeyStore</a></h4>
<div class="paragraph">
<p>KeyStores are created with the JDK tool <code>$JAVA_HOME/bin/keytool</code>.</p>
</div>
<div class="paragraph">
<p>The following command creates a KeyStore file containing a private key and a self-signed certificate:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>keytool
-genkeypair <i class="conum" data-value="1"></i><b>(1)</b>
-validity 90 <i class="conum" data-value="2"></i><b>(2)</b>
-keyalg RSA <i class="conum" data-value="3"></i><b>(3)</b>
-keysize 2048 <i class="conum" data-value="4"></i><b>(4)</b>
-keystore /path/to/keystore.p12 <i class="conum" data-value="5"></i><b>(5)</b>
-storetype pkcs12 <i class="conum" data-value="6"></i><b>(6)</b>
-dname "CN=domain.com, OU=Unit, O=Company, L=City, S=State, C=Country" <i class="conum" data-value="7"></i><b>(7)</b>
-ext san=dns:www.domain.com,dns:domain.org <i class="conum" data-value="8"></i><b>(8)</b>
-v <i class="conum" data-value="9"></i><b>(9)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>the command to generate a key and certificate pair</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>specifies the number of days after which the certificate expires</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>the algorithm <em>must</em> be RSA (the DSA algorithm does not work for web sites)</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>indicates the strength of the key</td>
</tr>
<tr>
<td><i class="conum" data-value="5"></i><b>5</b></td>
<td>the keyStore file</td>
</tr>
<tr>
<td><i class="conum" data-value="6"></i><b>6</b></td>
<td>the keyStore type, stick with the standard PKCS12</td>
</tr>
<tr>
<td><i class="conum" data-value="7"></i><b>7</b></td>
<td>the distinguished name (more below)&#8201;&#8212;&#8201;customize it with your values for CN, OU, O, L, S and C</td>
</tr>
<tr>
<td><i class="conum" data-value="8"></i><b>8</b></td>
<td>the extension with the subject alternative names (more below)</td>
</tr>
<tr>
<td><i class="conum" data-value="9"></i><b>9</b></td>
<td>verbose output</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The command prompts for the KeyStore password that you must choose to protect the access to the KeyStore.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The important parts of the command above are the <em>Common Name</em> (CN) part of the distinguished name, and the subject alternative names (SAN).</p>
</div>
<div class="paragraph">
<p>The CN value must be the main domain you own and that you want to use for your web applications.
For example, if you have bought domains <code>domain.com</code> and <code>domain.org</code>, you want to specify <code>CN=domain.com</code> as your main domain.</p>
</div>
<div class="paragraph">
<p>Furthermore, to specify additional domains or subdomains within the same certificate, you must specify the SAN extension.
In the example above, <code>san=dns:www.domain.com,dns:domain.org</code> specifies <code>www.domain.com</code> and <code>domain.org</code> as alternative names for your web applications (that you can configure using <a href="#og-deploy-virtual-hosts">virtual hosts</a>).</p>
</div>
<div class="paragraph">
<p>In rare cases, you may want to specify IP addresses, rather than domains, in the SAN extension.
The syntax in such case is <code>san=ip:127.0.0.1,ip:[::1]</code>, which specifies as subject alternative names IPv4 <code>127.0.0.1</code> and IPv6 <code>[::1]</code>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="og-keystore-csr"><a class="anchor" href="#og-keystore-csr"></a><a class="link" href="#og-keystore-csr">Creating a Certificate Signing Request</a></h4>
<div class="paragraph">
<p>Self-signed certificates are not trusted by browsers and generic clients: you need to establish a trust chain by having your self-signed certificate signed by a certificate authority (CA).</p>
</div>
<div class="paragraph">
<p>Browsers and generic clients (e.g. Java clients) have an internal list of trusted certificate authorities root certificates; they use these trusted certificates to verify the certificate they received from the server when they connect to your web applications.</p>
</div>
<div class="paragraph">
<p>To have your self-signed certificate signed by a certificate authority you first need to produce a <em>certificate signing request</em> (CSR):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>keytool
-certreq <i class="conum" data-value="1"></i><b>(1)</b>
-file domain.com.csr <i class="conum" data-value="2"></i><b>(2)</b>
-keystore keystore.p12 <i class="conum" data-value="3"></i><b>(3)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>the command to generate a certificate signing request</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>the file to save the CSR</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>the keystore that contains the self-signed certificate</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Then, you have to send the CSR file to the certificate authority of your choice, and wait for their reply (they will probably require a proof that you really own the domains indicated in your certificate).</p>
</div>
<div class="paragraph">
<p>Eventually, the certificate authority will reply to you with one or more files containing the CA certificate chain, and your certificate signed by their certificate chain.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-keystore-csr-import"><a class="anchor" href="#og-keystore-csr-import"></a><a class="link" href="#og-keystore-csr-import">Importing the Signed Certificate</a></h4>
<div class="paragraph">
<p>The file you receive from the CA is typically in PEM format, and you <strong>must</strong> import it back into the same KeyStore file you used to generate the CSR.
You must import <strong>both</strong> the certificate chain and your signed certificate.</p>
</div>
<div class="paragraph">
<p>First, import the certificate chain:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>keytool
-importcert <i class="conum" data-value="1"></i><b>(1)</b>
-alias ca <i class="conum" data-value="2"></i><b>(2)</b>
-file chain_from_ca.pem <i class="conum" data-value="3"></i><b>(3)</b>
-keystore keystore.p12 <i class="conum" data-value="4"></i><b>(4)</b>
-trustcacerts <i class="conum" data-value="5"></i><b>(5)</b>
-v <i class="conum" data-value="6"></i><b>(6)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>the command to import certificates</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>use the <code>ca</code> alias to differentiate from the alias of the server certificate</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>the file containing the certificate chain received from the CA</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>your KeyStore file</td>
</tr>
<tr>
<td><i class="conum" data-value="5"></i><b>5</b></td>
<td>specify that you trust CA certificates</td>
</tr>
<tr>
<td><i class="conum" data-value="6"></i><b>6</b></td>
<td>verbose output</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Then, import the signed certificate:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>keytool
-importcert
-file signed_certificate.pem
-keystore keystore.p12
-trustcacerts
-v</pre>
</div>
</div>
<div class="paragraph">
<p>Now you have a trusted certificate in your KeyStore that you can use for the domains of your web applications.</p>
</div>
<div class="paragraph">
<p>Refer to the section about configuring <a href="#og-protocols-ssl">secure protocols</a> to configure the secure connector with your newly created KeyStore.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-keystore-client-authn"><a class="anchor" href="#og-keystore-client-authn"></a><a class="link" href="#og-keystore-client-authn">Creating a KeyStore for Client Certificate Authentication</a></h4>
<div class="paragraph">
<p>For the majority of secure web sites, it is the client (typically the browser) that validates the certificate sent by the server (by verifying the certificate chain).
This is the <em>server domain certificate</em>.</p>
</div>
<div class="paragraph">
<p>However, the TLS protocol supports a <em>mutual authentication</em> mode where also the client must send a certificate to the server, that the server validates.</p>
</div>
<div class="paragraph">
<p>You typically want to sign the client certificate(s) with a server certificate that you control, and you must distribute the client certificate(s) to all the clients that need it, and redistribute the client certificates when they expire.
The <em>server authentication certificate</em> may be different from the <em>server domain certificate</em>, but it&#8217;s typically stored in the same KeyStore for simplicity (although under a different alias).</p>
</div>
<div class="paragraph">
<p>First, you want to create the private key and server authentication certificate that you will use to sign client certificates:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>keytool
-genkeypair
-alias server_authn <i class="conum" data-value="1"></i><b>(1)</b>
-validity 90
-keyalg RSA
-keysize 2048
-keystore keystore.p12 <i class="conum" data-value="2"></i><b>(2)</b>
-storetype pkcs12
-dname "CN=server_authn, OU=Unit, O=Company, L=City, S=State, C=Country" <i class="conum" data-value="3"></i><b>(3)</b>
-ext bc=ca:true <i class="conum" data-value="4"></i><b>(4)</b>
-v</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>use the <code>server_authn</code> alias to differentiate from the alias of the server certificate</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>the KeyStore file</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>the CN is not that important, since this certificate will not be validated by clients</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>the extension with the basic constraints (more below)</td>
</tr>
</table>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
The important difference with the <a href="#og-keystore-create">creation of a server certificate</a> is the <em>basic constraints</em> extension (<code>bc</code>) that indicates that this certificates acts as a certificate authority (<code>ca:true</code>).
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Now you want to export both the private key and server authentication certificate.
Unfortunately, the <code>keytool</code> program cannot export private keys, so you need to use a different command line program like <code>openssl</code>, or a graphical program like <a href="https://keystore-explorer.org/">KeyStore Explorer</a>.</p>
</div>
<div class="paragraph">
<p>Let&#8217;s use <code>openssl</code> to export the server authentication private key:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>openssl
pkcs12
-in keystore.p12
-nodes
-nocerts
-out server_authn.key</pre>
</div>
</div>
<div class="paragraph">
<p>Now let&#8217;s export the server authentication certificate:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>keytool
-exportcert
-keystore keystore.p12
-rfc
-file server_authn.crt
-v</pre>
</div>
</div>
<div class="paragraph">
<p>At this point, you want to create a client KeyStore, so that you can sign the client certificate with the server authentication cryptographic material:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>keytool
-genkeypair
-validity 90
-keyalg RSA
-keysize 2048
-keystore client_keystore.p12 <i class="conum" data-value="1"></i><b>(1)</b>
-storetype pkcs12
-dname "CN=client, OU=Unit, O=Company, L=City, S=State, C=Country" <i class="conum" data-value="2"></i><b>(2)</b>
-v</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>the client KeyStore file</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>the CN is not that important, since it will not be validated by the server</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Now produce a certificate signing request (CSR):</p>
</div>
<div class="listingblock">
<div class="content">
<pre>keytool
-certreq
-file client.csr
-keystore client_keystore.p12</pre>
</div>
</div>
<div class="paragraph">
<p>Now you need to sign the CSR, but again the <code>keytool</code> program does not have this functionality, and you must resort again to use <code>openssl</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>openssl
x509
-req
-days 90
-in client.csr
-CA server_authn.crt
-CAkey server_authn.key
-CAcreateserial
-sha256
-out signed.crt</pre>
</div>
</div>
<div class="paragraph">
<p>Now you need to import the server authentication certificate and the signed client certificate into the client KeyStore.</p>
</div>
<div class="paragraph">
<p>First, the server authentication certificate:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>keytool
-importcert
-alias ca
-file server_authn.crt
-keystore client_keystore.p12
-v</pre>
</div>
</div>
<div class="paragraph">
<p>Then, the signed client certificate:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>keytool
-importcert
-file signed.crt
-keystore client_keystore.p12
-v</pre>
</div>
</div>
<div class="paragraph">
<p>Now you can distribute <code>client_keystore.p12</code> to your client(s).</p>
</div>
<div class="paragraph">
<p>Refer to the section about configuring <a href="#og-protocols-ssl">secure protocols</a> to configure the secure connector to require client authentication.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-modules"><a class="anchor" href="#og-modules"></a><a class="link" href="#og-modules">Jetty Modules</a></h4>
<div class="paragraph">
<p>TODO</p>
</div>
</div>
<div class="sect3">
<h4 id="og-module-bytebufferpool"><a class="anchor" href="#og-module-bytebufferpool"></a><a class="link" href="#og-module-bytebufferpool">Module <code>bytebufferpool</code></a></h4>
<div class="paragraph">
<p>The <code>bytebufferpool</code> module allows you to configure the server-wide <code>ByteBuffer</code> pool.</p>
</div>
<div class="paragraph">
<p>The module file is <code>$JETTY_HOME/modules/bytebufferpool.mod</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre># 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</pre>
</div>
</div>
<div class="paragraph">
<p>Among the configurable properties, the most relevant are:</p>
</div>
<div class="paragraph">
<p>TODO</p>
</div>
</div>
<div class="sect3">
<h4 id="og-module-deploy"><a class="anchor" href="#og-module-deploy"></a><a class="link" href="#og-module-deploy">Module <code>deploy</code></a></h4>
<div class="paragraph">
<p>The <code>deploy</code> module provides the deployment feature through a <code>DeploymentManager</code> component that watches a directory for changes (see <a href="#og-deploy">how to deploy web applications</a> for more information).</p>
</div>
<div class="paragraph">
<p>Files or directories added in this monitored directory cause the <code>DeploymentManager</code> to deploy them as web applications; updating files already existing in this monitored directory cause the <code>DeploymentManager</code> to re-deploy the correspondent web application; removing files in this monitored directory cause the <code>DeploymentManager</code> to undeploy the correspondent web application (see also <a href="#og-deploy-rules">here</a> for more information).</p>
</div>
<div class="paragraph">
<p>The module file is <code>$JETTY_HOME/modules/deploy.mod</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>[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</pre>
</div>
</div>
<div class="paragraph">
<p>Among the configurable properties, the most relevant are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>jetty.deploy.monitoredDir</code>, to change the name of the monitored directory.</p>
</li>
<li>
<p><code>jetty.deploy.scanInterval</code>, to change the scan period, that is how frequently the <code>DeploymentManager</code> wakes up to scan the monitored directory for changes.
Setting <code>jetty.deploy.scanInterval=0</code> disabled <em>hot</em> deployment so that only static deployment will be possible (see also <a href="#og-deploy-hot-static">here</a> for more information).</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="og-module-http"><a class="anchor" href="#og-module-http"></a><a class="link" href="#og-module-http">Module <code>http</code></a></h4>
<div class="paragraph">
<p>The <code>http</code> module provides the clear-text connector and support for the clear-text HTTP/1.1 protocol, and depends on the <a href="#og-module-server"><code>server</code> module</a>.</p>
</div>
<div class="paragraph">
<p>The module properties to configure the clear-text connector are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>### Clear-Text HTTP Connector Configuration
## The host/address to bind the connector to.
# jetty.http.host=0.0.0.0
## The port the connector listens on.
# jetty.http.port=8080
## The connector idle timeout, in milliseconds.
# jetty.http.idleTimeout=30000
## The number of acceptors (-1 picks a default value based on number of cores).
# jetty.http.acceptors=-1
## The number of selectors (-1 picks a default value based on number of cores).
# jetty.http.selectors=-1
## The ServerSocketChannel accept queue backlog (0 picks the platform default).
# jetty.http.acceptQueueSize=0
## The thread priority delta to give to acceptor threads.
# jetty.http.acceptorPriorityDelta=0
## Whether to enable the SO_REUSEADDR socket option.
# jetty.http.reuseAddress=true
## Whether to enable the TCP_NODELAY socket option on accepted sockets.
# jetty.http.acceptedTcpNoDelay=true
## The SO_RCVBUF socket option to set on accepted sockets.
## A value of -1 indicates that the platform default is used.
# jetty.http.acceptedReceiveBufferSize=-1
## The SO_SNDBUF socket option to set on accepted sockets.
## A value of -1 indicates that the platform default is used.
# jetty.http.acceptedSendBufferSize=-1</pre>
</div>
</div>
<div class="paragraph">
<p>Among the configurable properties, the most relevant are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>jetty.http.port</code>, default <code>8080</code>, is the network port that Jetty listens to for clear-text HTTP/1.1 connections.</p>
</li>
<li>
<p><code>jetty.http.idleTimeout</code>, default <code>30</code> seconds, 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.</p>
</li>
<li>
<p><code>jetty.http.acceptors</code>, 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.</p>
</li>
<li>
<p><code>jetty.http.selectors</code>, 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.</p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="og-module-http-acceptors"><a class="anchor" href="#og-module-http-acceptors"></a><a class="link" href="#og-module-http-acceptors">Configuration of Acceptors</a></h5>
<div class="paragraph">
<p>Accepting connections is a blocking operation, so a thread is blocked in the <code>accept()</code> call until a connection is accepted, and other threads are blocked on the lock acquired just before the <code>accept()</code> call.</p>
</div>
<div class="paragraph">
<p>When the accepting thread accepts a connection, it performs a little processing of the just accepted connection, before forwarding it to other components.</p>
</div>
<div class="paragraph">
<p>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 <code>accept()</code>.</p>
</div>
<div class="paragraph">
<p>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.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-module-http-selectors"><a class="anchor" href="#og-module-http-selectors"></a><a class="link" href="#og-module-http-selectors">Configuration of Selectors</a></h5>
<div class="paragraph">
<p>Performing a NIO <code>select()</code> call is a blocking operation, where the selecting thread is blocked in the <code>select()</code> 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.</p>
</div>
<div class="paragraph">
<p>A single NIO selector can manage thousands of connections, with the assumption that not many of them will be ready at the same time.</p>
</div>
<div class="paragraph">
<p>For a single NIO selector, the ratio between the average number of selected connections over the total number of connections for every <code>select()</code> call depends heavily on the protocol but also on the application.</p>
</div>
<div class="paragraph">
<p>Multiplexed protocols such as HTTP/2 tend to be busier than duplex protocols such as HTTP/1.1, leading to a higher ratio.</p>
</div>
<div class="paragraph">
<p>REST applications that exchange many little JSON messages tend to be busier than file server applications, leading to a higher ratio.</p>
</div>
<div class="paragraph">
<p>The higher the ratio, the higher the number of selectors you want to have, compatibly with the number of cores&#8201;&#8212;&#8201;there is no point in having 64 selector threads on a single core hardware.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-module-http2"><a class="anchor" href="#og-module-http2"></a><a class="link" href="#og-module-http2">Module <code>http2</code></a></h4>
<div class="paragraph">
<p>The <code>http2</code> module enables support for the secure HTTP/2 protocol.</p>
</div>
<div class="paragraph">
<p>The module properties are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>## Specifies the maximum number of concurrent requests per session.
# jetty.http2.maxConcurrentStreams=128
## Specifies the initial stream receive window (client to server) in bytes.
# jetty.http2.initialStreamRecvWindow=524288
## Specifies the initial session receive window (client to server) in bytes.
# jetty.http2.initialSessionRecvWindow=1048576
## Specifies the maximum number of keys in all SETTINGS frames received by a session.
# jetty.http2.maxSettingsKeys=64
## Specifies the maximum number of bad frames and pings per second,
## after which a session is closed to avoid denial of service attacks.
# jetty.http2.rateControl.maxEventsPerSecond=20</pre>
</div>
</div>
<div class="paragraph">
<p>The <code>jetty.http2.rateControl.maxEventsPerSecond</code> property controls the number of "bad" or "unnecessary" frames that a client may send before the server closes the connection (with code <a href="https://tools.ietf.org/html/rfc7540#section-7"><code>ENHANCE_YOUR_CALM</code></a>) to avoid a denial of service.</p>
</div>
<div class="paragraph">
<p>For example, an attacker may send empty <code>SETTINGS</code> frames to a server in a tight loop.
While the <code>SETTINGS</code> frames don&#8217;t change the server configuration and each of them is somehow harmless, the server will be very busy processing them because they are sent by the attacker one after the other, causing a CPU spike and eventually a denial of service (as all CPUs will be busy processing empty <code>SETTINGS</code> frames).</p>
</div>
<div class="paragraph">
<p>The same attack may be performed with <code>PRIORITY</code> frames, empty <code>DATA</code> frames, <code>PING</code> frames, etc.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-module-http2c"><a class="anchor" href="#og-module-http2c"></a><a class="link" href="#og-module-http2c">Module <code>http2c</code></a></h4>
<div class="paragraph">
<p>The <code>http2c</code> module enables support for the clear-text HTTP/2 protocol.</p>
</div>
<div class="paragraph">
<p>The module properties are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>## Specifies the maximum number of concurrent requests per session.
# jetty.http2c.maxConcurrentStreams=1024
## Specifies the initial stream receive window (client to server) in bytes.
# jetty.http2c.initialStreamRecvWindow=65535
## Specifies the initial session receive window (client to server) in bytes.
# jetty.http2.initialSessionRecvWindow=1048576
## Specifies the maximum number of keys in all SETTINGS frames received by a session.
# jetty.http2.maxSettingsKeys=64
## Specifies the maximum number of bad frames and pings per second,
## after which a session is closed to avoid denial of service attacks.
# jetty.http2.rateControl.maxEventsPerSecond=20</pre>
</div>
</div>
<div class="paragraph">
<p>The <code>jetty.http2.rateControl.maxEventsPerSecond</code> property controls the number of "bad" or "unnecessary" frames that a client may send before the server closes the connection (with code <a href="https://tools.ietf.org/html/rfc7540#section-7"><code>ENHANCE_YOUR_CALM</code></a>) to avoid a denial of service.</p>
</div>
<div class="paragraph">
<p>For example, an attacker may send empty <code>SETTINGS</code> frames to a server in a tight loop.
While the <code>SETTINGS</code> frames don&#8217;t change the server configuration and each of them is somehow harmless, the server will be very busy processing them because they are sent by the attacker one after the other, causing a CPU spike and eventually a denial of service (as all CPUs will be busy processing empty <code>SETTINGS</code> frames).</p>
</div>
<div class="paragraph">
<p>The same attack may be performed with <code>PRIORITY</code> frames, empty <code>DATA</code> frames, <code>PING</code> frames, etc.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-module-http-forwarded"><a class="anchor" href="#og-module-http-forwarded"></a><a class="link" href="#og-module-http-forwarded">Module <code>http-forwarded</code></a></h4>
<div class="paragraph">
<p>The <code>http-forwarded</code> module provides support for processing the <code>Forwarded</code> HTTP header (defined in <a href="https://tools.ietf.org/html/rfc7239">RFC 7239</a>) and the now obsoleted <code>X-Forwarded-*</code> HTTP headers.</p>
</div>
<div class="paragraph">
<p>The module properties are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>### ForwardedRequestCustomizer Configuration
## Whether to process only the RFC7239 "Forwarded" header.
## "X-Forwarded-*" headers are not processed.
# jetty.httpConfig.forwardedOnly=false
## Whether the address obtained from "Forwarded: by=" or
## "X-Forwarded-Server" is used in the request authority.
# jetty.httpConfig.forwardedProxyAsAuthority=false
## Whether the "X-Forwarded-Port" header is used in the request authority,
## or else it is the remote client port.
# jetty.httpConfig.forwardedPortAsAuthority=true
## The name of the RFC 7239 HTTP header.
# jetty.httpConfig.forwardedHeader=Forwarded
## The name of the obsolete forwarded host HTTP header.
# jetty.httpConfig.forwardedHostHeader=X-Forwarded-Host
## The name of the obsolete forwarded server HTTP header.
# jetty.httpConfig.forwardedServerHeader=X-Forwarded-Server
## The name of the obsolete forwarded scheme HTTP header.
# jetty.httpConfig.forwardedProtoHeader=X-Forwarded-Proto
## The name of the obsolete forwarded for HTTP header.
# jetty.httpConfig.forwardedForHeader=X-Forwarded-For
## The name of the obsolete forwarded port HTTP header.
# jetty.httpConfig.forwardedPortHeader=X-Forwarded-Port
## The name of the obsolete forwarded https HTTP header.
# jetty.httpConfig.forwardedHttpsHeader=X-Proxied-Https
## The name of the obsolete forwarded SSL session ID HTTP header.
# jetty.httpConfig.forwardedSslSessionIdHeader=Proxy-ssl-id
## The name of the obsolete forwarded SSL cipher HTTP header.
# jetty.httpConfig.forwardedCipherSuiteHeader=Proxy-auth-cert</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-module-https"><a class="anchor" href="#og-module-https"></a><a class="link" href="#og-module-https">Module <code>https</code></a></h4>
<div class="paragraph">
<p>The <code>https</code> module provides the HTTP/1.1 protocol to the <a href="#og-module-ssl"><code>ssl</code> module</a>.</p>
</div>
<div class="paragraph">
<p>The module file is <code>$JETTY_HOME/modules/https.mod</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre># DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
[description]
Adds HTTPS protocol support to the TLS(SSL) Connector.
[tags]
connector
https
http
ssl
[depend]
ssl
[optional]
alpn
http2
http-forwarded
[xml]
etc/jetty-https.xml</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-module-server"><a class="anchor" href="#og-module-server"></a><a class="link" href="#og-module-server">Module <code>server</code></a></h4>
<div class="paragraph">
<p>The <code>server</code> module provides generic server support, and configures generic HTTP properties that apply to all HTTP protocols, the scheduler properties and the server specific properties.</p>
</div>
<div class="paragraph">
<p>The <code>server</code> module depends on the <a href="#og-module-threadpool"><code>threadpool</code> module</a>, the <a href="#og-module-bytebufferpool"><code>bytebufferpool</code> module</a> and the <a href="#og-module-logging"><code>logging</code> module</a>.</p>
</div>
<div class="paragraph">
<p>The module file is <code>$JETTY_HOME/modules/server.mod</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre># 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-jakarta-servlet-api-5.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</pre>
</div>
</div>
<div class="paragraph">
<p>Among the configurable properties, the most relevant are:</p>
</div>
<div class="paragraph">
<p>TODO</p>
</div>
</div>
<div class="sect3">
<h4 id="og-module-ssl"><a class="anchor" href="#og-module-ssl"></a><a class="link" href="#og-module-ssl">Module <code>ssl</code></a></h4>
<div class="paragraph">
<p>The <code>ssl</code> module provides the secure connector, and allows you to configure the KeyStore properties and the TLS parameters, and depends on the <a href="#og-module-server"><code>server</code> module</a>.</p>
</div>
<div class="sect4">
<h5 id="og-module-ssl-connector"><a class="anchor" href="#og-module-ssl-connector"></a><a class="link" href="#og-module-ssl-connector">Secure Connector Properties</a></h5>
<div class="paragraph">
<p>The module properties to configure the secure connector are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>### TLS (SSL) Connector Configuration
## The host/address to bind the connector to.
# jetty.ssl.host=0.0.0.0
## The port the connector listens on.
# jetty.ssl.port=8443
## The connector idle timeout, in milliseconds.
# jetty.ssl.idleTimeout=30000
## The number of acceptors (-1 picks a default value based on number of cores).
# jetty.ssl.acceptors=-1
## The number of selectors (-1 picks a default value based on number of cores).
# jetty.ssl.selectors=-1
## The ServerSocketChannel accept queue backlog (0 picks the platform default).
# jetty.ssl.acceptQueueSize=0
## The thread priority delta to give to acceptor threads.
# jetty.ssl.acceptorPriorityDelta=0
## Whether to enable the SO_REUSEADDR socket option.
# jetty.ssl.reuseAddress=true
## Whether to enable the TCP_NODELAY socket option on accepted sockets.
# jetty.ssl.acceptedTcpNoDelay=true
## The SO_RCVBUF socket option to set on accepted sockets.
## A value of -1 indicates that the platform default is used.
# jetty.ssl.acceptedReceiveBufferSize=-1
## The SO_SNDBUF socket option to set on accepted sockets.
## A value of -1 indicates that the platform default is used.
# jetty.ssl.acceptedSendBufferSize=-1
## Whether client SNI data is required for all secure connections.
## When SNI is required, clients that do not send SNI data are rejected with an HTTP 400 response.
# jetty.ssl.sniRequired=false
## Whether client SNI data is checked to match CN and SAN in server certificates.
## When SNI is checked, if the match fails the connection is rejected with an HTTP 400 response.
# jetty.ssl.sniHostCheck=true
## The max age, in seconds, for the Strict-Transport-Security response header.
# jetty.ssl.stsMaxAgeSeconds=31536000
## Whether to include the subdomain property in any Strict-Transport-Security header.
# jetty.ssl.stsIncludeSubdomains=true</pre>
</div>
</div>
<div class="paragraph">
<p>Among the configurable properties, the most relevant are:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>jetty.ssl.port</code></dt>
<dd>
<p>the network port that Jetty listens to for secure connections&#8201;&#8212;&#8201;default <code>8443</code>.</p>
</dd>
<dt class="hdlist1"><code>jetty.http.idleTimeout</code></dt>
<dd>
<p>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&#8201;&#8212;&#8201;default <code>30000</code> milliseconds.</p>
</dd>
<dt class="hdlist1"><code>jetty.http.acceptors</code></dt>
<dd>
<p>the number of threads that compete to accept connections&#8201;&#8212;&#8201;default -1 (i.e. an accept heuristic decides the value based on the number of cores).
Refer to <a href="#og-module-http-acceptors">this section</a> for more information about acceptor threads.</p>
</dd>
<dt class="hdlist1"><code>jetty.http.selectors</code></dt>
<dd>
<p>the number of NIO selectors (with an associated thread) that manage connections&#8201;&#8212;&#8201;default -1 (i.e. a select heuristic decides the value based on the number of cores).
Refer to <a href="#og-module-http-selectors">this section</a> for more information about selector threads.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>The module properties to configure the KeyStore and TLS parameters are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>### SslContextFactory Configuration
## Note that OBF passwords are not secure, just protected from casual observation.
## Whether client SNI data is required for all secure connections.
## When SNI is required, clients that do not send SNI data are rejected with a TLS handshake error.
# jetty.sslContext.sniRequired=false
## The Endpoint Identification Algorithm.
## Same as javax.net.ssl.SSLParameters#setEndpointIdentificationAlgorithm(String).
# jetty.sslContext.endpointIdentificationAlgorithm=
## The JSSE Provider.
# jetty.sslContext.provider=
## The KeyStore file path (relative to $JETTY_BASE).
# jetty.sslContext.keyStorePath=etc/keystore.p12
## The TrustStore file path (relative to $JETTY_BASE).
# jetty.sslContext.trustStorePath=etc/keystore.p12
## The KeyStore password.
# jetty.sslContext.keyStorePassword=
## The Keystore type.
# jetty.sslContext.keyStoreType=PKCS12
## The KeyStore provider.
# jetty.sslContext.keyStoreProvider=
## The KeyManager password.
# jetty.sslContext.keyManagerPassword=
## The TrustStore password.
# jetty.sslContext.trustStorePassword=
## The TrustStore type.
# jetty.sslContext.trustStoreType=PKCS12
## The TrustStore provider.
# jetty.sslContext.trustStoreProvider=
## Whether client certificate authentication is required.
# jetty.sslContext.needClientAuth=false
## Whether client certificate authentication is desired, but not required.
# jetty.sslContext.wantClientAuth=false
## Whether cipher order is significant.
# jetty.sslContext.useCipherSuitesOrder=true
## The SSLSession cache size.
# jetty.sslContext.sslSessionCacheSize=-1
## The SSLSession cache timeout (in seconds).
# jetty.sslContext.sslSessionTimeout=-1
## Whether TLS renegotiation is allowed.
# jetty.sslContext.renegotiationAllowed=true
## The max number of TLS renegotiations per connection.
# jetty.sslContext.renegotiationLimit=5</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-module-ssl-keystore-tls"><a class="anchor" href="#og-module-ssl-keystore-tls"></a><a class="link" href="#og-module-ssl-keystore-tls">KeyStore Properties and TLS Properties</a></h5>
<div class="paragraph">
<p>Among the configurable properties, the most relevant are:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.sslContext.keyStorePath</dt>
<dd>
<p>the KeyStore path on the file system.
If it is a relative path, it is relative to <code>$JETTY_BASE</code>.
Defaults to <code>$JETTY_BASE/etc/keystore.p12</code>.</p>
</dd>
<dt class="hdlist1"><code>jetty.sslContext.keyStorePassword</code></dt>
<dd>
<p>the KeyStore password, which you want to explicitly configure.
The password may be obfuscated with the <a href="#og-password">Jetty Password Tool</a>.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>If you need to configure client certificate authentication, you want to configure one of these properties (they are mutually exclusive):</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>jetty.sslContext.needClientAuth</code></dt>
<dd>
<p>whether client certificate authentication should be required.</p>
</dd>
<dt class="hdlist1"><code>jetty.sslContext.wantClientAuth</code></dt>
<dd>
<p>whether client certificate authentication should be requested.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>If you configure client certificate authentication, you need to configure and distribute a client KeyStore as explained in <a href="#og-keystore-client-authn">this section</a>.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-module-ssl-reload"><a class="anchor" href="#og-module-ssl-reload"></a><a class="link" href="#og-module-ssl-reload">Module <code>ssl-reload</code></a></h4>
<div class="paragraph">
<p>The <code>ssl-reload</code> module provides a periodic scanning of the directory where the KeyStore file resides.
When the scanning detects a change to the KeyStore file, the correspondent <code>SslContextFactory.Server</code> component is reloaded with the new KeyStore configuration.</p>
</div>
<div class="paragraph">
<p>The module properties are:</p>
</div>
<div class="listingblock">
<div class="content">
<pre># Monitored directory scan period, in seconds.
# jetty.sslContext.reload.scanInterval=1</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-module-test-keystore"><a class="anchor" href="#og-module-test-keystore"></a><a class="link" href="#og-module-test-keystore">Module <code>test-keystore</code></a></h4>
<div class="paragraph">
<p>The <code>test-keystore</code> module provides a KeyStore containing a self-signed certificate for domain <code>localhost</code>.</p>
</div>
<div class="paragraph">
<p>The module file is <code>$JETTY_HOME/modules/test-keystore.mod</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>[description]
Test keystore with test SSL Certificate.
DO NOT USE IN PRODUCTION!!!
[tags]
demo
ssl
[depend]
ssl
[files]
basehome:modules/test-keystore/test-keystore.p12|etc/test-keystore.p12
[ini]
jetty.sslContext.keyStorePath?=etc/test-keystore.p12
jetty.sslContext.trustStorePath?=etc/test-keystore.p12
jetty.sslContext.keyStoreType?=PKCS12
jetty.sslContext.keyStorePassword?=OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</pre>
</div>
</div>
<div class="paragraph">
<p>Note how properties <code>jetty.sslContext.keyStorePath</code> and <code>jetty.sslContext.keyStorePassword</code> are configured, only if not already set (via the <code>?=</code> operator), directly in the module file, rather than in a <code>*.ini</code> file.
This is done to avoid that these properties accidentally overwrite a real KeyStore configuration.</p>
</div>
</div>
<div class="sect3">
<h4 id="og-module-threadpool"><a class="anchor" href="#og-module-threadpool"></a><a class="link" href="#og-module-threadpool">Module <code>threadpool</code></a></h4>
<div class="paragraph">
<p>The <code>threadpool</code> module allows you to configure the server-wide thread pool.</p>
</div>
<div class="paragraph">
<p>The module file is <code>$JETTY_HOME/modules/threadpool.mod</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre># 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</pre>
</div>
</div>
<div class="paragraph">
<p>Among the configurable properties, the most relevant are:</p>
</div>
<div class="paragraph">
<p>TODO</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-xml"><a class="anchor" href="#og-xml"></a><a class="link" href="#og-xml">Jetty XML</a></h3>
<div class="paragraph">
<p>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.</p>
</div>
<div class="paragraph">
<p>The Jetty XML format is very similar to that of frameworks like Spring or Plexus, although it predates all of them and it&#8217;s typically more powerful as it can invoke any Java API.</p>
</div>
<div class="paragraph">
<p>The Jetty XML format is used in <a href="#og-modules">Jetty modules</a> to create the Jetty server components, as well as in <a href="#og-deploy">Jetty XML context files</a> to configure web applications, but it can be used to call any Java API.</p>
</div>
<div class="sect3">
<h4 id="og-xml-syntax"><a class="anchor" href="#og-xml-syntax"></a><a class="link" href="#og-xml-syntax">Jetty XML Syntax</a></h4>
<div class="paragraph">
<p>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 <a href="#og-modules">Jetty module system</a> and the <a href="#og-deploy">Jetty deploy system</a>.</p>
</div>
<div class="paragraph">
<p>The Jetty XML elements define attributes such as <code>id</code>, <code>name</code>, <code>class</code>, etc. that may be replaced by correspondent elements, so that these XML documents are equivalent:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;Get id="stderr" class="java.lang.System" name="err"&gt;
&lt;Call name="println" arg="HELLO" /&gt;
&lt;/Get&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;Get&gt;
&lt;Id&gt;stderr&lt;/Id&gt;
&lt;Name&gt;err&lt;/Name&gt;
&lt;Class&gt;java.lang.System&lt;/Class&gt;
&lt;Call&gt;
&lt;Name&gt;println&lt;/Name&gt;
&lt;Arg&gt;HELLO&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Get&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>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&#8217;s where elements gives you the required flexibility.</p>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-configure"><a class="anchor" href="#og-xml-syntax-configure"></a><a class="link" href="#og-xml-syntax-configure"><code>&lt;Configure&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>Configure</code> must be the root element of the XML document.</p>
</div>
<div class="paragraph">
<p>The following Jetty XML creates an empty <code>String</code> and assigns it the id <code>mystring</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure id="mystring" class="java.lang.String" /&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>This is equivalent to the following Java code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">var mystring = new String();</code></pre>
</div>
</div>
<div class="paragraph">
<p>If an object with the id <code>mystring</code> already exists, then it is not created again but rather just referenced.</p>
</div>
<div class="paragraph">
<p>Typically the <code>&lt;Configure&gt;</code> element is used to configure a <code>Server</code> instance or <code>ContextHandler</code> subclasses such as <code>WebAppContext</code> that represent web applications.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-arg"><a class="anchor" href="#og-xml-syntax-arg"></a><a class="link" href="#og-xml-syntax-arg"><code>&lt;Arg&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>Arg</code> is used to pass arguments to <a href="#og-xml-syntax-new">constructors</a> and <a href="#og-xml-syntax-call">method calls</a>.</p>
</div>
<div class="paragraph">
<p>The following example creates a minimal Jetty <code>Server</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.server.Server"&gt;
&lt;Arg type="int"&gt;8080&lt;/Arg&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Arguments may have a <code>type</code> attribute that explicitly performs <a href="#og-xml-syntax-types">type coercion</a>.</p>
</div>
<div class="paragraph">
<p>Arguments may also have a <code>name</code> attribute, which is matched with the corresponding Java annotation in the source class, that helps to identify arguments:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.server.Server"&gt;
&lt;Arg name="port" type="int"&gt;8080&lt;/Arg&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-new"><a class="anchor" href="#og-xml-syntax-new"></a><a class="link" href="#og-xml-syntax-new"><code>&lt;New&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;New&gt;</code> creates a new object of the type specified by the mandatory <code>class</code> attribute.
A sequence of <code>Arg</code> elements, that must be contiguous and before other elements, may be present to specify the constructor arguments.</p>
</div>
<div class="paragraph">
<p>Within element <code>&lt;New&gt;</code> the newly created object is in <a href="#og-xml-syntax-scope">scope</a> and may be the implicit target of other, nested, elements.</p>
</div>
<div class="paragraph">
<p>The following example creates an <code>ArrayList</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;New id="mylist" class="java.util.ArrayList"&gt;
&lt;Arg type="int"&gt;16&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>This is equivalent to the following Java code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">var mylist = new ArrayList(16);</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-call"><a class="anchor" href="#og-xml-syntax-call"></a><a class="link" href="#og-xml-syntax-call"><code>&lt;Call&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;Call&gt;</code> invokes a method specified by the mandatory <code>name</code> attribute.
A sequence of <code>Arg</code> elements, that must be contiguous and before other elements, may be present to specify the method arguments.</p>
</div>
<div class="paragraph">
<p>Within element <code>&lt;Call&gt;</code> the return value, if the return type is not <code>void</code>, is in <a href="#og-xml-syntax-scope">scope</a> and may be the implicit target of other, nested, elements.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;New class="java.util.ArrayList"&gt;
&lt;Call name="listIterator"&gt;
&lt;Arg type="int"&gt;0&lt;/Arg&gt;
&lt;/Call&gt;
&lt;Call name="next" /&gt;
&lt;/New&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>This is equivalent to the following Java code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">new ArrayList().listIterator(0).next();</code></pre>
</div>
</div>
<div class="paragraph">
<p>It is possible to call <code>static</code> methods by specifying the <code>class</code> attribute:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;Call id="myhost" name="getByName" class="java.net.InetAddress"&gt;
&lt;Arg&gt;jdk.java.net&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>This is equivalent to the following Java code:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-java" data-lang="java">var myhost = InetAddress.getByName("jdk.java.net");</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-get"><a class="anchor" href="#og-xml-syntax-get"></a><a class="link" href="#og-xml-syntax-get"><code>&lt;Get&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;Get&gt;</code> retrieves the value of a JavaBean property specified by the mandatory <code>name</code> attribute.</p>
</div>
<div class="paragraph">
<p>If the JavaBean property is <code>foo</code> (or <code>Foo</code>), <code>&lt;Get&gt;</code> first attempts to invoke <em>method</em> <code>getFoo()</code>; failing that, attempts to retrieve the value from <em>field</em> <code>foo</code> (or <code>Foo</code>).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure id="server" class="org.eclipse.jetty.server.Server"&gt;
&lt;!-- Invokes getter method server.getVersion() --&gt;
&lt;Get id="version" name="version" /&gt;
&lt;!-- Gets the System.err field --&gt;
&lt;Get class="java.lang.System" name="err"&gt;
&lt;Call name="println"&gt;
&lt;Arg&gt;Jetty&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Get&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-set"><a class="anchor" href="#og-xml-syntax-set"></a><a class="link" href="#og-xml-syntax-set"><code>&lt;Set&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;Set&gt;</code> stores the value of a JavaBean property specified by the mandatory <code>name</code> attribute.</p>
</div>
<div class="paragraph">
<p>If the JavaBean property is <code>foo</code> (or <code>Foo</code>), <code>&lt;Set&gt;</code> first attempts to invoke <em>method</em> <code>setFoo(&#8230;&#8203;)</code> with the value in the <a href="#og-xml-syntax-scope">scope</a> as argument; failing that, attempts to store the value in the scope to <em>field</em> <code>foo</code> (or <code>Foo</code>).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure id="server" class="org.eclipse.jetty.server.Server"&gt;
&lt;!-- The value in the &lt;Set&gt; scope is the string "true" --&gt;
&lt;Set name="dryRun"&gt;true&lt;/Set&gt;
&lt;!-- The value in the &lt;Set&gt; scope is the instance created by &lt;New&gt; --&gt;
&lt;Set name="requestLog"&gt;
&lt;New class="org.eclipse.jetty.server.CustomRequestLog" /&gt;
&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-map"><a class="anchor" href="#og-xml-syntax-map"></a><a class="link" href="#og-xml-syntax-map"><code>&lt;Map&gt;</code> and <code>&lt;Entry&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;Map&gt;</code> allows the creation of a new <code>java.util.Map</code> implementation, specified by the <code>class</code> attribute&#8201;&#8212;&#8201;by default a <code>HashMap</code>.</p>
</div>
<div class="paragraph">
<p>The map entries are specified with a sequence of <code>&lt;Entry&gt;</code> elements, each with exactly 2 <code>&lt;Item&gt;</code> elements, for example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;Map class="java.util.concurrent.ConcurrentHashMap"&gt;
&lt;Entry&gt;
&lt;Item&gt;host&lt;/Item&gt;
&lt;Item&gt;
&lt;Call class="java.net.InetAddress" name="getByName"&gt;
&lt;Arg&gt;localhost&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Item&gt;
&lt;/Entry&gt;
&lt;/Map&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-put"><a class="anchor" href="#og-xml-syntax-put"></a><a class="link" href="#og-xml-syntax-put"><code>&lt;Put&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;Put&gt;</code> is a convenience element that puts a key/value pair into objects that implement <code>java.util.Map</code>.
You can only specify the key value via the <code>name</code> attribute, so the key can only be a literal string (for keys that are not literal strings, use the <code>&lt;Call&gt;</code> element).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;New class="java.util.Properties"&gt;
&lt;Put name="host"&gt;
&lt;Call class="java.net.InetAddress" name="getByName"&gt;
&lt;Arg&gt;localhost&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Put&gt;
&lt;/New&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-array"><a class="anchor" href="#og-xml-syntax-array"></a><a class="link" href="#og-xml-syntax-array"><code>&lt;Array&gt;</code> and <code>&lt;Item&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;Array&gt;</code> creates a new array, whose component type may be specified by the <code>type</code> attribute.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure&gt;
&lt;Array type="java.lang.Object"&gt;
&lt;Item /&gt; &lt;!-- null --&gt;
&lt;Item&gt;literalString&lt;/Item&gt;
&lt;Item type="String"&gt;&lt;/Item&gt; &lt;!-- empty string --&gt;
&lt;Item type="Double"&gt;1.0D&lt;/Item&gt;
&lt;Item&gt;
&lt;New class="java.lang.Exception" /&gt;
&lt;/Item&gt;
&lt;/Array&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-ref"><a class="anchor" href="#og-xml-syntax-ref"></a><a class="link" href="#og-xml-syntax-ref"><code>&lt;Ref&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;Ref&gt;</code> allows you to reference an object via the <code>refid</code> attribute`, putting it into <a href="#og-xml-syntax-scope">scope</a> so that nested elements can operate on it.
You must give a unique <code>id</code> attribute to the objects you want to reference.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;!-- The Jetty Server has id="server" --&gt;
&lt;Configure id="server" class="org.eclipse.jetty.server.Server"&gt;
&lt;Get class="java.lang.System" name="err"&gt;
&lt;!-- Here the System.err field is in scope, but you
want to operate on the server to get its version --&gt;
&lt;Ref refid="server"&gt;
&lt;!-- Store the server version under id="myversion" --&gt;
&lt;Get id="myversion" name="version" /&gt;
&lt;/Ref&gt;
&lt;Call name="println"&gt;
&lt;!-- Reference the server version stored above --&gt;
&lt;Arg&gt;Server version is: &lt;Ref refid="myversion" /&gt;&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Get&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-property"><a class="anchor" href="#og-xml-syntax-property"></a><a class="link" href="#og-xml-syntax-property"><code>&lt;Property&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;Property&gt;</code> retrieves the value of the Jetty module property specified by the <code>name</code> attribute, and it is mostly used when creating <a href="#og-modules">custom Jetty modules</a> or when using <a href="#og-deploy-jetty">Jetty context XML files</a>.</p>
</div>
<div class="paragraph">
<p>The <code>deprecated</code> attribute allows you to specify a comma separated list of old, deprecated, property names for backward compatibility.</p>
</div>
<div class="paragraph">
<p>The <code>default</code> attribute allows you to specify a default value for the property, if it has not been explicitly defined.</p>
</div>
<div class="paragraph">
<p>For example, you may want to configure the context path of your web application in this way:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="contextPath"&gt;
<mark>&lt;Property name="com.myapps.mywiki.context.path" default="/wiki" /&gt;</mark>
&lt;/Set&gt;
&lt;Set name="war"&gt;/opt/myapps/mywiki.war&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>contextPath</code> value is resolved by looking for the Jetty module property <code>com.myapps.mywiki.context.path</code>; if this property is not set, then the default value of <code>/wiki</code> is used.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-system-property"><a class="anchor" href="#og-xml-syntax-system-property"></a><a class="link" href="#og-xml-syntax-system-property"><code>&lt;SystemProperty&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;SystemProperty&gt;</code> retrieves the value of the JVM system property specified by the <code>name</code> attribute, via <code>System.getProperty(&#8230;&#8203;)</code>.</p>
</div>
<div class="paragraph">
<p>The <code>deprecated</code> attribute allows you to specify a comma separated list of old, deprecated, system property names for backward compatibility.</p>
</div>
<div class="paragraph">
<p>The <code>default</code> attribute allows you to specify a default value for the system property value, if it has not been explicitly defined.</p>
</div>
<div class="paragraph">
<p>The following example creates a minimal Jetty <code>Server</code> that listens on a port specified by the <code>com.acme.http.port</code> system property:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure id="server" class="org.eclipse.jetty.server.Server"&gt;
&lt;Arg type="int"&gt;
&lt;SystemProperty name="com.acme.http.port" default="8080" /&gt;
&lt;/Arg&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-env"><a class="anchor" href="#og-xml-syntax-env"></a><a class="link" href="#og-xml-syntax-env"><code>&lt;Env&gt;</code></a></h5>
<div class="paragraph">
<p>Element <code>&lt;Env&gt;</code> retrieves the value of the environment variable specified by the <code>name</code> attribute, via <code>System.getenv(&#8230;&#8203;)</code>.</p>
</div>
<div class="paragraph">
<p>The <code>deprecated</code> attribute allows you to specify a comma separated list of old, deprecated, environment variable names for backward compatibility.</p>
</div>
<div class="paragraph">
<p>The <code>default</code> attribute allows you to specify a default value for the environment variable value, if it has not been explicitly defined.</p>
</div>
<div class="paragraph">
<p>The following example creates a minimal Jetty <code>Server</code> that listens on a port specified by the <code>COM_ACME_HTTP_PORT</code> environment variable:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure id="server" class="org.eclipse.jetty.server.Server"&gt;
&lt;Arg type="int"&gt;
&lt;Env name="COM_ACME_HTTP_PORT" default="8080" /&gt;
&lt;/Arg&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-types"><a class="anchor" href="#og-xml-syntax-types"></a><a class="link" href="#og-xml-syntax-types">Type Coercion</a></h5>
<div class="paragraph">
<p>Elements that have the <code>type</code> attribute explicitly perform the type coercion of the string value present in the XML document to the Java type specified by the <code>type</code> attribute.</p>
</div>
<div class="paragraph">
<p>Supported types are the following:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>all primitive types and their boxed equivalents, for example <code>type="int"</code> but also <code>type="Integer"</code> (short form) and <code>type="java.lang.Integer"</code> (fully qualified form)</p>
</li>
<li>
<p><code>java.lang.String</code>, in both short form and fully qualified form</p>
</li>
<li>
<p><code>java.net.URL</code>, in both short form and fully qualified form</p>
</li>
<li>
<p><code>java.net.InetAddress</code>, in both short form and fully qualified form</p>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="og-xml-syntax-scope"><a class="anchor" href="#og-xml-syntax-scope"></a><a class="link" href="#og-xml-syntax-scope">Scopes</a></h5>
<div class="paragraph">
<p>Elements that create new objects or that return a value create a <em>scope</em>.
Within these elements there may be nested elements that will operate on that scope, i.e. on the new object or returned value.</p>
</div>
<div class="paragraph">
<p>The following example illustrates how scopes work:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure id="server" class="org.eclipse.jetty.server.Server"&gt;
&lt;Arg type="int"&gt;8080&lt;/Arg&gt;
&lt;!-- Here the Server object has been created and is in scope --&gt;
&lt;!-- Calls the setter on the Server object that is in scope --&gt;
&lt;Set name="stopTimeout"&gt;5000&lt;/Set&gt;
&lt;!-- Creates a new object --&gt;
&lt;New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration"&gt;
&lt;!-- Here the HttpConfiguration just created is in a nested scope --&gt;
&lt;!-- Calls the setter on the HttpConfiguration object that is in scope --&gt;
&lt;Set name="secureScheme"&gt;https&lt;/Set&gt;
&lt;/New&gt;
&lt;!-- Calls the getter on the Server object that is in scope --&gt;
&lt;Get name="ThreadPool"&gt;
&lt;!-- Here the ThreadPool object returned by the getter is in a nested scope --&gt;
&lt;!-- Calls the setter on the ThreadPool object that is in scope --&gt;
&lt;Set name="maxThreads" type="int"&gt;256&lt;/Set&gt;
&lt;/Get&gt;
&lt;!-- Gets the System.err field --&gt;
&lt;Get class="java.lang.System" name="err"&gt;
&lt;!-- Here the System.err object is in scope --&gt;
&lt;!-- Equivalent to: var myversion = server.getVersion() --&gt;
&lt;Ref refid="server"&gt;
&lt;!-- Here the "server" object is in scope --&gt;
&lt;Get id="myversion" name="version" /&gt;
&lt;/Ref&gt;
&lt;!-- Calls println() on the System.err object --&gt;
&lt;Call name="println"&gt;
&lt;Arg&gt;Server version is: &lt;Ref refid="myversion" /&gt;&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Get&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-sessions"><a class="anchor" href="#og-sessions"></a><a class="link" href="#og-sessions">HTTP Session Management</a></h3>
<div class="paragraph">
<p>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.</p>
</div>
<div class="sect3">
<h4 id="og-session-overview"><a class="anchor" href="#og-session-overview"></a><a class="link" href="#og-session-overview">HTTP Session Overview</a></h4>
<div class="sect4">
<h5 id="og-terminology"><a class="anchor" href="#og-terminology"></a><a class="link" href="#og-terminology">Terminology</a></h5>
<div class="paragraph">
<p>Before diving into the specifics of how to plug-in and configure various alternative HTTP session management modules, let&#8217;s review some useful terminology:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Session</dt>
<dd>
<p>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.</p>
</dd>
<dt class="hdlist1">SessionIdManager</dt>
<dd>
<p>is responsible for allocating session ids.
A Jetty server can have at most 1 SessionIdManager.</p>
</dd>
<dt class="hdlist1">HouseKeeper</dt>
<dd>
<p>is responsible for periodically orchestrating the removal of expired sessions.
This process is referred to as <a href="#og-session-base-scavenge">"scavenging"</a>.</p>
</dd>
<dt class="hdlist1">SessionHandler</dt>
<dd>
<p>is responsible for managing the lifecycle of sessions.
A context can have at most 1 <code>SessionHandler</code>.</p>
</dd>
<dt class="hdlist1">SessionCache</dt>
<dd>
<p>is a L1 cache of in-use session objects.
The <code>SessionCache</code> is used by the <code>SessionHandler</code>.</p>
</dd>
<dt class="hdlist1">SessionDataStore</dt>
<dd>
<p>is responsible for all clustering/persistence operations on sessions.
A <code>SessionCache</code> uses a <code>SessionDataStore</code> as a backing store.</p>
</dd>
<dt class="hdlist1">CachingSessionDataStore</dt>
<dd>
<p>is an L2 cache of session data.
A <code>SessionCache</code> can use a <code>CachingSessionDataStore</code> as its backing store.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>More details on these concepts can be found in the <a href="../programming-guide/index.html/server/sessions/sessions">Programming Guide</a>.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p><code>SessionDataStore</code>s implementations interact with other, usually third party, systems responsible for storing and/or distributing session information.
Sessions can be distributed without being persisted.
They can also be persisted without being distributed.
Because persisting session information to a shared store is a very common way of distributing (also known as "clustering") sessions, in the documentation we will often refer to just "persisting".</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="og-session-modules"><a class="anchor" href="#og-session-modules"></a><a class="link" href="#og-session-modules">Session Modules</a></h5>
<div class="paragraph">
<p>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.</p>
</div>
<div class="paragraph">
<p>For example, Jetty ships with two alternative implementations of the <code>SessionCache</code>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>one that caches sessions in memory: <a href="#og-session-cache-hash"><code>session-cache-hash</code></a></p>
</li>
<li>
<p>one that does not actually cache: <a href="#og-session-cache-null"><code>session-cache-null</code></a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>There are at least 6 alternative implementations of the <code>SessionDataStore</code> that you can use to persist/distribute your http sessions:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>file system storage: <a href="#og-session-filesystem"><code>session-store-file</code></a></p>
</li>
<li>
<p>relational database storage: <a href="#og-session-jdbc"><code>session-store-jdbc</code></a></p>
</li>
<li>
<p>NoSQL database storage: <a href="#og-session-mongo"><code>session-store-mongo</code></a></p>
</li>
<li>
<p>Google Cloud datastore storage: <a href="#og-session-gcloud"><code>session-store-gcloud</code></a></p>
</li>
<li>
<p>Hazelcast: <a href="#og-session-hazelcast-remote"><code>session-store-hazelcast-remote</code></a> or <a href="#og-session-hazelcast-embedded"><code>session-store-hazelcast-embedded</code></a></p>
</li>
<li>
<p>Infinispan: <a href="#og-session-infinispan"><code>session-store-infinispan-remote</code></a> or <a href="#og-session-infinispan-embedded"><code>session-store-infinispan-embedded</code></a></p>
</li>
</ul>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
It is worth noting that if you do not configure <em>any</em> session modules, Jetty will still provide HTTP sessions that are cached in memory but are never persisted.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-session-base"><a class="anchor" href="#og-session-base"></a><a class="link" href="#og-session-base">The Base Session Module</a></h4>
<div class="paragraph">
<p>The <code>sessions</code> module is the base module that all other session modules depend upon.
As such it will be <em>transitively</em> enabled if you enable any of the other session modules: you need to <em>explicitly</em> enable it if you wish to <em>change</em> any settings from their defaults.</p>
</div>
<div class="paragraph">
<p>Enabling the <code>sessions</code> module puts the <code>$JETTY_HOME/etc/sessions/id-manager.xml</code> file onto the execution path and generates a <code>$JETTY_BASE/start.d/sessions.ini</code> file.</p>
</div>
<div class="paragraph">
<p>The <code>id-manager.xml</code> file instantiates a <code>DefaultSessionIdManager</code> and <code>HouseKeeper</code>.
The former is used to generate and manage session ids whilst the latter is responsible for periodic <a href="#og-session-base-scavenge">scavenging</a> of expired sessions.</p>
</div>
<div class="sect4">
<h5 id="og-configuration"><a class="anchor" href="#og-configuration"></a><a class="link" href="#og-configuration">Configuration</a></h5>
<div class="paragraph">
<p>The <code>$JETTY_BASE/start.d/sessions.ini</code> file contains these configuration properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.sessionIdManager.workerName</dt>
<dd>
<p>This uniquely identifies the jetty server instance and is applied to the <code>SessionIdManager</code>.
You can either provide a value for this property, or you can allow Jetty to try and synthesize a <code>workerName</code> - the latter option is <em>only</em> advisable in the case of a single, non-clustered deployment.
There are two ways a default <code>workerName</code> can be synthesized:</p>
<div class="ulist">
<ul>
<li>
<p>if running on Google AppEngine, the <code>workerName</code> will be formed by concatenating the values of the environment variables <code>JETTY_WORKER_INSTANCE</code> and <code>GAE_MODULE_INSTANCE</code></p>
</li>
<li>
<p>otherwise, the <code>workerName</code> will be formed by concatenating the environment variable <code>JETTY_WORKER_INSTANCE</code> and the literal <code>0</code>.</p>
</li>
</ul>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>So, if you&#8217;re not running on Google AppEngine, and you haven&#8217;t configured one, the workerName will always be: <code>node0</code>.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
If you have more than one Jetty instance, it is <strong>crucial</strong> that you configure the <code>workerName</code> differently for each instance.
</td>
</tr>
</table>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.sessionScavengeInterval.seconds</dt>
<dd>
<p>This is the period in <em>seconds</em> between runs of the <code>HouseKeeper</code>, 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 <a href="#og-session-base-scavenge">scavenge</a> interval is shorter than the <code>&lt;session-timeout&gt;</code> of your sessions to ensure that they are promptly scavenged.
On the other hand, if you have a backend store configured for your sessions, <a href="#og-session-base-scavenge">scavenging</a> too frequently can increase the load on it.</p>
</dd>
</dl>
</div>
<div class="admonitionblock caution">
<table>
<tr>
<td class="icon">
<i class="fa icon-caution" title="Caution"></i>
</td>
<td class="content">
Don&#8217;t forget that the <code>&lt;session-timeout&gt;</code> is specified in <code>web.xml</code> in <em>minutes</em> and the value of the <code>jetty.sessionScavengeInterval.seconds</code> is in <em>seconds</em>.
</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="og-session-base-scavenge"><a class="anchor" href="#og-session-base-scavenge"></a><a class="link" href="#og-session-base-scavenge">Session Scavenging</a></h5>
<div class="paragraph">
<p>The <code>HouseKeeper</code> is responsible for the periodic initiation of session scavenge cycles.
The <code>jetty.sessionScavengeInterval.seconds</code> property in <code>$JETTY_BASE/start.d/sessions.ini</code> controls the periodicity of the cycle.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The HouseKeeper semi-randomly adds an additional 10% to the configured <code>sessionScavengeInterval</code>.
This is to prevent multiple nodes in a cluster that are all started at once from syncing up scavenge cycles and placing extra load on the configured persistence mechanism.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>A session whose expiry time has been exceeded is considered eligible for scavenging.
The session might be present in a <code>SessionCache</code> and/or present in the session persistence/clustering mechanism.</p>
</div>
<div class="paragraph">
<p>Scavenging occurs for all contexts on a server at every cycle.
The <code>HouseKeeper</code> sequentially asks the <code>SessionHandler</code> in each context to find and remove expired sessions.
The <code>SessionHandler</code> works with the <code>SessionDataStore</code> to evaluate candidates for expiry held in the <code>SessionCache</code>, and also to sweep the persistence mechanism to find expired sessions.</p>
</div>
<div class="paragraph">
<p>The sweep takes two forms: once per cycle the <code>SessionDataStore</code> searches for sessions for its own context that have expired; infrequently, the <code>SessionDataStore</code> will widen the search to expired sessions in all contexts.
The former finds sessions that are no longer in this context&#8217;s <code>SessionCache</code>, and using some heuristics, are unlikely to be in the <code>SessionCache</code> of the same context on another node either.
These sessions will be loaded and fully expired, meaning that <code>HttpSessionListener.destroy()</code> 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 <code>HttpSessionListener.destroy()</code> being called.</p>
</div>
<div class="paragraph">
<p>A combination of these sweeps should ensure that the persistence mechanism does not fill over time with expired sessions.</p>
</div>
<div class="paragraph">
<p>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.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-session-cache"><a class="anchor" href="#og-session-cache"></a><a class="link" href="#og-session-cache">Modules for HTTP Session Caching</a></h4>
<div class="paragraph">
<p>In this section we will look at the alternatives for the <code>SessionCache</code>, 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.</p>
</div>
<div class="paragraph">
<p>The <a href="#og-session-usecases">scenarios</a> go into more detail on this.</p>
</div>
<div class="sect4">
<h5 id="og-session-cache-hash"><a class="anchor" href="#og-session-cache-hash"></a><a class="link" href="#og-session-cache-hash">Caching in Memory</a></h5>
<div class="paragraph">
<p>If you wish to change any of the default configuration values you should enable the <code>session-cache-hash</code> <a href="#startup-modules">module</a>.
The name <code>"hash"</code> harks back to historical Jetty session implementations, whereby sessions were kept in memory using a HashMap.</p>
</div>
<div class="sect5">
<h6 id="og-configuration-2"><a class="anchor" href="#og-configuration-2"></a><a class="link" href="#og-configuration-2">Configuration</a></h6>
<div class="paragraph">
<p>The <code>$JETTY_BASE/start.d/session-cache-hash.ini</code> contains the following configurable properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.evictionPolicy</dt>
<dd>
<p>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 <code>SessionDataStore</code> that persists sessions.
The eviction strategies and their corresponding values are:</p>
<div class="dlist">
<dl>
<dt class="hdlist1">-1 (NO EVICTION)</dt>
<dd>
<p>sessions are never evicted from the cache.
The only way they leave are via expiration or invalidation.</p>
</dd>
<dt class="hdlist1">0 (EVICT AFTER USE)</dt>
<dd>
<p>sessions are evicted from the cache as soon as the last active request for it finishes.
The session will be passed to the <code>SessionDataStore</code> to be written out before eviction.</p>
</dd>
<dt class="hdlist1">&gt;= 1 (EVICT ON INACTIVITY)</dt>
<dd>
<p>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 <code>jetty.session.saveOnInactiveEvict</code> property to force a session write before eviction.</p>
</dd>
</dl>
</div>
</dd>
</dl>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
If you are not using one of the session store modules, ie one of the <code>session-store-xxxx</code>s, then sessions will be lost when the context is stopped, or the session is evicted.
</td>
</tr>
</table>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.saveOnInactiveEvict</dt>
<dd>
<p>Boolean, default <code>false</code>.
This controls whether a session will be persisted to the <code>SessionDataStore</code> if it is being evicted due to the EVICT ON INACTIVITY policy.
Usually sessions will be written to the <code>SessionDataStore</code> whenever the last simultaneous request exits the session.
However, as <code>SessionDataStores</code> can be configured to skip some writes (see the documentation for the <code>session-store-xxx</code> module that you are using), this option is provided to ensure that the session will be written out.</p>
</dd>
</dl>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
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.
</td>
</tr>
</table>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.saveOnCreate</dt>
<dd>
<p>Boolean, default <code>false</code>.
Controls whether a session that is newly created will be immediately saved to the <code>SessionDataStore</code> or 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.</p>
</dd>
<dt class="hdlist1">jetty.session.removeUnloadableSessions</dt>
<dd>
<p>Boolean, default <code>false</code>.
Controls whether the session cache should ask a <code>SessionDataStore</code> to delete a session that cannot be restored - for example because it is corrupted.</p>
</dd>
<dt class="hdlist1">jetty.session.flushOnResponseCommit</dt>
<dd>
<p>Boolean, default <code>false</code>.
If true, if a session is "dirty" - ie its attributes have changed - it will be written to the <code>SessionDataStore</code> 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.</p>
</dd>
<dt class="hdlist1">jetty.session.invalidateOnShutdown</dt>
<dd>
<p>Boolean, default <code>false</code>.
If true, when a context is shutdown, all sessions in the cache are invalidated and deleted both from the cache and from the <code>SessionDataStore</code>.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-session-cache-null"><a class="anchor" href="#og-session-cache-null"></a><a class="link" href="#og-session-cache-null">No Caching</a></h5>
<div class="paragraph">
<p>You may need to use the <code>session-cache-null</code> 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&#8217;t enable a module that provides session persistence (ie one of the <code>session-store-xxx</code> modules), then sessions will <em>neither</em> be retained in memory <em>nor</em> persisted.</p>
</div>
<div class="sect5">
<h6 id="og-configuration-3"><a class="anchor" href="#og-configuration-3"></a><a class="link" href="#og-configuration-3">Configuration</a></h6>
<div class="paragraph">
<p>The <code>$JETTY_BASE/start.d/session-cache-null.ini</code> contains the following configurable properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.saveOnCreate</dt>
<dd>
<p>Boolean, default <code>false</code>.
Controls whether a session that is newly created will be immediately saved to the <code>SessionDataStore</code> or 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.</p>
</dd>
<dt class="hdlist1">jetty.session.removeUnloadableSessions</dt>
<dd>
<p>Boolean, default <code>false</code>.
Controls whether the session cache should ask a <code>SessionDataStore</code> to delete a session that cannot be restored - for example because it is corrupted.</p>
</dd>
<dt class="hdlist1">jetty.session.flushOnResponseCommit</dt>
<dd>
<p>Boolean, default <code>false</code>.
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.</p>
</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-session-filesystem"><a class="anchor" href="#og-session-filesystem"></a><a class="link" href="#og-session-filesystem">Modules for Persistent HTTP Sessions: File System</a></h4>
<div class="paragraph">
<p>The <code>session-store-file</code> Jetty module supports persistent storage of session data in a filesystem.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
Persisting sessions to the local file system should <strong>never</strong> be used in a clustered environment.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Enabling this module creates the <code>$JETTY_BASE/sessions</code> directory.
By default session data will be saved to this directory, one file representing each session.</p>
</div>
<div class="paragraph">
<p>File names follow this pattern:</p>
</div>
<div class="paragraph">
<p><code>[expiry]_[contextpath]_[virtualhost]_[id]</code></p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">expiry</dt>
<dd>
<p>This is the expiry time in milliseconds since the epoch.</p>
</dd>
<dt class="hdlist1">contextpath</dt>
<dd>
<p>This is the context path with any special characters, including <code>/</code>, replaced by the <code><em></code> underscore character.
For example, a context path of <code>/catalog</code> would become <code>_catalog</code>.
A context path of simply <code>/</code> becomes just <code>_</em></code>.</p>
</dd>
<dt class="hdlist1">virtualhost</dt>
<dd>
<p>This is the first virtual host associated with the context and has the form of 4 digits separated by <code>.</code> characters: <code>[digit].[digit].[digit].[digit]</code>.
If there are no virtual hosts associated with a context, then <code>0.0.0.0</code> is used.</p>
</dd>
<dt class="hdlist1">id</dt>
<dd>
<p>This is the unique id of the session.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Putting all of the above together as an example, a session with an id of <code>node0ek3vx7x2y1e7pmi3z00uqj1k0</code> for the context with path <code>/test</code> with no virtual hosts and an expiry of <code>1599558193150</code> would have a file name of:</p>
</div>
<div class="paragraph">
<p><code>1599558193150__test_0.0.0.0_node0ek3vx7x2y1e7pmi3z00uqj1k0</code></p>
</div>
<div class="sect4">
<h5 id="og-configuration-4"><a class="anchor" href="#og-configuration-4"></a><a class="link" href="#og-configuration-4">Configuration</a></h5>
<div class="paragraph">
<p>The <code>$JETTY_BASE/start.d/sessions.ini</code> file contains the following properties which may be modified to customise filesystem session storage:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.storeDir</dt>
<dd>
<p>The default is <code>$JETTY_BASE/sessions</code>.
This is a path that defines the location for storage of session files.</p>
</dd>
<dt class="hdlist1">jetty.session.file.deleteUnrestorableFiles</dt>
<dd>
<p>Boolean, default <code>false</code>.
If set to <code>true</code>, 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.</p>
</dd>
<dt class="hdlist1">jetty.session.gracePeriod.seconds</dt>
<dd>
<p>Integer, default 3600.
Used during session <a href="#og-session-base-scavenge">scavenging</a>.
Multiples of this period are used to define how long ago a stored session must have expired before it should be <a href="#og-session-base-scavenge">scavenged</a>.</p>
</dd>
<dt class="hdlist1">jetty.session.savePeriod.seconds</dt>
<dd>
<p>Integer, in seconds, default is <code>0</code>.
Whenever a session is accessed by a request, its <code>lastAccessTime</code> and <code>expiry</code> are updated.
Even if your sessions are read-mostly, the <code>lastAccessTime</code> and <code>expiry</code> will 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.</p>
</dd>
</dl>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>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 <code>expiry</code> time thus making it appear to other nodes that it has expired.
Thorough consideration of the <code>maxIdleTime</code> of the session when setting the <code>savePeriod</code> is imperative - it would be undesirable to set a <code>savePeriod</code> that is larger than the <code>maxIdleTime</code>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-session-jdbc"><a class="anchor" href="#og-session-jdbc"></a><a class="link" href="#og-session-jdbc">Modules for Persistent HTTP Sessions: JDBC</a></h4>
<div class="paragraph">
<p>Enabling the <code>session-store-jdbc</code> module configures Jetty to persist session data in a relational database.</p>
</div>
<div class="sect4">
<h5 id="og-configuration-5"><a class="anchor" href="#og-configuration-5"></a><a class="link" href="#og-configuration-5">Configuration</a></h5>
<div class="paragraph">
<p>After enabling the module, the <code>$JETTY_BASE/start.d/session-store-jdbc.ini</code> file contains the following customizable properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.gracePeriod.seconds</dt>
<dd>
<p>Integer, default 3600.
Used during session <a href="#og-session-base-scavenge">scavenging</a>.
Multiples of this period are used to define how long ago a stored session must have expired before it should be <a href="#og-session-base-scavenge">scavenged</a>.</p>
</dd>
<dt class="hdlist1">jetty.session.savePeriod.seconds</dt>
<dd>
<p>Integer, in seconds, default is <code>0</code>.
Whenever a session is accessed by a request, its <code>lastAccessTime</code> and <code>expiry</code> are updated.
Even if your sessions are read-mostly, the <code>lastAccessTime</code> and <code>expiry</code> will 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.</p>
</dd>
</dl>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>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 <code>expiry</code> time thus making it appear to other nodes that it has expired.
Thorough consideration of the <code>maxIdleTime</code> of the session when setting the <code>savePeriod</code> is imperative - it would be undesirable to set a <code>savePeriod</code> that is larger than the <code>maxIdleTime</code>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">db-connection-type</dt>
<dd>
<p>Default <code>datasource</code>.
Set to either <code>datasource</code> or <code>driver</code> depending on the type of connection being used.
Depending which you select, there are additional properties available:</p>
<div class="dlist">
<dl>
<dt class="hdlist1"><code>datasource</code></dt>
<dd>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.jdbc.datasourceName</dt>
<dd>
<p>Name of the remote datasource.</p>
</dd>
</dl>
</div>
</dd>
<dt class="hdlist1"><code>driver</code></dt>
<dd>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.jdbc.driverClass</dt>
<dd>
<p>Name of the JDBC driver that controls access to the remote database, such as <code>com.mysql.jdbc.Driver</code></p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.driverUrl</dt>
<dd>
<p>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: <code>jdbc:mysql://127.0.0.1:3306/sessions?user=sessionsadmin</code>.</p>
</dd>
</dl>
</div>
</dd>
</dl>
</div>
</dd>
<dt class="hdlist1">jetty.session.jdbc.blobType</dt>
<dd>
<p>Optional.
Default <code>blob</code> or <code>bytea</code> for 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.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.longType</dt>
<dd>
<p>Optional.
Default <code>bigint</code> or <code>number(20)</code> 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.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.stringType</dt>
<dd>
<p>Optional.
Default <code>varchar</code>.
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.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.schemaName</dt>
<dt class="hdlist1">jetty.session.jdbc.schema.catalogName</dt>
<dd>
<p>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 <a href="https://en.wikipedia.org/wiki/Database_schema" class="bare">https://en.wikipedia.org/wiki/Database_schema</a> and <a href="https://en.wikipedia.org/wiki/Database_catalog" class="bare">https://en.wikipedia.org/wiki/Database_catalog</a>.
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 <code>db-connection-type</code> you have configured).
To set them explicitly, uncomment and supply appropriate values for the <code>jetty.session.jdbc.schema.schemaName</code> and/or <code>jetty.session.jdbc.schema.catalogName</code> properties.
Alternatively, to allow Jetty to infer them from a database connection, use the special string <code>INFERRED</code> instead.
If you leave them blank or commented out, then the sessions table will not be scoped by schema or catalog name.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.table</dt>
<dd>
<p>Default <code>JettySessions</code>.
This is the name of the table in which session data is stored.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.accessTimeColumn</dt>
<dd>
<p>Default <code>accessTime</code>.
This is the name of the column that stores the time - in ms since the epoch - at which a session was last accessed</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.contextPathColumn</dt>
<dd>
<p>Default <code>contextPath</code>.
This is the name of the column that stores the <code>contextPath</code> of a session.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.cookieTimeColumn</dt>
<dd>
<p>Default <code>cookieTime</code>.
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.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.createTimeColumn</dt>
<dd>
<p>Default <code>createTime</code>.
This is the name of the column that stores the time - in ms since the epoch - at which a session was created.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.expiryTimeColumn</dt>
<dd>
<p>Default <code>expiryTime</code>.
This is name of the column that stores - in ms since the epoch - the time at which a session will expire.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.lastAccessTimeColumn</dt>
<dd>
<p>Default <code>lastAccessTime</code>.
This is the name of the column that stores the time - in ms since the epoch - that a session was previously accessed.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.lastSavedTimeColumn</dt>
<dd>
<p>Default <code>lastSavedTime</code>.
This is the name of the column that stores the time - in ms since the epoch - at which a session was last written.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.idColumn</dt>
<dd>
<p>Default <code>sessionId</code>.
This is the name of the column that stores the id of a session.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.lastNodeColumn</dt>
<dd>
<p>Default <code>lastNode</code>.
This is the name of the column that stores the <code>workerName</code> of the last node to write a session.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.virtualHostColumn</dt>
<dd>
<p>Default <code>virtualHost</code>.
This is the name of the column that stores the first virtual host of the context of a session.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.maxIntervalColumn</dt>
<dd>
<p>Default <code>maxInterval</code>.
This is the name of the column that stores the interval - in ms - during which a session can be idle before being considered expired.</p>
</dd>
<dt class="hdlist1">jetty.session.jdbc.schema.mapColumn</dt>
<dd>
<p>Default <code>map</code>.
This is the name of the column that stores the serialized attributes of a session.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-session-mongo"><a class="anchor" href="#og-session-mongo"></a><a class="link" href="#og-session-mongo">Modules for Persistent HTTP Sessions: MongoDB</a></h4>
<div class="paragraph">
<p>Enabling the <code>session-store-mongo</code> module configures Jetty to store session data in MongoDB.</p>
</div>
<div class="paragraph">
<p>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 <code>$JETTY_BASE/lib/nosql/</code>.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
If you want to use updated versions of the jar files automatically downloaded by Jetty, you can place them in the associated <code>$JETTY_BASE/lib/</code> directory and use the <code>--skip-file-validation=&lt;module name&gt;</code> command line option to prevent errors when starting your server.
</td>
</tr>
</table>
</div>
<div class="sect4">
<h5 id="og-configuration-6"><a class="anchor" href="#og-configuration-6"></a><a class="link" href="#og-configuration-6">Configuration</a></h5>
<div class="paragraph">
<p>The <code>$JETTY_BASE/start.d/session-store-mongo.ini</code> file contains these configurable properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.mongo.dbName</dt>
<dd>
<p>Default is "HttpSessions".
This is the name of the database in MongoDB used to store the session collection.</p>
</dd>
<dt class="hdlist1">jetty.session.mongo.collectionName</dt>
<dd>
<p>Default is "jettySessions".
This is the name of the collection in MongoDB used to store all of the sessions.</p>
</dd>
<dt class="hdlist1">The connection type-</dt>
<dd>
<p>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.</p>
<div class="dlist">
<dl>
<dt class="hdlist1">connection-type=address</dt>
<dd>
<p>Used when utilizing a direct connection to the MongoDB server.</p>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.mongo.host</dt>
<dd>
<p>Host name or address for the remote MongoDB instance.</p>
</dd>
<dt class="hdlist1">jetty.session.mongo.port</dt>
<dd>
<p>Port number for the remote MongoDB instance.</p>
</dd>
</dl>
</div>
</dd>
<dt class="hdlist1">connection-type=uri</dt>
<dd>
<p>Used when utilizing MongoURI for secured connections.</p>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.mongo.connectionString</dt>
<dd>
<p>The string defining the MongoURI value, such as <code>mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]</code>.
More information on how to format the MongoURI string can be found in the <a href="https://docs.mongodb.com/manual/reference/connection-string/">official documentation for mongo</a>.</p>
</dd>
</dl>
</div>
</dd>
</dl>
</div>
</dd>
</dl>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>You will only use <strong>one</strong> <code>connection-type</code> at a time, either <code>address</code> or <code>uri</code>.
If both are utilized in your <code>session-store-mongo.ini</code>, only the <em>last</em> <code>connection-type</code> configured in the file will be used.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.gracePeriod.seconds</dt>
<dd>
<p>Integer, in seconds.
Default 3600.
Used during session <a href="#og-session-base-scavenge">scavenging</a>.
Multiples of this period are used to define how long ago a stored session must have expired before it should be <a href="#og-session-base-scavenge">scavenged</a>.</p>
</dd>
<dt class="hdlist1">jetty.session.savePeriod.seconds</dt>
<dd>
<p>Integer, in seconds, default is <code>0</code>.
Whenever a session is accessed by a request, its <code>lastAccessTime</code> and <code>expiry</code> are updated.
Even if your sessions are read-mostly, the <code>lastAccessTime</code> and <code>expiry</code> will 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.</p>
</dd>
</dl>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>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 <code>expiry</code> time thus making it appear to other nodes that it has expired.
Thorough consideration of the <code>maxIdleTime</code> of the session when setting the <code>savePeriod</code> is imperative - it would be undesirable to set a <code>savePeriod</code> that is larger than the <code>maxIdleTime</code>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-session-infinispan"><a class="anchor" href="#og-session-infinispan"></a><a class="link" href="#og-session-infinispan">Modules for Persistent HTTP Sessions: Infinispan</a></h4>
<div class="paragraph">
<p>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 <a href="#og-session-base-scavenge">scavenge</a> expired sessions, you will also need to enable the appropriate <code>infinispan-[remote|embedded]-query</code> module.</p>
</div>
<div class="sect4">
<h5 id="og-session-infinispan-remote"><a class="anchor" href="#og-session-infinispan-remote"></a><a class="link" href="#og-session-infinispan-remote">Remote Infinispan Session Module</a></h5>
<div class="paragraph">
<p>The <code>session-store-infinispan-remote</code> module configures Jetty to talk to an external Infinispan instance to store session data.</p>
</div>
<div class="paragraph">
<p>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).</p>
</div>
<div class="paragraph">
<p>Infinispan-specific jar files are download to the directory named <code>$JETTY_BASE/lib/infinispan/</code>.</p>
</div>
<div class="paragraph">
<p>In addition to adding these modules to the classpath of the server it also added several ini configuration files to the <code>$JETTY_BASE/start.d</code> directory.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
If you have updated versions of the jar files automatically downloaded by Jetty, you can place them in the associated <code>$JETTY_BASE/lib/</code> directory and use the <code>--skip-file-validation=&lt;module name&gt;</code> command line option to prevent errors when starting your server.
</td>
</tr>
</table>
</div>
<div class="sect5">
<h6 id="og-configuration-7"><a class="anchor" href="#og-configuration-7"></a><a class="link" href="#og-configuration-7">Configuration</a></h6>
<div class="paragraph">
<p>The <code>$JETTY_BASE/start.d/session-store-infinispan-remote.ini</code> contains the following configurable properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.infinispan.remoteCacheName</dt>
<dd>
<p>Default <code>"sessions"</code>.
This is the name of the cache in Infinispan where sessions will be stored.</p>
</dd>
<dt class="hdlist1">jetty.session.infinispan.idleTimeout.seconds</dt>
<dd>
<p>Integer, in seconds, default <code>0</code>.
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 <strong>not</strong> want to set a value for this, as you want Jetty to manage all session expiration (and call any HttpSessionListeners).
You <strong>should</strong> enable the <a href="#og-session-infinispan-remote-query">infinispan-remote-query</a> to allow jetty to <a href="#og-session-base-scavenge">scavenge</a> 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.</p>
</dd>
</dl>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
You should make sure that the number of seconds you specify is larger than the configured <code>maxIdleTime</code> for sessions.
</td>
</tr>
</table>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.gracePeriod.seconds</dt>
<dd>
<p>Integer, default 3600.
Used during session <a href="#og-session-base-scavenge">scavenging</a>.
Multiples of this period are used to define how long ago a stored session must have expired before it should be <a href="#og-session-base-scavenge">scavenged</a>.</p>
</dd>
<dt class="hdlist1">jetty.session.savePeriod.seconds</dt>
<dd>
<p>Integer, in seconds, default is <code>0</code>.
Whenever a session is accessed by a request, its <code>lastAccessTime</code> and <code>expiry</code> are updated.
Even if your sessions are read-mostly, the <code>lastAccessTime</code> and <code>expiry</code> will 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.</p>
</dd>
</dl>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>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 <code>expiry</code> time thus making it appear to other nodes that it has expired.
Thorough consideration of the <code>maxIdleTime</code> of the session when setting the <code>savePeriod</code> is imperative - it would be undesirable to set a <code>savePeriod</code> that is larger than the <code>maxIdleTime</code>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-session-infinispan-remote-query"><a class="anchor" href="#og-session-infinispan-remote-query"></a><a class="link" href="#og-session-infinispan-remote-query">Remote Infinispan Query Module</a></h5>
<div class="paragraph">
<p>The <code>infinispan-remote-query</code> module allows Jetty to <a href="#og-session-base-scavenge">scavenge</a> expired sessions.
Note that this is an <strong>additional</strong> module, to be used in conjunction with the <code>session-store-infinispan-remote</code> module.</p>
</div>
<div class="paragraph">
<p>There are no configuration properties associated with this module.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-session-infinispan-embedded"><a class="anchor" href="#og-session-infinispan-embedded"></a><a class="link" href="#og-session-infinispan-embedded">Embedded Infinispan Session Module</a></h5>
<div class="paragraph">
<p>Enabling the <code>session-store-infinispan-embedded</code> module runs an in-process instance of Infinispan.</p>
</div>
<div class="paragraph">
<p>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 <code>$JETTY_BASE/lib/infinispan/</code>.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
If you have updated versions of the jar files automatically downloaded by Jetty, you can place them in the associated <code>$JETTY_BASE/lib/</code> directory and use the <code>--skip-file-validation=&lt;module name&gt;</code> command line option to prevent errors when starting your server.
</td>
</tr>
</table>
</div>
<div class="sect5">
<h6 id="og-configuration-8"><a class="anchor" href="#og-configuration-8"></a><a class="link" href="#og-configuration-8">Configuration</a></h6>
<div class="paragraph">
<p>The <code>$JETTY_BASE/start.d/session-store-infinispan-embedded.ini</code> contains the following configurable properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.infinispan.idleTimeout.seconds</dt>
<dd>
<p>Integer, in seconds, default <code>0</code>.
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 <strong>not</strong> want to set a value for this, as you want Jetty to manage all session expiration (and call any HttpSessionListeners).
You <strong>should</strong> enable the <a href="#og-session-infinispan-embedded-query">infinispan-embedded-query</a> to allow Jetty to <a href="#og-session-base-scavenge">scavenge</a> for expired sessions.
If you do not, then there is the possibility that expired sessions can be left in Infinispan.</p>
</dd>
</dl>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
You should make sure that the number of seconds you specify is larger than the configured <code>maxIdleTime</code> for sessions.
</td>
</tr>
</table>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.gracePeriod.seconds</dt>
<dd>
<p>Integer, default 3600.
Used during session <a href="#og-session-base-scavenge">scavenging</a>.
Multiples of this period are used to define how long ago a stored session must have expired before it should be <a href="#og-session-base-scavenge">scavenged</a>.</p>
</dd>
<dt class="hdlist1">jetty.session.savePeriod.seconds</dt>
<dd>
<p>Integer, in seconds, default is <code>0</code>.
Whenever a session is accessed by a request, its <code>lastAccessTime</code> and <code>expiry</code> are updated.
Even if your sessions are read-mostly, the <code>lastAccessTime</code> and <code>expiry</code> will 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.</p>
</dd>
</dl>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Thorough consideration of the <code>maxIdleTime</code> of the session when setting the <code>savePeriod</code> is imperative - it would be undesirable to set a <code>savePeriod</code> that is larger than the <code>maxIdleTime</code>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-session-infinispan-embedded-query"><a class="anchor" href="#og-session-infinispan-embedded-query"></a><a class="link" href="#og-session-infinispan-embedded-query">Embedded Infinispan Query Module</a></h5>
<div class="paragraph">
<p>The <code>infinispan-embedded-query</code> module allows Jetty to <a href="#og-session-base-scavenge">scavenge</a> expired sessions.</p>
</div>
<div class="paragraph">
<p>There are no configuration properties associated with this module.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-converting-session-format-for-jetty-9-4-13"><a class="anchor" href="#og-converting-session-format-for-jetty-9-4-13"></a><a class="link" href="#og-converting-session-format-for-jetty-9-4-13">Converting Session Format for Jetty-9.4.13</a></h5>
<div class="paragraph">
<p>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 <a href="https://github.com/eclipse/jetty.project/issues/2919" class="bare">https://github.com/eclipse/jetty.project/issues/2919</a> for more background.</p>
</div>
<div class="paragraph">
<p>We have provided a conversion program which will convert any sessions stored in Infinispan to the new format.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
We recommend that you backup your stored sessions before running the conversion program.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>How to use the converter:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>java -cp jetty-jakarta-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] &lt;cache-name&gt; [check]</pre>
</div>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">The classpath</dt>
<dd>
<p>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.</p>
</dd>
<dt class="hdlist1">Parameters</dt>
<dd>
<p>When used with no arguments the usage message is printed. When used with the <code>cache-name</code> parameter the conversion is performed. When used with both <code>cache-name</code> and <code>check</code> parameters, sessions are checked for whether or not they are converted.</p>
<div class="dlist">
<dl>
<dt class="hdlist1">-Dhost</dt>
<dd>
<p>you can optionally provide a system property with the address of your remote Infinispan server. Defaults to the localhost.</p>
</dd>
<dt class="hdlist1">-Dverbose</dt>
<dd>
<p>defaults to false. If true, prints more comprehensive stacktrace information about failures. Useful to diagnose why a session is not converted.</p>
</dd>
<dt class="hdlist1">cache-name</dt>
<dd>
<p>the name of the remote cache containing your sessions. This is mandatory.</p>
</dd>
<dt class="hdlist1">check</dt>
<dd>
<p>the optional check command will verify sessions have been converted. Use it <em>after</em> doing the conversion.</p>
</dd>
</dl>
</div>
</dd>
</dl>
</div>
<div class="paragraph">
<p>To perform the conversion, run the InfinispanSessionLegacyConverter with just the <code>cache-name</code>, and optionally the <code>host</code> system property.
The following command will attempt to convert all sessions in the cached named <code>my-remote-cache</code> on the machine <code>myhost</code>, ensuring that application classes in the <code>/my/custom/classes</code> directory are on the classpath:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>java -cp jetty-jakarta-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</pre>
</div>
</div>
<div class="paragraph">
<p>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 <em>it is prudent to take a backup of your cache before attempting the conversion</em>.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-session-hazelcast"><a class="anchor" href="#og-session-hazelcast"></a><a class="link" href="#og-session-hazelcast">Modules for Persistent HTTP Sessions: Hazelcast</a></h4>
<div class="paragraph">
<p>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.</p>
</div>
<div class="sect4">
<h5 id="og-session-hazelcast-remote"><a class="anchor" href="#og-session-hazelcast-remote"></a><a class="link" href="#og-session-hazelcast-remote">Remote Hazelcast Clustering</a></h5>
<div class="paragraph">
<p>Enabling the <code>session-store-hazelcast-remote</code> module allows jetty to communicate with a remote Hazelcast instance to cluster session data.</p>
</div>
<div class="paragraph">
<p>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).</p>
</div>
<div class="paragraph">
<p>Hazelcast-specific jar files will be downloaded and saved to a directory named <code>$JETTY_BASE/lib/hazelcast/</code>.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
If you have updated versions of the jar files automatically downloaded by Jetty, you can place them in the associated <code>$JETTY_BASE/lib/</code> directory and use the <code>--skip-file-validation=&lt;module name&gt;</code> command line option to prevent errors when starting your server.
</td>
</tr>
</table>
</div>
<div class="sect5">
<h6 id="og-configuration-9"><a class="anchor" href="#og-configuration-9"></a><a class="link" href="#og-configuration-9">Configuration</a></h6>
<div class="paragraph">
<p>The <code>start.d/session-store-hazelcast-remote.ini</code> contains a list of all the configurable options for the Hazelcast module:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.hazelcast.mapName</dt>
<dd>
<p>The default is "jetty-distributed-session-map".
This is the name of the Map in Hazelcast where sessions will be stored.</p>
</dd>
<dt class="hdlist1">jetty.session.hazelcast.onlyClient</dt>
<dd>
<p>Boolean, default <code>true</code>.
The Hazelcast instance will be configured in client mode.</p>
</dd>
<dt class="hdlist1">jetty.session.hazelcast.configurationLocation</dt>
<dd>
<p>Optional.
This is the path to an external Hazelcast xml configuration file.</p>
</dd>
<dt class="hdlist1">jetty.session.hazelcast.useQueries</dt>
<dd>
<p>Boolean, default <code>false</code>.
If <code>true</code>, Jetty will use Hazelcast queries to find sessions to <a href="#og-session-base-scavenge">scavenge</a>.
If <code>false</code> sessions that are not currently in a <a href="#og-session-cache">session cache</a> cannot be <a href="#og-session-base-scavenge">scavenged</a>, and will need to be removed by some external process.</p>
</dd>
<dt class="hdlist1">jetty.session.hazelcast.addresses</dt>
<dd>
<p>Optional.
These are the addresses of remote Hazelcast instances with which to communicate.</p>
</dd>
<dt class="hdlist1">jetty.session.gracePeriod.seconds</dt>
<dd>
<p>Integer, in seconds.
Default 3600.
Used during session <a href="#og-session-base-scavenge">scavenging</a>.
Multiples of this period are used to define how long ago a stored session must have expired before it should be <a href="#og-session-base-scavenge">scavenged</a>.</p>
</dd>
<dt class="hdlist1">jetty.session.savePeriod.seconds</dt>
<dd>
<p>Integer, in seconds, default is <code>0</code>.
Whenever a session is accessed by a request, its <code>lastAccessTime</code> and <code>expiry</code> are updated.
Even if your sessions are read-mostly, the <code>lastAccessTime</code> and <code>expiry</code> will 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.</p>
</dd>
</dl>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>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 <code>expiry</code> time thus making it appear to other nodes that it has expired.
Thorough consideration of the <code>maxIdleTime</code> of the session when setting the <code>savePeriod</code> is imperative - it would be undesirable to set a <code>savePeriod</code> that is larger than the <code>maxIdleTime</code>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
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.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-session-hazelcast-embedded"><a class="anchor" href="#og-session-hazelcast-embedded"></a><a class="link" href="#og-session-hazelcast-embedded">Embedded Hazelcast Clustering</a></h5>
<div class="paragraph">
<p>This will run an in-process instance of Hazelcast.
This can be useful for example during testing.
To enable this you enable the <code>session-store-hazelcast-embedded</code> module.</p>
</div>
<div class="paragraph">
<p>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).</p>
</div>
<div class="paragraph">
<p>Hazelcast-specific jar files will be downloaded to a directory named <code>$JETTY_BASE/lib/hazelcast/</code>.</p>
</div>
<div class="sect5">
<h6 id="og-configuration-10"><a class="anchor" href="#og-configuration-10"></a><a class="link" href="#og-configuration-10">Configuration</a></h6>
<div class="paragraph">
<p>The <code>$JETTY_BASE/start.d/start.d/session-store-hazelcast-embedded.ini</code> contains a list of all the configurable options for the Hazelcast module:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.hazelcast.mapName</dt>
<dd>
<p>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.</p>
</dd>
<dt class="hdlist1">jetty.session.hazelcast.configurationLocation</dt>
<dd>
<p>Optional.
This is the path to an external Hazelcast xml configuration file.</p>
</dd>
<dt class="hdlist1">jetty.session.hazelcast.useQueries</dt>
<dd>
<p>Boolean, default <code>false'.
If `true</code>, Jetty will use Hazelcast queries to find expired sessions to <a href="#og-session-base-scavenge">scavenge</a>.
If <code>false</code> sessions that are not currently in a <a href="#og-session-cache">session cache</a> cannot be <a href="#og-session-base-scavenge">scavenged</a>, and will need to be removed by some external process.</p>
</dd>
<dt class="hdlist1">jetty.session.gracePeriod.seconds</dt>
<dd>
<p>Integer, in seconds.
Default 3600.
Used during session <a href="#og-session-base-scavenge">scavenging</a>.
Multiples of this period are used to define how long ago a stored session must have expired before it should be <a href="#og-session-base-scavenge">scavenged</a>.</p>
</dd>
<dt class="hdlist1">jetty.session.savePeriod.seconds</dt>
<dd>
<p>Integer, in seconds, default is <code>0</code>.
Whenever a session is accessed by a request, its <code>lastAccessTime</code> and <code>expiry</code> are updated.
Even if your sessions are read-mostly, the <code>lastAccessTime</code> and <code>expiry</code> will 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.</p>
</dd>
</dl>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>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 <code>expiry</code> time thus making it appear to other nodes that it has expired.
Thorough consideration of the <code>maxIdleTime</code> of the session when setting the <code>savePeriod</code> is imperative - it would be undesirable to set a <code>savePeriod</code> that is larger than the <code>maxIdleTime</code>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
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&#8217;s classes - you will need to extract these classes and put them onto the jetty server&#8217;s classpath.
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-session-gcloud"><a class="anchor" href="#og-session-gcloud"></a><a class="link" href="#og-session-gcloud">Modules for Persistent HTTP Sessions: Google Cloud DataStore</a></h4>
<div class="paragraph">
<p>Jetty can store http session information into GCloud by enabling the <code>session-store-gcloud</code> module.</p>
</div>
<div class="sect4">
<h5 id="og-preparation"><a class="anchor" href="#og-preparation"></a><a class="link" href="#og-preparation">Preparation</a></h5>
<div class="paragraph">
<p>You will first need to create a project and enable the Google Cloud api: <a href="https://cloud.google.com/docs/authentication#preparation" class="bare">https://cloud.google.com/docs/authentication#preparation</a>.
Take note of the project id that you create in this step as you need to supply it in later steps.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-communicating-with-gclouddatastore"><a class="anchor" href="#og-communicating-with-gclouddatastore"></a><a class="link" href="#og-communicating-with-gclouddatastore">Communicating with GCloudDataStore</a></h5>
<div class="sect5">
<h6 id="og-when-running-jetty-outside-of-google-infrastructure"><a class="anchor" href="#og-when-running-jetty-outside-of-google-infrastructure"></a><a class="link" href="#og-when-running-jetty-outside-of-google-infrastructure">When Running Jetty Outside of Google Infrastructure</a></h6>
<div class="paragraph">
<p>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.</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Using the GCloud SDK:</p>
<div class="ulist">
<ul>
<li>
<p>Ensure you have the GCloud SDK installed: <a href="https://cloud.google.com/sdk/?hl=en" class="bare">https://cloud.google.com/sdk/?hl=en</a></p>
</li>
<li>
<p>Use the GCloud tool to set up the project you created in the preparation step: <code>gcloud config set project PROJECT_ID</code></p>
</li>
<li>
<p>Use the GCloud tool to authenticate a google account associated with the project created in the preparation step: <code>gcloud auth login ACCOUNT</code></p>
</li>
</ul>
</div>
</li>
<li>
<p>Using environment variables</p>
<div class="ulist">
<ul>
<li>
<p>Define the environment variable <code>GCLOUD_PROJECT</code> with the project id you created in the preparation step.</p>
</li>
<li>
<p>Generate a JSON <a href="https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts">service account key</a> and then define the environment variable <code>GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/key.json</code></p>
</li>
</ul>
</div>
</li>
</ol>
</div>
</div>
<div class="sect5">
<h6 id="og-when-running-jetty-inside-of-google-infrastructure"><a class="anchor" href="#og-when-running-jetty-inside-of-google-infrastructure"></a><a class="link" href="#og-when-running-jetty-inside-of-google-infrastructure">When Running Jetty Inside of Google Infrastructure</a></h6>
<div class="paragraph">
<p>The Google deployment tools will automatically configure the project and authentication information for you.</p>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-configuring-indexes-for-session-data"><a class="anchor" href="#og-configuring-indexes-for-session-data"></a><a class="link" href="#og-configuring-indexes-for-session-data">Configuring Indexes for Session Data</a></h5>
<div class="paragraph">
<p>Using some special, composite indexes can speed up session search operations, although it may make write operations slower.
By default, indexes will <em>not</em> be used.
In order to use them, you will need to manually upload a file that defines the indexes.
This file is named <code>index.yaml</code> and you can find it in your distribution in <code>$JETTY_BASE/etc/sessions/gcloud/index.yaml</code>.</p>
</div>
<div class="paragraph">
<p>Follow the instructions <a href="https://cloud.google.com/datastore/docs/tools/#the_development_workflow_using_gcloud">here</a> to upload the pre-generated <code>index.yaml</code> file.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-communicating-with-the-gclouddatastore-emulator"><a class="anchor" href="#og-communicating-with-the-gclouddatastore-emulator"></a><a class="link" href="#og-communicating-with-the-gclouddatastore-emulator">Communicating with the GCloudDataStore Emulator</a></h5>
<div class="paragraph">
<p>To enable communication using the GCloud Emulator:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Ensure you have the GCloud SDK installed: <a href="https://cloud.google.com/sdk/?hl=en" class="bare">https://cloud.google.com/sdk/?hl=en</a></p>
</li>
<li>
<p>Follow the instructions <a href="https://cloud.google.com/datastore/docs/tools/datastore-emulator">here</a> 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.</p>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="og-enabling-the-google-cloud-datastore-module"><a class="anchor" href="#og-enabling-the-google-cloud-datastore-module"></a><a class="link" href="#og-enabling-the-google-cloud-datastore-module">Enabling the Google Cloud DataStore Module</a></h5>
<div class="paragraph">
<p>The <code>session-store-gcloud</code> module provides GCloud support for storing session data.</p>
</div>
<div class="paragraph">
<p>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.</p>
</div>
<div class="paragraph">
<p>As GCloud requires certain Java Commons Logging features to work correctly, Jetty routes these through SLF4J by transitively enabling the <code>jcl-slf4j</code> module during installation.
Therefore, you will <em>also</em> 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 <code>session-store-gcloud</code> module, or you can just enable <code>session-store-gcloud</code> module and it will print out a list of available SLF4J implementations.
You can then choose one and enable it.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
If you want to use updated versions of the jar files automatically downloaded during the module enablement, you can place them in the associated <code>$JETTY_BASE/lib/</code> directory and use the <code>--skip-file-validation=&lt;module name&gt;</code> command line option to prevent errors when starting your server.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-configuration-11"><a class="anchor" href="#og-configuration-11"></a><a class="link" href="#og-configuration-11">Configuration</a></h4>
<div class="paragraph">
<p>The <code>$JETTY_BASE/start.d/session-store-gcloud.ini</code> file contains all of the configurable properties for the <code>session-store-gcloud</code> module:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.gcloud.maxRetries</dt>
<dd>
<p>Integer.
Default 5.
Maximum number of retries to connect to GCloud DataStore to write a session.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.backoffMs</dt>
<dd>
<p>Integer in milliseconds.
Default 1000.
Number of milliseconds between successive attempts to connect to the GCloud DataStore to write a session.</p>
</dd>
<dt class="hdlist1">jetty.session.gracePeriod.seconds</dt>
<dd>
<p>Integer, in seconds.
Default 3600.
Used during session <a href="#og-session-base-scavenge">scavenging</a>.
Multiples of this period are used to define how long ago a stored session must have expired before it should be <a href="#og-session-base-scavenge">scavenged</a>.</p>
</dd>
<dt class="hdlist1">jetty.session.savePeriod.seconds</dt>
<dd>
<p>Integer, in seconds, default is <code>0</code>.
Whenever a session is accessed by a request, its <code>lastAccessTime</code> and <code>expiry</code> are updated.
Even if your sessions are read-mostly, the <code>lastAccessTime</code> and <code>expiry</code> will 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.</p>
</dd>
</dl>
</div>
<div class="admonitionblock warning">
<table>
<tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
<div class="paragraph">
<p>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 <code>expiry</code> time thus making it appear to other nodes that it has expired.
Thorough consideration of the <code>maxIdleTime</code> of the session when setting the <code>savePeriod</code> is imperative - it would be undesirable to set a <code>savePeriod</code> that is larger than the <code>maxIdleTime</code>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.gcloud.namespace</dt>
<dd>
<p>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 <a href="https://cloud.google.com/datastore/docs/concepts/multitenancy">here.</a></p>
</dd>
<dt class="hdlist1">Configuration of the stored session object and its fields names-</dt>
<dd>
<p>You should very rarely, if ever, need to change these defaults.</p>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.gcloud.model.kind</dt>
<dd>
<p>The default is "GCloudSession".
This is the type of the object that is stored in GCloud.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.id</dt>
<dd>
<p>The default is "id".
This is the session id.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.contextPath</dt>
<dd>
<p>The default is "contextPath".
This is the canonicalized context path of the context to which the session belongs.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.vhost</dt>
<dd>
<p>The default is "vhost".
This is the canonicalized virtual host of the context to which the session belongs.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.accessed</dt>
<dd>
<p>The default is "accessed".
This is the current access time of the session.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.lastAccessed</dt>
<dd>
<p>The default is "lastAccessed".
This is the last access time of the session.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.createTime</dt>
<dd>
<p>The default is "createTime".
This is the time, in ms since the epoch, at which the session was created.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.cookieSetTime</dt>
<dd>
<p>The default is "cookieSetTime".
This is the time at which the session cookie was last set.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.lastNode</dt>
<dd>
<p>The default is "lastNode".
This is the <code>workerName</code> of the last node to manage the session.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.expiry</dt>
<dd>
<p>The default is "expiry".
This is the time, in ms since the epoch, at which the session will expire.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.maxInactive</dt>
<dd>
<p>The default is "maxInactive".
This is the session timeout in ms.</p>
</dd>
<dt class="hdlist1">jetty.session.gcloud.model.attributes</dt>
<dd>
<p>The default is "attributes".
This is a map of all the session attributes.</p>
</dd>
</dl>
</div>
</dd>
</dl>
</div>
</div>
<div class="sect3">
<h4 id="og-session-memcached"><a class="anchor" href="#og-session-memcached"></a><a class="link" href="#og-session-memcached">Modules for Persistent HTTP Sessions: The L2 Session Data Cache</a></h4>
<div class="paragraph">
<p>If your chosen persistence technology is slow, it can be helpful to locally cache the session data.
The <code>CachingSessionDataStore</code> is a special type of <code>SessionDataStore</code> that locally caches session data, which makes reads faster. It writes-through to your chosen type of <code>SessionDataStore</code> when session data changes.</p>
</div>
<div class="sect4">
<h5 id="og-memcachedsessiondatamap"><a class="anchor" href="#og-memcachedsessiondatamap"></a><a class="link" href="#og-memcachedsessiondatamap">MemcachedSessionDataMap</a></h5>
<div class="paragraph">
<p>The <code>MemcachedSessionDataMap</code> uses <code>memcached</code> to perform caching of <code>SessionData</code>.</p>
</div>
<div class="paragraph">
<p>To enable it with the Jetty distribution, enable the <code>session-store-cache</code> module, along with your chosen <code>session-store-xxxx</code> module.</p>
</div>
<div class="sect5">
<h6 id="og-configuration-12"><a class="anchor" href="#og-configuration-12"></a><a class="link" href="#og-configuration-12">Configuration</a></h6>
<div class="paragraph">
<p>The <code>$JETTY_BASE/start.d/session-store-cache.ini</code> contains the following configurable properties:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.session.memcached.host</dt>
<dd>
<p>Default value is <code>localhost</code>.
This is the host on which the memcached server resides.</p>
</dd>
<dt class="hdlist1">jetty.session.memcached.port</dt>
<dd>
<p>Default value is <code>11211</code>.
This is the port on which the memcached server is listening.</p>
</dd>
<dt class="hdlist1">jetty.session.memcached.expirySec</dt>
<dd>
<p>Default value <code>0</code>.
This is the length of time in seconds that an item can remain in the memcached cache, where 0 indicates indefinitely.</p>
</dd>
<dt class="hdlist1">jetty.session.memcached.heartbeats</dt>
<dd>
<p>Default value <code>true</code>.
Whether the memcached system should generate heartbeats.</p>
</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-session-usecases"><a class="anchor" href="#og-session-usecases"></a><a class="link" href="#og-session-usecases">Session Scenarios</a></h4>
<div class="sect4">
<h5 id="og-minimizing-support-for-sessions"><a class="anchor" href="#og-minimizing-support-for-sessions"></a><a class="link" href="#og-minimizing-support-for-sessions">Minimizing Support for Sessions</a></h5>
<div class="paragraph">
<p>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&#8217;t use them (or use JSPs that use them), then you can do the following:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>enable the <a href="#og-session-base">base sessions module</a> and <a href="#og-session-base">configure the scavenge interval</a> to 0 to prevent scavenging</p>
</li>
<li>
<p>enable the <a href="#og-session-cache-null">null session cache module</a> to prevent sessions being cached in memory</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>If you wish to do any further minimization, you should consult the <a href="../programming-guide/index.html">Programming Guide</a>.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-clustering-with-a-sticky-load-balancer"><a class="anchor" href="#og-clustering-with-a-sticky-load-balancer"></a><a class="link" href="#og-clustering-with-a-sticky-load-balancer">Clustering with a Sticky Load Balancer</a></h5>
<div class="paragraph">
<p>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 <a href="#og-session-cache-hash"><code>DefaultSessionCache</code></a> can be used to keep in-use session objects <a href="#og-session-cache-hash">in memory</a>.
You can fine-tune the cache by controlling how long session objects remain in memory with the <a href="#og-session-cache-hash">eviction policy settings</a>.</p>
</div>
<div class="paragraph">
<p>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 <code>EVICT_ON_SESSION_EXIT</code> eviction policy will remove a session object from the cache as soon as the last simultaneous request referencing it exits.
Alternatively, the <code>EVICT_ON_INACTIVITY</code> policy will remove a session object from the cache after a configurable amount of time has passed without a request referencing it.</p>
</div>
<div class="paragraph">
<p>If your sessions are very long lived and infrequently referenced, you might use the <code>EVICT_ON_INACTIVITY_POLICY</code> to control the size of the cache.</p>
</div>
<div class="paragraph">
<p>If your sessions are small, or relatively few or stable in number or they are read-mostly, then you might select the <code>NEVER_EVICT</code> policy.
With this policy, session objects will remain in the cache until they either expire or are explicitly invalidated.</p>
</div>
<div class="paragraph">
<p>If you have a high likelihood of simultaneous requests for the same session object, then the <code>EVICT_ON_SESSION_EXIT</code> policy will ensure the session object stays in the cache as long as it is needed.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-clustering-without-a-sticky-load-balancer"><a class="anchor" href="#og-clustering-without-a-sticky-load-balancer"></a><a class="link" href="#og-clustering-without-a-sticky-load-balancer">Clustering Without a Sticky Load Balancer</a></h5>
<div class="paragraph">
<p>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 <code>SessionCache</code> 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 <a href="#og-session-cache-null"><code>NullSessionCache</code></a> or to de-tune the <a href="#og-session-cache-hash"><code>DefaultSessionCache</code></a>.
If you use the <code>NullSessionCache</code> 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.</p>
</div>
<div class="paragraph">
<p>If you use the <code>DefaultSessionCache</code>, 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 <code>EVICT_ON_SESSION_EXIT</code> 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.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-handling-corrupted-or-unreadable-session-data"><a class="anchor" href="#og-handling-corrupted-or-unreadable-session-data"></a><a class="link" href="#og-handling-corrupted-or-unreadable-session-data">Handling Corrupted or Unreadable Session Data</a></h5>
<div class="paragraph">
<p>For various reasons it might not be possible for the <code>SessionDataStore</code> 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 <code>$JETTY_BASE/start.d/session-cache-hash.ini</code> or <code>$JETTY_BASE/start.d/session-cache-null.ini</code> property <code>jetty.session.removeUnloadableSessions</code> to <code>true</code> will allow the unreadable session to be removed from persistent storage.
This can be useful for preventing the <a href="#og-session-base-scavenge">scavenger</a> from continually generating errors on the same expired, but un-readable session.</p>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-quickstart"><a class="anchor" href="#og-quickstart"></a><a class="link" href="#og-quickstart">Faster Web Application Deployment</a></h3>
<div class="paragraph">
<p>The auto discovery features of the Servlet Specification can make deployments slow and uncertain.
Auto discovery of web application configuration can be useful during the development as it allows new features and frameworks to be enabled simply by dropping in a jar file.
However for production deployment, the need to scan the contents of many jars can have a significant impact at startup time.</p>
</div>
<div class="paragraph">
<p>The <code>quickstart</code> module allows a webapp to be pre-scanned, making startup predictable and faster.
During scanning all declarative configuration (ie from web.xml, web-fragment.xml and annotations) are encoded into an effective <code>web.xml</code>, called <code>WEB-INF/quickstart-web.xml</code>, which can be inspected to understand what will be deployed.
NOTE:: Programmatic configuration is <em>not</em> encoded into the generated <code>quickstart-web.xml</code> file.</p>
</div>
<div class="paragraph">
<p>With <code>quickstart</code>, webapps that took many seconds to scan and deploy can now be deployed in a few hundred milliseconds.</p>
</div>
<div class="sect3">
<h4 id="og-enabling"><a class="anchor" href="#og-enabling"></a><a class="link" href="#og-enabling">Enabling</a></h4>
<div class="paragraph">
<p>Enable the <code>quickstart</code> module for your jetty base:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-screen" data-lang="screen">$ cd $JETTY-BASE
$ java -jar $JETTY_HOME/start.jar --add-module=quickstart</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>$JETTY-BASE/start.d/quickstart.ini</code> file contains these configurable parameters:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.quickstart.mode</dt>
<dd>
<p>The values are:</p>
<div class="dlist">
<dl>
<dt class="hdlist1">AUTO</dt>
<dd>
<p>Allows jetty to run either with or without a <code>quickstart-web.xml</code> file.
If jetty detects the file, then it will be used, otherwise the app is started normally.</p>
</dd>
<dt class="hdlist1">GENERATE</dt>
<dd>
<p>In this mode, jetty will generate a <code>quickstart-web.xml</code> file and then terminate.
Use this mode first before changing to either <code>AUTO</code> or <code>QUICKSTART</code>.</p>
</dd>
<dt class="hdlist1">QUICKSTART</dt>
<dd>
<p>In this mode, if jetty does not detect a <code>quickstart-web.xml</code> file then jetty will not start.</p>
</dd>
</dl>
</div>
</dd>
<dt class="hdlist1">jetty.quickstart.origin</dt>
<dd>
<p>Use this parameter to set the name of the attribute in the <code>quickstart-web.xml</code> file that contains the origin of each element.
Knowing the descriptor or annotation from which each element derives can be useful for debugging.
Note that the origin attribute does not conform to the web xml schema, so if you deploy with xml validation, you&#8217;ll see errors.
It is probably best to do a few trial runs with the attribute set, then turn it off for final generation.</p>
</dd>
<dt class="hdlist1">jetty.quickstart.xml</dt>
<dd>
<p>Use this parameter to change the name of the generated file.
By default this is <code>quickstart-web.xml</code> in the webapp&#8217;s <code>WEB-INF</code> directory.
The file named by this parameter will always be interpreted relative to <code>WEB-INF</code>.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>If your webapp is a war file, you will need to either first unpack it yourself, or use a context xml file (or code equivalent) that calls <code>WebAppContext.setExtractWAR(true)</code>.
If you allow Jetty to do the unpacking, it will use the usual mechanisms to find the location to which to unpack.
Note that by default Jetty unpacks to a temporary location which is <em>not</em> reused between executions.
So either specify the directory to which to unpack, or make a <code>work</code> directory in your base to ensure the unpacked war is preserved and reused across restarts.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-annotations"><a class="anchor" href="#og-annotations"></a><a class="link" href="#og-annotations">Annotations</a></h3>
<div class="paragraph">
<p>Enable the <code>annotations</code> module if your webapp - or any of its third party libraries - uses any of the following:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Annotations:</p>
<div class="ulist">
<ul>
<li>
<p>@Resource</p>
</li>
<li>
<p>@Resources</p>
</li>
<li>
<p>@PostConstruct</p>
</li>
<li>
<p>@PreDestroy</p>
</li>
<li>
<p>@DeclaredRoles</p>
</li>
<li>
<p>@RunAs</p>
</li>
<li>
<p>@MultipartConfig</p>
</li>
<li>
<p>@WebServlet</p>
</li>
<li>
<p>@WebFilter</p>
</li>
<li>
<p>@WebListener</p>
</li>
<li>
<p>@WebInitParam</p>
</li>
<li>
<p>@ServletSecurity, @HttpConstraint, @HttpMethodConstraint</p>
</li>
<li>
<p>@HandlesTypes</p>
</li>
</ul>
</div>
</li>
<li>
<p>javax.servlet.ServletContainerInitializers</p>
</li>
<li>
<p>JSP</p>
</li>
</ul>
</div>
<div class="sect3">
<h4 id="og-annotations-scanning"><a class="anchor" href="#og-annotations-scanning"></a><a class="link" href="#og-annotations-scanning">Annotation Scanning</a></h4>
<div class="paragraph">
<p>According to more recent versions of the Servlet Specification, the web.xml file can contain the attribute <code>metadata-complete</code>.
If this is set to <code>true</code>, then <em>no</em> annotation scanning takes place, and your descriptor must contain the equivalent xml statements of any annotations.</p>
</div>
<div class="paragraph">
<p>If it is <code>metadata-complete=false</code>, or your web.xml predates the inclusion of this attribute, annotation scanning is required to take place.</p>
</div>
<div class="paragraph">
<p>To prevent annotation scanning you can use the <code>WebAppContext.setConfigurationDiscovered(false)</code> method.
Here&#8217;s an example context xml file that calls this method:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Set name="configurationDiscovered"&gt;false&lt;/Set&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Configures a <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a>, which is the Jetty component that represents a standard Servlet web application.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Specifies that scanning should not take place.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>However, despite <code>metadata-complete=true</code>, scanning of classes may <em>still</em> occur because of <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContainerInitializer.html">javax.servlet.ServletContainerInitializer</a>s.
Classes implementing this interface are found by Jetty using the <a href="http://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html">javax.util.ServiceLoader</a> mechanism, and if one is present <em>and</em> it includes the @HandlesTypes annotation, then Jetty must scan the class hierarchy of the web application.
This may be very time-consuming if you have many jars.</p>
</div>
<div class="paragraph">
<p>We will now look at ways to limit the jars that are scanned.</p>
</div>
<div class="sect4">
<h5 id="og-the-container-classpath"><a class="anchor" href="#og-the-container-classpath"></a><a class="link" href="#og-the-container-classpath">The container classpath</a></h5>
<div class="paragraph">
<p>By default, Jetty will <em>not</em> scan any classes that are on the container&#8217;s classpath.</p>
</div>
<div class="paragraph">
<p>Sometimes, you may have third party libraries on the container&#8217;s classpath that you need to be scanned.
In this case, use the <code>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</code> context attribute to define which container jars and class directories to scan.
The value of this attribute is a regular expression.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example from a context xml file that includes any jar whose name starts with "foo-" or "bar-", or a directory named "classes":</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Call name="setAttribute"&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;Arg&gt;org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern&lt;/Arg&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;Arg&gt;.*/foo-[^/]*\.jar$|.*/bar-[^/]*\.jar$|.*/classes/.*&lt;/Arg&gt; <i class="conum" data-value="4"></i><b>(4)</b>
&lt;/Call&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Configures a <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a>, which is the Jetty component that represents a standard Servlet web application.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Specifies a context attribute.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Specifies the name of the context attribute.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Specifies the value of the context attribute.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Note that the order of the patterns defines the ordering of the scanning of the jars or class directories.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-the-webapp-classpath"><a class="anchor" href="#og-the-webapp-classpath"></a><a class="link" href="#og-the-webapp-classpath">The webapp classpath</a></h5>
<div class="paragraph">
<p>By default Jetty will scan <em>all</em> classes from <code>WEB-INF/classes</code> and <em>all</em> jars from <code>WEB-INF/lib</code> according to the order, if any, established by absolute or relative ordering clauses in web.xml.</p>
</div>
<div class="paragraph">
<p>If your webapp contains many jar files that you know do not contain any annotations, you can significantly speed up deployment by omitting them from scanning.
However, be careful if your webapp uses a <code>ServletContainerInitializer</code> with an <code>@HandlesTypes</code> annotation that you don&#8217;t exclude jars that contain classes matching the annotation.</p>
</div>
<div class="paragraph">
<p>Use the <code>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</code> context attribute to define a regular expression for jars and class directories to select for scanning.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of a context xml file that sets a pattern that matches any jar on the webapp&#8217;s classpath that starts with <code>spring-</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Call name="setAttribute"&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;Arg&gt;org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern&lt;/Arg&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;Arg&gt;.*/spring-[^/]*\.jar$&lt;/Arg&gt; <i class="conum" data-value="4"></i><b>(4)</b>
&lt;/Call&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Configures a <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a>, which is the Jetty component that represents a standard Servlet web application.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Specifies a context attribute.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Specifies the name of the context attribute.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Specifies the value of the context attribute.</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="og-multi-threading"><a class="anchor" href="#og-multi-threading"></a><a class="link" href="#og-multi-threading">Multi-threading</a></h5>
<div class="paragraph">
<p>By default Jetty performs annotation scanning in a multi-threaded manner in order to complete it in the minimum amount of time.</p>
</div>
<div class="paragraph">
<p>If you don&#8217;t want multi-threaded scanning, you can configure Jetty to revert to single-threaded scanning.
There are several options to configure this:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Set the context attribute <code>org.eclipse.jetty.annotations.multiThreaded</code> to <code>false</code></p>
</li>
<li>
<p>Set the <code>Server</code> attribute <code>org.eclipse.jetty.annotations.multiThreaded</code> to <code>false</code></p>
</li>
<li>
<p>Set the System property <code>org.eclipse.jetty.annotations.multiThreaded</code> to <code>false</code></p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Method 1 will only affect the current webapp.
Method 2 will affect all webapps deployed to the same Server instance.
Method 3 will affect all webapps deployed in the same JVM.</p>
</div>
<div class="paragraph">
<p>By default, Jetty will wait a maximum of 60 seconds for all of the scanning threads to complete.
You can set this to a higher or lower number of seconds by doing one of the following:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Set the context attribute <code>org.eclipse.jetty.annotations.maxWait</code></p>
</li>
<li>
<p>Set the <code>Server</code> attribute <code>org.eclipse.jetty.annotations.maxWait</code></p>
</li>
<li>
<p>Set the System property <code>org.eclipse.jetty.annotations.maxWait</code></p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Method 1 will only affect the current webapp.
Method 2 will affect all webapps deployed to the same Server instance.
Method 3 will affect all webapps deployed in the same JVM.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-annotations-scis"><a class="anchor" href="#og-annotations-scis"></a><a class="link" href="#og-annotations-scis">ServletContainerInitializers</a></h4>
<div class="paragraph">
<p>The <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContainerInitializer.html">javax.servlet.ServletContainerInitializer</a> class can exist in: the container&#8217;s classpath, the webapp&#8217;s <code>WEB-INF/classes</code> directory, the webapp&#8217;s <code>WEB-INF/lib</code> jars, or any external extraClasspath that you have configured on the webapp.</p>
</div>
<div class="paragraph">
<p>The Servlet Specification does not define any order in which a <code>ServletContainerInitializer</code> must be called when the webapp starts.
By default Jetty will call them in the following order:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>ServletContainerInitializers from the container&#8217;s classpath</p>
</li>
<li>
<p>ServletContainerInitializers from WEB-INF/classes</p>
</li>
<li>
<p>ServletContainerInitializers from WEB-INF/lib jars <em>in the order established in web.xml</em>, or in the order that the SCI is returned by the <a href="http://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html">javax.util.ServiceLoader</a> if there is <em>no</em> ordering.</p>
</li>
</ol>
</div>
<div class="sect4">
<h5 id="og-exclusions"><a class="anchor" href="#og-exclusions"></a><a class="link" href="#og-exclusions">Exclusions</a></h5>
<div class="paragraph">
<p>By default, as according to the Servlet Specification, all <code>ServletContainerInitializer</code> that are discovered are invoked.</p>
</div>
<div class="paragraph">
<p>Sometimes, depending on your requirements, you may need to prevent some being called at all.</p>
</div>
<div class="paragraph">
<p>In this case, you can define the <code>org.eclipse.jetty.containerInitializerExclusionPattern</code> context attribute.</p>
</div>
<div class="paragraph">
<p>This is a regular expression that defines <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">patterns</a> of classnames that you want to exclude.
Here&#8217;s an example of setting the context attribute in a context xml file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Call name="setAttribute"&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;Arg&gt;org.eclipse.jetty.containerInitializerExclusionPattern&lt;/Arg&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;Arg&gt;com.acme.*|com.corp.SlowContainerInitializer&lt;/Arg&gt; <i class="conum" data-value="4"></i><b>(4)</b>
&lt;/Call&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Configures a <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a>, which is the Jetty component that represents a standard Servlet web application.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Specifies a context attribute.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Specifies the name of the context attribute.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Specifies the value of the context attribute.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>In this example we exclude <strong>all</strong> <code>ServletContainerInitializer</code> instances in the <code>com.acme package</code>, and the specific class <code>com.corp.SlowContainerInitializer</code>.</p>
</div>
<div class="paragraph">
<p>It is possible to use exclusion and ordering together to control <code>ServletContainerInitializer</code> invocation - the exclusions will be applied before the ordering.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-ordering"><a class="anchor" href="#og-ordering"></a><a class="link" href="#og-ordering">Ordering</a></h5>
<div class="paragraph">
<p>If you need <code>ServletContainerInitializer</code> classes called in a specific order, you can use the context attribute <code>org.eclipse.jetty.containerInitializerOrder</code>.
Set it to a list of comma separated class names of <code>ServletContainerInitializers</code> in the order that you want them applied.</p>
</div>
<div class="paragraph">
<p>You may optionally use the wildcard character <code>*</code> <strong>once</strong> in the list.
It will match all <code>ServletContainerInitializer</code> classes not explicitly named in the list.</p>
</div>
<div class="paragraph">
<p>Here is an example context xml file that ensures the <code>com.example.PrioritySCI</code> will be called first, followed by the <code>com.acme.FooSCI</code>, then all other SCIs:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Call name="setAttribute"&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;Arg&gt;org.eclipse.jetty.containerInitializerOrder&lt;/Arg&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;Arg&gt;org.eclipse.jetty.websocket.javax.server.JavaxWebSocketServletContainerInitializer, com.acme.FooSCI, *&lt;/Arg&gt; <i class="conum" data-value="4"></i><b>(4)</b>
&lt;/Call&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Configures a <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a>, which is the Jetty component that represents a standard Servlet web application.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Specifies a context attribute.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Specifies the name of the context attribute.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Specifies the value of the context attribute.</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-jsp"><a class="anchor" href="#og-jsp"></a><a class="link" href="#og-jsp">Java Server Pages</a></h3>
<div class="paragraph">
<p>Jetty supports JSP via the <code>jsp</code> module, which is based on Apache Jasper:</p>
</div>
<div class="listingblock">
<div class="content">
<pre># DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
[description]
Enables JSP for all web applications deployed on the server.
[depend]
servlet
annotations
apache-jsp</pre>
</div>
</div>
<div class="paragraph">
<p>Logging has been bridged to Jetty logging, so you can enable logging for the <code>org.apache.jasper</code> package, subpackages and classes as usual.</p>
</div>
<div class="sect4">
<h5 id="og-configuration-of-the-jsp-servlet"><a class="anchor" href="#og-configuration-of-the-jsp-servlet"></a><a class="link" href="#og-configuration-of-the-jsp-servlet">Configuration of the JSP servlet</a></h5>
<div class="paragraph">
<p>The <code>org.eclipse.jetty.jsp.JettyJspServlet</code> is the servlet responsible for serving jsps.</p>
</div>
<div class="paragraph">
<p>It is configured as the default jsp servlet in the <a href="../../../../../../jetty-home/target/jetty-home/etc/webdefault.xml">webdefault.xml</a> file.
Notice that Jetty identifies the jsp servlet by the presence of the <code>id=jsp</code> attribute in the <code>&lt;servlet&gt;</code> declaration.</p>
</div>
<div class="paragraph">
<p>That file maps the <code>org.eclipse.jetty.jsp.JettyJspServlet</code> to the following partial urls:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>*.jsp</code></p>
</li>
<li>
<p><code>*.jspf</code></p>
</li>
<li>
<p><code>*.jspx</code></p>
</li>
<li>
<p><code>*.xsp</code></p>
</li>
<li>
<p><code>*.JSP</code></p>
</li>
<li>
<p><code>*.JSPF</code></p>
</li>
<li>
<p><code>*.JSPX</code></p>
</li>
<li>
<p><code>*.XSP</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>You can change to a different servlet, change or add <code>&lt;init-param&gt;</code>s or add extra <code>&lt;servlet-mapping&gt;</code>s in your <code>web.xml</code> file.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of adding an <code>&lt;init-param&gt;</code> to augment the definitions from the standard <code>webdefault.xml</code> file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml"> &lt;servlet id="jsp"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;servlet-name&gt;jsp&lt;/servlet-name&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;init-param&gt;
&lt;param-name&gt;keepgenerated&lt;/param-name&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;param-value&gt;true&lt;/param-value&gt; <i class="conum" data-value="4"></i><b>(4)</b>
&lt;/init-param&gt;
&lt;/servlet&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This identifies this servlet as the jsp servlet to Jetty.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>This identifies this declaration as augmenting the already-defined servlet called <code>jsp</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>This init param controls whether the jsp servlet retains the <code>*.java</code> files generated during jsp compilation.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>This sets the value of the init param</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Another element you might consider adding to the default setup is <code>async-supported</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;servlet id="jsp"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;servlet-name&gt;jsp&lt;/servlet-name&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;async-supported&gt;true&lt;/async-supported&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;/servlet&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This identifies this servlet as the jsp servlet to Jetty.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>This identifies this declaration as augmenting the already-defined servlet called <code>jsp</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>By default, the jsp servlet does not support async.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>There are many configuration parameters for the Apache Jasper jsp servlet, here are some of them:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<caption class="title">Table 4. Jsp Servlet Parameters</caption>
<colgroup>
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
<col style="width: 25%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">init param</th>
<th class="tableblock halign-left valign-top">Description</th>
<th class="tableblock halign-left valign-top">Default</th>
<th class="tableblock halign-left valign-top"><code>webdefault.xml</code></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">checkInterval</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If non-zero and <code>development</code> is <code>false</code>, background jsp recompilation is enabled. This value is the interval in seconds between background recompile checks.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">classpath</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The classpath is dynamically generated if the context has a URL classloader. The <code>org.apache.catalina.jsp_classpath</code>
context attribute is used to add to the classpath, but if this is not set, this <code>classpath</code> configuration item is added to the classpath instead.`</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">classdebuginfo</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Include debugging info in class file.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">compilerClassName</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If not set, defaults to the Eclipse jdt compiler.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">compiler</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Used if the Eclipse jdt compiler cannot be found on the
classpath. It is the classname of a compiler that Ant should invoke.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">compilerTargetVM</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Target vm to compile for.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.8</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.8</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">compilerSourceVM</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Sets source compliance level for the jdt compiler.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.8</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.8</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">development</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If <code>true</code> recompilation checks occur at the frequency governed by <code>modificationTestInterval</code>.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">displaySourceFragment</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Should a source fragment be included in
exception messages</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">dumpSmap</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Dump SMAP JSR45 info to a file.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">enablePooling</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Determines whether tag handler pooling is enabled.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">engineOptionsClass</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Allows specifying the Options class used to
configure Jasper. If not present, the default EmbeddedServletOptions
will be used.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">errorOnUseBeanInvalidClassAttribute</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Should Jasper issue an error when
the value of the class attribute in an useBean action is not a valid
bean class</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">fork</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Only relevant if you use Ant to compile jsps: by default Jetty will use the Eclipse jdt compiler.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">genStrAsCharArray</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Option for generating Strings as char arrays.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">ieClassId</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The class-id value to be sent to Internet Explorer when
using &lt;jsp:plugin&gt; tags.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">clsid:8AD9C840-044E-11D1-B3E9-00805F499D93</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">javaEncoding</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Pass through the encoding to use for the compilation.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">UTF8</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">jspIdleTimeout</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The amount of time in seconds a JSP can be idle before
it is unloaded. A value of zero or less indicates never unload.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">keepgenerated</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Do you want to keep the generated Java files around?</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">mappedFile</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Support for mapped Files. Generates a servlet that has a
print statement per line of the JSP file </p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">maxLoadedJsps</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The maximum number of JSPs that will be loaded for a web
application. If more than this number of JSPs are loaded, the least
recently used JSPs will be unloaded so that the number of JSPs loaded at
any one time does not exceed this limit. A value of zero or less
indicates no limit.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">modificationTestInterval</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If <code>development=true</code>, interval between
recompilation checks, triggered by a request.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">quoteAttributeEL</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">When EL is used in an attribute value on a JSP page, should the rules for quoting of attributes described in JSP.1.6 be applied to the expression</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">recompileOnFail</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">If a JSP compilation fails should the
modificationTestInterval be ignored and the next access trigger a
re-compilation attempt? Used in development mode only and is disabled by
default as compilation may be expensive and could lead to excessive
resource usage.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">scratchDir</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Directory where servlets are generated. The default is the value of the context attribute <code>javax.servlet.context.tempdir</code>, or the system property <code>java.io.tmpdir</code> if the context attribute is not set.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">strictQuoteEscaping</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Should the quote escaping required by section JSP.1.6 of the JSP specification be applied to scriplet expression.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TRUE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">-</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">suppressSmap</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Generation of SMAP info for JSR45 debugging.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">trimSpaces</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Should template text that consists entirely of whitespace be removed from the output (true), replaced with a single space (single) or left unchanged (false)? Note that if a JSP page or tag file specifies a trimDirectiveWhitespaces value of true, that will take precedence over this configuration setting for that page/tag.
trimmed?</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">xpoweredBy</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Generate an X-Powered-By response header.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">FALSE</p></td>
</tr>
</tbody>
</table>
<div class="dlist">
<dl>
<dt class="hdlist1">NOTE</dt>
<dd>
<p>If the value you set doesn&#8217;t take effect, try using all lower case instead of camel case, or capitalizing only some of the words in the name, as Jasper is inconsistent in its parameter naming strategy.</p>
</dd>
</dl>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-javaserver-pages-standard-tag-libraries"><a class="anchor" href="#og-javaserver-pages-standard-tag-libraries"></a><a class="link" href="#og-javaserver-pages-standard-tag-libraries">JavaServer Pages Standard Tag Libraries</a></h3>
<div class="paragraph">
<p>The JavaServer Pages Standlard Tag Library (JSTL) is part of the Jetty distribution, and is available via the <code>jstl</code> module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre># DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
[description]
Enables JSTL for all web applications deployed on the server.
[depend]
jsp
apache-jstl</pre>
</div>
</div>
<div class="paragraph">
<p>When enabled, Jetty will make the JSTL tags available for your webapps.</p>
</div>
</div>
<div class="sect2">
<h3 id="og-javaserver-faces-taglibs"><a class="anchor" href="#og-javaserver-faces-taglibs"></a><a class="link" href="#og-javaserver-faces-taglibs">JavaServer Faces Taglibs</a></h3>
<div class="paragraph">
<p>If you want to use JSF with your webapp, you should copy the relevant jars from your implementation of choice into your <code>$jetty.base</code> directory, ideally into <code>$jetty.base/lib/ext</code>.
If that directory does not exist, enable the <code>ext</code> module, which will create the directory and ensure all jars within it are put onto the container classpath.</p>
</div>
<div class="paragraph">
<p>Then you will need to tell Jetty which of those jars contains the <code>*.tld</code> files.
To accomplish that, you need to specify either the name of the file or a pattern that matches the name/s of the file/s as the <code>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</code> context attribute.
You will need to preserve the existing value of the attribute, and add in your extra pattern.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example of using a context xml file to add in a pattern to match files starting with <code>jsf-</code>, which contain the <code>*.tld</code> files:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Call name="setAttribute"&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;Arg&gt;org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern&lt;/Arg&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;Arg.*/jetty-servlet-api-[^/]*\.jar$|.*/javax.servlet.jsp.jstl-.*\.jar$|.*/org.apache.taglibs.taglibs-standard-impl-.*\.jar$|.*/jsf-[^/]*\.jar$&gt;&lt;/Arg&gt; <i class="conum" data-value="4"></i><b>(4)</b>
&lt;/Call&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Configures a <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/webapp/WebAppContext.html"><code>WebAppContext</code></a>, which is the Jetty component that represents a standard Servlet web application.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Specifies a context attribute.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Specifies the name of the context attribute.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Adds the additional pattern <code>.*/jsf-[^/]*\.jar$</code> to those already existing.</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="og-jndi"><a class="anchor" href="#og-jndi"></a><a class="link" href="#og-jndi">JNDI</a></h3>
<div class="paragraph">
<p>Enable the <code>plus</code> module in order to be able to use JNDI resources in your webapp.
If you already have the <code>annotations</code> module enabled, then it will already be enabled.</p>
</div>
<div class="paragraph">
<p>If you have extra jars associated with your JNDI resources, eg database drivers etc, that are not located inside your webapp then you should place those jars into your <code>$jetty.base/lib/ext</code> directory.
If your base doesn&#8217;t already contain this directory, then enable the <code>ext</code> module, and Jetty will create the directory for you and ensure its contents are on the server&#8217;s classpath.</p>
</div>
<div class="paragraph">
<p>You can now declare JNDI resources and reference them within your webapps.</p>
</div>
<div class="sect3">
<h4 id="og-declaring-resources"><a class="anchor" href="#og-declaring-resources"></a><a class="link" href="#og-declaring-resources">Declaring resources</a></h4>
<div class="paragraph">
<p>You must declare the objects you want bound into the environment so that you can then hook them into your webapp via <code>env-entry</code>, <code>resource-ref</code> and <code>resource-env-refs</code> in <code>web.xml</code>, <code>web-fragment.xml</code> or <code>override-web.xml</code>.</p>
</div>
<div class="paragraph">
<p>You make these declarations in Jetty XML files that are either <em>external</em> or <em>internal</em> to your webapp.
A server or context XML file is external to your webapp.
The special <code>WEB-INF/jetty-env.xml</code> file is internal to your webapp.
See the section on <a href="#og-jndi-xml">Jetty XML files</a> for more information on how to choose in which XML file to place your declarations.</p>
</div>
<div class="paragraph">
<p>For now, let&#8217;s look at <em>what</em> you declare in the XML file, regardless of its location.</p>
</div>
<div class="paragraph">
<p>Declaring a JDNI resource to be referenced later in your webapp is accomplished by declaring new instances of the following types:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1"><a href="#og-jndi-env"><code>org.eclipse.jetty.plus.jndi.EnvEntry</code></a></dt>
<dd>
<p>Used for <code>env-entry</code> type of entries</p>
</dd>
<dt class="hdlist1"><a href="#og-jndi-resource"><code>org.eclipse.jetty.plus.jndi.Resource</code></a></dt>
<dd>
<p>Used for most other type of resources</p>
</dd>
<dt class="hdlist1"><a href="#og-jndi-tx"><code>org.eclipse.jetty.plus.jndi.Transaction</code></a></dt>
<dd>
<p>For a JTA manager</p>
</dd>
<dt class="hdlist1"><a href="#og-jndi-link"><code>org.eclipse.jetty.plus.jndi.Link</code></a></dt>
<dd>
<p>For the link between a <code>web.xml</code> resource name and a naming entry</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>Declarations of each of these types follow a similar pattern:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;New class="org.eclipse.jetty.plus.jndi.xxxx"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Arg&gt;&lt;!-- scope --&gt;&lt;/Arg&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;Arg&gt;&lt;!-- name --&gt;&lt;/Arg&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;Arg&gt;&lt;!-- value --&gt;&lt;/Arg&gt; <i class="conum" data-value="4"></i><b>(4)</b>
&lt;/New&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Defines a resource to Jetty.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Specifies the <a href="#og-jndi-scope">scope</a> of the resource.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Specifies the name of the resource which will be looked up by the webapp relative to the <code>java:comp/env</code> namespace.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Specifies the value of the resource.</td>
</tr>
</table>
</div>
<div class="sect4">
<h5 id="og-jndi-env"><a class="anchor" href="#og-jndi-env"></a><a class="link" href="#og-jndi-env">org.eclipse.jetty.plus.jndi.EnvEntry</a></h5>
<div class="paragraph">
<p>Sometimes it is useful to pass configuration information to a webapp at runtime that you either cannot or cannot conveniently code into a <code>web.xml</code> <code>&lt;env-entry&gt;</code>.
In such cases, you can use the <code>org.eclipse.jetty.plus.jndi.EnvEntry</code> class, and optionally even override an entry of the same name in <code>web.xml</code>.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example that defines the equivalent of an <code>env-entry</code> called <code>mySpecialValue</code> with value <code>4000</code> that overrides an <code>&lt;env-entry&gt;</code> declaration of the same name in web.xml:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;New class="org.eclipse.jetty.plus.jndi.EnvEntry"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Arg&gt;&lt;/Arg&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;Arg&gt;mySpecialValue&lt;/Arg&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;Arg type="java.lang.Integer"&gt;4000&lt;/Arg&gt; <i class="conum" data-value="4"></i><b>(4)</b>
&lt;Arg type="boolean"&gt;true&lt;/Arg&gt; <i class="conum" data-value="5"></i><b>(5)</b>
&lt;/New&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Define an <code>EnvEntry</code> that corresponds to an <code>&lt;env-entry&gt;</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td><a href="#og-jndi-scope">Scoped</a> at the JVM level.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>The name of the entry, corresponding to a lookup by the webapp of <code>java:comp/env/mySpecialValue</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>The value of the entry, in this case the integer value <code>4000</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="5"></i><b>5</b></td>
<td><code>true</code> means to override the value of an <code>&lt;env-entry&gt;</code> of the same name in <code>web.xml</code>.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Note that if you don&#8217;t want to override the <code>web.xml</code> value, simply omit the last argument, or set it to <code>false</code>.</p>
</div>
<div class="paragraph">
<p>The Servlet Specification allows binding only the following object types to an <code>env-entry</code>:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>java.lang.String</p>
</li>
<li>
<p>java.lang.Integer</p>
</li>
<li>
<p>java.lang.Float</p>
</li>
<li>
<p>java.lang.Double</p>
</li>
<li>
<p>java.lang.Long</p>
</li>
<li>
<p>java.lang.Short</p>
</li>
<li>
<p>java.lang.Character</p>
</li>
<li>
<p>java.lang.Byte</p>
</li>
<li>
<p>java.lang.Boolean</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Jetty is a little more flexible and allows you to also bind:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>custom POJOs</p>
</li>
<li>
<p><a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/naming/Reference.html"><code>javax.naming.References</code></a></p>
</li>
<li>
<p><a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/naming/Referenceable.html"><code>javax.naming.Referenceables</code></a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Be aware that if you take advantage of this feature, your web application is <em>not portable</em>.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-jndi-resource"><a class="anchor" href="#og-jndi-resource"></a><a class="link" href="#og-jndi-resource">org.eclipse.jetty.plus.jndi.Resource</a></h5>
<div class="paragraph">
<p>You can configure any type of resource that you want to refer to in <code>web.xml</code> via a <code>resource-ref</code> or <code>resource-env-ref</code> by using the <code>org.eclipse.jetty.plus.jndi.Resource</code> type of naming entry.</p>
</div>
<div class="paragraph">
<p>You provide the scope, the name of the object (relative to <code>java:comp/env</code>) and a POJO, <code>javax.naming.Reference</code> or <code>javax.naming.Referenceable</code> instance.</p>
</div>
<div class="paragraph">
<p>Let&#8217;s examine how to configure some of the most common types of resources.</p>
</div>
<div class="sect5">
<h6 id="og-datasources"><a class="anchor" href="#og-datasources"></a><a class="link" href="#og-datasources">DataSources</a></h6>
<div class="paragraph">
<p>In this example, we&#8217;ll configure a <a href="http://db.apache.org/derby">Derby</a> DataSource named <code>jdbc/myds</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;New class="org.eclipse.jetty.plus.jndi.Resource"&gt;
&lt;Arg&gt;&lt;Ref refid="wac"/&gt;&lt;/Arg&gt;
&lt;Arg&gt;jdbc/myds&lt;/Arg&gt;
&lt;Arg&gt;
&lt;New class="org.apache.derby.jdbc.EmbeddedDataSource"&gt;
&lt;Set name="DatabaseName"&gt;test&lt;/Set&gt;
&lt;Set name="createDatabase"&gt;create&lt;/Set&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>This would linked into the webapps JNDI namespace via an entry in a <code>web.xml</code> like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;resource-ref&gt;
&lt;res-ref-name&gt;jdbc/myds&lt;/res-ref-name&gt;
&lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
&lt;res-auth&gt;Container&lt;/res-auth&gt;
&lt;/resource-ref&gt;</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>When configuring Resources, ensure that the type of object you configure matches the type of object you expect to look up in <code>java:comp/env</code>.
For database connection factories, this means that the object you register as a Resource <em>must</em> implement the <code>javax.sql.DataSource</code> interface.</p>
</div>
<div class="paragraph">
<p>Also note that the <a href="http://jcp.org/aboutJava/communityprocess/pr/jsr244/index.html">J2EE Specification</a> recommends storing DataSources relative to <code>jdbc/</code> and thus looked up by the application as <code>java:comp/env/jdbc/xxx</code>.
Eg The Datasource bound in Jetty as <code>jdbc/users</code> would be looked up by the application as <code>java:comp/env/jdbc/users</code></p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect5">
<h6 id="og-jms-queues-topics-and-connectionfactories"><a class="anchor" href="#og-jms-queues-topics-and-connectionfactories"></a><a class="link" href="#og-jms-queues-topics-and-connectionfactories">JMS Queues, Topics and ConnectionFactories</a></h6>
<div class="paragraph">
<p>Jetty can bind any implementation of the JMS destinations and connection factories.</p>
</div>
<div class="paragraph">
<p>Here is an example of binding an <a href="http://activemq.apache.org">ActiveMQ</a> in-JVM connection factory:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;New class="org.eclipse.jetty.plus.jndi.Resource"&gt;
&lt;Arg&gt;&lt;Ref refid='wac'/&gt;&lt;/Arg&gt;
&lt;Arg&gt;jms/connectionFactory&lt;/Arg&gt;
&lt;Arg&gt;
&lt;New class="org.apache.activemq.ActiveMQConnectionFactory"&gt;
&lt;Arg&gt;vm://localhost?broker.persistent=false&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The corresponding entry in <code>web.xml</code> to bind the ConnectionFactory into the webapp&#8217;s JNDI namespace would be:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;resource-ref&gt;
&lt;res-ref-name&gt;jms/connectionFactory&lt;/res-ref-name&gt;
&lt;res-type&gt;javax.jms.ConnectionFactory&lt;/res-type&gt;
&lt;res-auth&gt;Container&lt;/res-auth&gt;
&lt;/resource-ref&gt;</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The <a href="http://jcp.org/aboutJava/communityprocess/pr/jsr244/index.html">J2EE Specification</a> recommends storing JMS connection factories under <code>jms/</code>.
Eg The ConnectionFactory bound in Jetty as <code>jms/inqueue</code> would be looked up by the application as <code>java:comp/env/jms/inqueue</code>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect5">
<h6 id="og-mail"><a class="anchor" href="#og-mail"></a><a class="link" href="#og-mail">Mail</a></h6>
<div class="paragraph">
<p>To configure access to <code>javax.mail.Session</code> from within a webapp, declare an <code>org.eclipse.jetty.plus.jndi.Resource</code> with an <code>org.eclipse.jetty.jndi.factories.MailSessionReference</code> that will hold the mail configuration and create the instance of the <code>Session</code> when it is referenced:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;New class="org.eclipse.jetty.plus.jndi.Resource"&gt;
&lt;Arg&gt;&lt;Ref refid="wac"/&gt;&lt;/Arg&gt;
&lt;Arg&gt;mail/Session&lt;/Arg&gt;
&lt;Arg&gt;
&lt;New class="org.eclipse.jetty.jndi.factories.MailSessionReference"&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Set name="user"&gt;fred&lt;/Set&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;Set name="password"&gt;OBF:1xmk1w261z0f1w1c1xmq&lt;/Set&gt; <i class="conum" data-value="3"></i><b>(3)</b>
&lt;Set name="properties"&gt; <i class="conum" data-value="4"></i><b>(4)</b>
&lt;New class="java.util.Properties"&gt;
&lt;Put name="mail.smtp.host"&gt;XXX&lt;/Put&gt;
&lt;Put name="mail.from"&gt;me@me&lt;/Put&gt;
&lt;Put name="mail.debug"&gt;true&lt;/Put&gt;
&lt;/New&gt;
&lt;/Set&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Use the <code>org.eclipse.jetty.jndi.factories.MailSessionReference</code> class to hold the configuration.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Set the username for the mail instance.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Set the password for the mail instance - use Jetty&#8217;s secure password obfuscation to obscure the password.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Set all other applicable properties.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The webapp performs a lookup for <code>java:comp/env/mail/Session</code> at runtime and obtains a <code>javax.mail.Session</code> that has the correct configuration to permit it to send email via SMTP.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Jetty does not provide the <code>javax.mail</code> and <code>javax.activation</code> jars.</p>
</div>
<div class="paragraph">
<p>Note also that the <a href="http://jcp.org/aboutJava/communityprocess/pr/jsr244/index.html">J2EE Specification</a> recommends storing JavaMail connection factories under <code>mail/</code>.
Eg The <code>MailSessionReference</code> bound to jetty as <code>mail/smtp</code> would be looked up by the application as <code>java:comp/env/mail/smtp</code>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect4">
<h5 id="og-jndi-tx"><a class="anchor" href="#og-jndi-tx"></a><a class="link" href="#og-jndi-tx">org.eclipse.jetty.plus.jndi.Transaction</a></h5>
<div class="paragraph">
<p>To perform distributed transactions with your resources, a <em>transaction manager</em> that supports the JTA interfaces is required.
The transaction manager is looked up by the application as <code>java:comp/UserTransaction</code>.</p>
</div>
<div class="paragraph">
<p>Jetty does not ship with a JTA manager, but <em>does</em> provide the infrastructure to plug in the JTA manager of your choice.</p>
</div>
<div class="paragraph">
<p>Use the <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/plus/jndi/Transaction.html">org.eclipse.jetty.plus.jndi.Transaction</a> object in a <a href="#og-jndi-xml">Jetty XML file</a> to configure the JTA manager.</p>
</div>
<div class="paragraph">
<p>The following example configures the <a href="http://www.atomikos.com/">Atomikos</a> transaction manager:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction"&gt;
&lt;Arg&gt;
&lt;New class="com.atomikos.icatch.jta.J2eeUserTransaction"/&gt;
&lt;/Arg&gt;
&lt;/New&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Jetty will automatically bind this JTA manager to the webapp&#8217;s JNDI namespace at <code>java:comp/UserTransaction</code>.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-jndi-link"><a class="anchor" href="#og-jndi-link"></a><a class="link" href="#og-jndi-link">org.eclipse.jetty.plus.jndi.Link</a></h5>
<div class="paragraph">
<p>Usually, the name you provide for the <code>org.eclipse.jetty.plus.jndi.Resource</code> is the same name you reference in <code>web.xml</code>.
This ensures that the two are linked together and thus accessible to your webapp.</p>
</div>
<div class="paragraph">
<p>However, if the names cannot be the same, then it is possible to effectively alias one to another using an <code>org.eclipse.jetty.plus.jndi.Link</code>.</p>
</div>
<div class="paragraph">
<p>Let&#8217;s look at an example.</p>
</div>
<div class="paragraph">
<p>Supposing you have a declaration for a Datasource named <code>jdbc/workforce</code> in a Jetty context XML file, but your web.xml wants to link to a <code>&lt;resource-ref&gt;</code> named <code>jdbc/employees</code>, and you cannot edit the web.xml.
You can create a <code>WEB-INF/jetty-env.xml</code> file with an <code>org.eclipse.jetty.plus.jndi.Link</code> that ties together the names <code>jdbc/workforce</code> and <code>jdbc/employees</code>:</p>
</div>
<div class="paragraph">
<p>The context XML file declares <code>jdbc/workforce</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;New class="org.eclipse.jetty.plus.jndi.Resource"&gt;
&lt;Arg&gt;&lt;Ref refid="wac"/&gt;&lt;/Arg&gt;
&lt;Arg&gt;jdbc/workforce&lt;/Arg&gt;
&lt;Arg&gt;
&lt;New class="org.apache.derby.jdbc.EmbeddedDataSource"&gt;
&lt;Set name="DatabaseName"&gt;test&lt;/Set&gt;
&lt;Set name="createDatabase"&gt;create&lt;/Set&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>web.xml</code> refers to it as <code>jdbc/employees</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;resource-ref&gt;
&lt;res-ref-name&gt;jdbc/employees&lt;/res-ref-name&gt;
&lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
&lt;res-auth&gt;Container&lt;/res-auth&gt;
&lt;/resource-ref&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Create a <code>WEB-INF/jetty-env.xml</code> file with a <code>org.eclipse.jetty.plus.jndi.Link</code> to link these names together:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;New class="org.eclipse.jetty.plus.jndi.Link"&gt;
&lt;Arg&gt;&lt;Ref refid='wac'/&gt;&lt;/Arg&gt;
&lt;Arg&gt;jdbc/employees&lt;/Arg&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Arg&gt;jdbc/workforce&lt;/Arg&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;/New&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The name as referenced in the <code>web.xml</code> file.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The name as referenced in the context XML file.</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="og-jndi-xml"><a class="anchor" href="#og-jndi-xml"></a><a class="link" href="#og-jndi-xml">Jetty XML files</a></h5>
<div class="paragraph">
<p>You can define naming resources in three places:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">Server XML file</dt>
<dd>
<p>Naming resources defined in a server XML file are <a href="#og-jndi-scope">scoped</a> at either the JVM level or the <code>org.eclipse.jetty.server.Server</code> level.
The classes for the resource <em>must</em> be visible at the Jetty <strong>container</strong> level.
If instead the classes for the resource only exist inside your webapp, you must declare it in a <code>WEB-INF/jetty-env.xml</code> file.</p>
</dd>
<dt class="hdlist1">Context XML file</dt>
<dd>
<p>Entries in a context XML file should be <a href="#og-jndi-scope">scoped</a> at the level of the webapp to which they apply (although it is possible to use a less strict scoping level of Server or JVM, but not recommended).
As with resources declared in a server XML file, classes associated with the resource <em>must</em> be visible on the <strong>container&#8217;s</strong> classpath.</p>
</dd>
<dt class="hdlist1">WEB-INF/jetty-env.xml</dt>
<dd>
<p>Naming resources in a <code>WEB-INF/jetty-env.xml</code> file are <a href="#og-jndi-scope">scoped</a> to the webapp in which the file resides.
While you can enter JVM or Server scopes if you choose, we do not recommend doing so.
The resources defined here may use classes from inside your webapp.</p>
</dd>
</dl>
</div>
</div>
<div class="sect4">
<h5 id="og-jndi-scope"><a class="anchor" href="#og-jndi-scope"></a><a class="link" href="#og-jndi-scope">Resource scoping</a></h5>
<div class="paragraph">
<p>Naming resources within Jetty belong to one of three different scopes, in increasing order of restrictiveness:</p>
</div>
<div class="paragraph">
<p><strong>JVM scope:</strong>
The name is unique across the JVM instance, and is visible to all application code.
This scope is represented by a <code>null</code> first parameter to the resource declaration.
For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;New id="cf" class="org.eclipse.jetty.plus.jndi.Resource"&gt;
&lt;Arg&gt;&lt;/Arg&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Arg&gt;jms/connectionFactory&lt;/Arg&gt;
&lt;Arg&gt;
&lt;New class="org.apache.activemq.ActiveMQConnectionFactory"&gt;
&lt;Arg&gt;vm://localhost?broker.persistent=false&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;/New&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Empty first arg equates to JVM scope for the object bound to name <code>jms/connectionFactory</code>.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p><strong>Server scope:</strong>
The name is unique to a Server instance, and is only visible to applications associated with that instance.
This scope is represented by referencing the Server instance as the first parameter to the resource declaration.
For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;New id="cf" class="org.eclipse.jetty.plus.jndi.Resource"&gt;
&lt;Arg&gt;&lt;Ref refid="Server"/&gt;&lt;/Arg&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Arg&gt;jms/connectionFactory&lt;/Arg&gt;
&lt;Arg&gt;
&lt;New class="org.apache.activemq.ActiveMQConnectionFactory"&gt;
&lt;Arg&gt;vm://localhost?broker.persistent=false&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;/New&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>We refer to the id <code>Server</code> which identifies the default <code>org.eclipse.jetty.server.Server</code> instance.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p><strong>Webapp scope:</strong>
The name is unique to the <code>org.eclipse.jetty.webapp.WebAppContext</code> instance, and is only visible to that application.
This scope is represented by referencing the instance as the first parameter to the resource declaration.
For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;New class="org.eclipse.jetty.plus.jndi.Resource"&gt;
&lt;Arg&gt;&lt;Ref refid='wac'/&gt;&lt;/Arg&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Arg&gt;jms/connectionFactory&lt;/Arg&gt;
&lt;Arg&gt;
&lt;New class="org.apache.activemq.ActiveMQConnectionFactory"&gt;
&lt;Arg&gt;vm://localhost?broker.persistent=false&lt;/Arg&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;/New&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>We refer to an instance of an <code>org.eclipse.jetty.webapp.WebAppContext</code> which has been previously defined.</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-jaas"><a class="anchor" href="#og-jaas"></a><a class="link" href="#og-jaas">JAAS</a></h3>
<div class="paragraph">
<p>JAAS implements a Java version of the standard Pluggable Authentication Module (PAM) framework.</p>
</div>
<div class="paragraph">
<p>JAAS can be used for two purposes:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>for authentication of users, to reliably and securely determine who is currently executing Java code, regardless of whether the code is running as an application, an applet, a bean, or a servlet</p>
</li>
<li>
<p>for authorization of users to ensure they have the access control rights (permissions) required to do the actions performed</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>JAAS authentication is performed in a pluggable fashion.
This permits applications to remain independent from underlying authentication technologies.
New or updated authentication technologies can be plugged under an application without requiring modifications to the application itself.</p>
</div>
<div class="paragraph">
<p>See Java Authentication and Authorization Service (JAAS) <a href="http://java.sun.com/javase/7/docs/technotes/guides/security/jaas/JAASRefGuide.html">Reference Guide</a> for more information about JAAS.</p>
</div>
<div class="paragraph">
<p>The Jetty JAAS support aims to dictate as little as possible whilst providing a sufficiently flexible infrastructure to allow users to drop either one of the <a href="#og-jaas-loginmodules">JAAS Login Modules that ships with Jetty</a>, or their
own custom <a href="https://docs.oracle.com/javase/7/docs/api/javax/security/auth/spi/LoginModule.html">LoginModules</a>.</p>
</div>
<div class="sect3">
<h4 id="og-jaas-configuration"><a class="anchor" href="#og-jaas-configuration"></a><a class="link" href="#og-jaas-configuration">Configuration</a></h4>
<div class="sect4">
<h5 id="og-jaas-module"><a class="anchor" href="#og-jaas-module"></a><a class="link" href="#og-jaas-module">The <code>jaas</code> module</a></h5>
<div class="paragraph">
<p>Enable the <code>jaas</code> module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre># DO NOT EDIT - See: https://www.eclipse.org/jetty/documentation/current/startup-modules.html
[description]
Enables JAAS for deployed web applications.
[depend]
server
[lib]
lib/jetty-jaas-${jetty.version}.jar
[xml]
etc/jetty-jaas.xml
[ini-template]
## The file location (relative to $jetty.base) for the
## JAAS "java.security.auth.login.config" system property
# jetty.jaas.login.conf=etc/login.conf</pre>
</div>
</div>
<div class="paragraph">
<p>The configurable items in the resulting <code>$jetty.base/start.d/jaas.ini</code> file are:</p>
</div>
<div class="dlist">
<dl>
<dt class="hdlist1">jetty.jaas.login.conf</dt>
<dd>
<p>This is the location of the file that will be referenced by the System property <code>java.security.auth.login.config</code>: Jetty sets this System property for you based on the value of this property.
The value of this property is assumed to be <em>relative to the <code>$jetty.base</code></em>.
The default value is <code>etc/login.conf</code>, which resolves to <code>$jetty.base/etc/login.conf</code>.
If you don&#8217;t want to put your login module configuration file here, you can change this property to point to where it is.</p>
</dd>
</dl>
</div>
<div class="paragraph">
<p>See more about the contents of this file in the <a href="#og-jaas-loginconf">Configuring JAAS</a> section.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-jaas-webapp"><a class="anchor" href="#og-jaas-webapp"></a><a class="link" href="#og-jaas-webapp">Configure the webapp for JAAS</a></h5>
<div class="paragraph">
<p>The <code>&lt;realm-name&gt;</code> in <code>web.xml</code> will be used to identify the <code>org.eclipse.jetty.jaas.JAASLoginService</code> declaration that integrates JAAS with Jetty.</p>
</div>
<div class="paragraph">
<p>For example, this <code>web.xml</code> contains a realm called <code>Test JAAS Realm</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;login-config&gt;
&lt;auth-method&gt;FORM&lt;/auth-method&gt;
&lt;realm-name&gt;Test JAAS Realm&lt;/realm-name&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;form-login-config&gt;
&lt;form-login-page&gt;/login/login&lt;/form-login-page&gt;
&lt;form-error-page&gt;/login/error&lt;/form-error-page&gt;
&lt;/form-login-config&gt;
&lt;/login-config&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The name of the realm, which must be <em>identical</em> to the name of an <code>org.eclipse.jetty.jaas.JAASLoginService</code> declaration.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>We now need to declare an <code>org.eclipse.jetty.jaas.JAASLoginService</code> that references the realm name of <code>Test JAAS Realm</code>.
Here&#8217;s an example of a suitable XML snippet:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;New class="org.eclipse.jetty.jaas.JAASLoginService"&gt;
&lt;Set name="Name"&gt;Test JAAS Realm&lt;/Set&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;Set name="LoginModuleName"&gt;xyz&lt;/Set&gt; <i class="conum" data-value="2"></i><b>(2)</b>
&lt;/New&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The name is the <em>same</em> as that declared in the <code>&lt;realm-name&gt;</code> in <code>web.xml</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The name that identifies a set of <code>javax.security.auth.spi.LoginModule</code> configurations that comprise the <a href="#og-jaas-loginconf">JAAS config file</a> identified in the <code>jetty.jaas.login.conf</code> property of the <a href="#og-jaas-module"><code>jaas</code> module</a>.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The <code>org.eclipse.jetty.jaas.JAASLoginService</code> can be declared in a couple of different places, pick whichever suits your purposes best:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>If you have more than one webapp that you would like to use the same security infrastructure, then you can declare your <code>org.eclipse.jetty.jaas.JAASLoginService</code> as a bean that is added to the <code>org.eclipse.jetty.server.Server</code>.
The file in which you declare this needs to be on Jetty&#8217;s execution path.
The recommended procedure is to create a file in your <code>$jetty.base/etc</code> directory and then ensure it is on the classpath either by adding it to the Jetty <a href="#og-start-jar">start command line</a>, or more conveniently to a <a href="#custom-modules">custom module</a>.</p>
<div class="paragraph">
<p>Here&#8217;s an example of this type of XML file:</p>
</div>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre>&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure id="Server" class="org.eclipse.jetty.server.Server"&gt;
&lt;Call name="addBean"&gt;
&lt;Arg&gt;
&lt;New class="org.eclipse.jetty.jaas.JAASLoginService"&gt;
&lt;Set name="name"&gt;Test JAAS Realm&lt;/Set&gt;
&lt;Set name="LoginModuleName"&gt;xyz&lt;/Set&gt;
&lt;/New&gt;
&lt;/Arg&gt;
&lt;/Call&gt;
&lt;/Configure&gt;</pre>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>Alternatively, if you want to use JAAS with a specific webapp only, you declare your <code>org.eclipse.jetty.jaas.JAASLoginService</code> in a context XLM file specific to that webapp:</p>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-xml" data-lang="xml">&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd"&gt;
&lt;Configure class="org.eclipse.jetty.webapp.WebAppContext"&gt;
&lt;Set name="securityHandler"&gt;
&lt;New class="org.eclipse.jetty.security.ConstraintSecurityHandler"&gt;
&lt;Set name="loginService"&gt;
&lt;New class="org.eclipse.jetty.jaas.JAASLoginService"&gt;
&lt;Set name="name"&gt;Test JAAS Realm&lt;/Set&gt;
&lt;Set name="loginModuleName"&gt;xyz&lt;/Set&gt;
&lt;/New&gt;
&lt;/Set&gt;
&lt;/New&gt;
&lt;/Set&gt;
&lt;/Configure&gt;</code></pre>
</div>
</div>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="og-jaas-loginconf"><a class="anchor" href="#og-jaas-loginconf"></a><a class="link" href="#og-jaas-loginconf">Configure JAAS</a></h5>
<div class="paragraph">
<p>We now need to setup the contents of the file we specified as the <code>jetty.jaas.login.conf</code> property when we <a href="#og-jaas-module">configured the <code>jaas</code> module</a>.
Refer to the <a href="https://docs.oracle.com/javase/7/docs/api/javax/security/auth/login/Configuration.html">syntax rules</a> of this file for a full description.</p>
</div>
<div class="paragraph">
<p>Remembering the example we set up <a href="#og-jaas-webapp">previously</a>, the contents of the <code>$jetty.base/etc/login.conf</code> file could look as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-ini" data-lang="ini">xyz { <i class="conum" data-value="1"></i><b>(1)</b>
com.acme.SomeLoginModule required debug=true; <i class="conum" data-value="2"></i><b>(2)</b>
com.other.OtherLoginModule optional; <i class="conum" data-value="3"></i><b>(3)</b>
};</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The name of the configuration <em>exactly</em> as specified in your <code>org.eclipse.jetty.jaas.JAASLoginService</code> declaration.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The first <code>LoginModule</code> declaration, containing the classname of the <code>LoginModule</code> and its configuration properties.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>A second <code>LoginModule</code> declaration.
You can provide as many <code>LoginModule</code> alternatives as you like, with a minimum of one.
Refer to the <a href="https://docs.oracle.com/javase/7/docs/api/javax/security/auth/login/Configuration.html">JAAS documentation</a> for more information on the standard configuration properties, and how JAAS interprets this file.</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect3">
<h4 id="og-jaas-loginmodules"><a class="anchor" href="#og-jaas-loginmodules"></a><a class="link" href="#og-jaas-loginmodules">Provided LoginModules</a></h4>
<div class="ulist">
<ul>
<li>
<p><a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/jaas/spi/JDBCLoginModule.html"><code>org.eclipse.jetty.jaas.spi.JDBCLoginModule</code></a></p>
</li>
<li>
<p><a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/jaas/spi/PropertyFileLoginModule.html"><code>org.eclipse.jetty.jaas.spi.PropertyFileLoginModule</code></a></p>
</li>
<li>
<p><a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/jaas/spi/DataSourceLoginModule.html"><code>org.eclipse.jetty.jaas.spi.DataSourceLoginModule</code></a></p>
</li>
<li>
<p><a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/jaas/spi/LdapLoginModule.html"><code>org.eclipse.jetty.jaas.ldap.LdapLoginModule</code></a></p>
</li>
</ul>
</div>
<div class="quoteblock">
<blockquote>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Passwords can be stored in clear text, obfuscated or checksummed.
The class <a href="http://www.eclipse.org/jetty/javadoc/11.0.0/org/eclipse/jetty/util/security/Password.html"><code>org.eclipse.jetty.util.security.Password</code></a> should be used to generate all varieties of passwords,the output from which can be put in to property files or entered into database tables.
</td>
</tr>
</table>
</div>
</blockquote>
</div>
<div class="sect4">
<h5 id="og-jdbcloginmodule"><a class="anchor" href="#og-jdbcloginmodule"></a><a class="link" href="#og-jdbcloginmodule">JDBCLoginModule</a></h5>
<div class="paragraph">
<p>The <code>org.eclipse.jetty.jaas.spi.JDBCLoginModule</code> stores user passwords and roles in a database accessed via JDBC calls.
You can configure the JDBC connection information, as well as the names of the table and columns storing the username and credential, and the names of the table and columns storing the roles.</p>
</div>
<div class="paragraph">
<p>Here is an example <a href="#og-jaas-loginconf">login module configuration file</a> entry for it using an HSQLDB driver:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-ini" data-lang="ini">jdbc { <i class="conum" data-value="1"></i><b>(1)</b>
org.eclipse.jetty.jaas.spi.JDBCLoginModule required <i class="conum" data-value="2"></i><b>(2)</b><i class="conum" data-value="3"></i><b>(3)</b>
dbUrl="jdbc:hsqldb:." <i class="conum" data-value="4"></i><b>(4)</b>
dbUserName="sa" <i class="conum" data-value="5"></i><b>(5)</b>
dbDriver="org.hsqldb.jdbcDriver" <i class="conum" data-value="6"></i><b>(6)</b>
userTable="myusers" <i class="conum" data-value="7"></i><b>(7)</b>
userField="myuser" <i class="conum" data-value="8"></i><b>(8)</b>
credentialField="mypassword" <i class="conum" data-value="9"></i><b>(9)</b>
userRoleTable="myuserroles" <i class="conum" data-value="10"></i><b>(10)</b>
userRoleUserField="myuser" <i class="conum" data-value="11"></i><b>(11)</b>
userRoleRoleField="myrole"; <i class="conum" data-value="12"></i><b>(12)</b>
};</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The name of the configuration.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The name of the <code>LoginModule</code> class.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>A standard JAAS flag making successful authentication via this <code>LoginModule</code> mandatory.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>The JDBC url used to connect to the database.</td>
</tr>
<tr>
<td><i class="conum" data-value="5"></i><b>5</b></td>
<td>The name of the JDBC user to use for the connection.</td>
</tr>
<tr>
<td><i class="conum" data-value="6"></i><b>6</b></td>
<td>The name of the JDBC Driver class.</td>
</tr>
<tr>
<td><i class="conum" data-value="7"></i><b>7</b></td>
<td>The name of the table holding the user authenication information.</td>
</tr>
<tr>
<td><i class="conum" data-value="8"></i><b>8</b></td>
<td>The name of the column holding the user name.</td>
</tr>
<tr>
<td><i class="conum" data-value="9"></i><b>9</b></td>
<td>The name of the column holding the user credential.</td>
</tr>
<tr>
<td><i class="conum" data-value="10"></i><b>10</b></td>
<td>The name of the table holding the user authorization information.</td>
</tr>
<tr>
<td><i class="conum" data-value="11"></i><b>11</b></td>
<td>The name of the column holding the user name.</td>
</tr>
<tr>
<td><i class="conum" data-value="12"></i><b>12</b></td>
<td>The name of the column holding the user role.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The properties <strong>7</strong>-<strong>12</strong> are used to format the following queries:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-sql" data-lang="sql"> select &lt;credentialField&gt; from &lt;userTable&gt;
where &lt;userField&gt; =?
select &lt;userRoleRoleField&gt; from &lt;userRoleTable&gt;
where &lt;userRoleUserField&gt; =?</code></pre>
</div>
</div>
<div class="paragraph">
<p>Credential and role information is lazily read from the database when a previously unauthenticated user requests authentication.
Note that this information is <em>only</em> cached for the length of the authenticated session.
When the user logs out or the session expires, the information is flushed from memory.</p>
</div>
<div class="paragraph">
<p>Note that passwords can be stored in the database in plain text or encoded formats - see the note on "Passwords/Credentials" above.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-datasourceloginmodule"><a class="anchor" href="#og-datasourceloginmodule"></a><a class="link" href="#og-datasourceloginmodule">DataSourceLoginModule</a></h5>
<div class="paragraph">
<p>Similar to the <code>org.eclipse.jetty.jaas.spi.JDBCLoginModule</code>, but using a <code>javax.sql.DataSource</code> to connect to the database instead of a JDBC driver.
The <code>javax.sql.DataSource</code> is obtained at runtime by performing a JNDI lookup on <code>java:comp/env/${dnJNDIName}</code>.</p>
</div>
<div class="paragraph">
<p>A sample login module configuration for this <code>LoginModule</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>ds { <i class="conum" data-value="1"></i><b>(1)</b>
org.eclipse.jetty.jaas.spi.DataSourceLoginModule required <i class="conum" data-value="2"></i><b>(2)</b><i class="conum" data-value="3"></i><b>(3)</b>
dbJNDIName="ds" <i class="conum" data-value="4"></i><b>(4)</b>
userTable="myusers" <i class="conum" data-value="5"></i><b>(5)</b>
userField="myuser" <i class="conum" data-value="6"></i><b>(6)</b>
credentialField="mypassword" <i class="conum" data-value="7"></i><b>(7)</b>
userRoleTable="myuserroles" <i class="conum" data-value="8"></i><b>(8)</b>
userRoleUserField="myuser" <i class="conum" data-value="9"></i><b>(9)</b>
userRoleRoleField="myrole"; <i class="conum" data-value="10"></i><b>(10)</b>
};</pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The name of the configuration.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The name of the <code>LoginModule</code> class.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>A standard JAAS flag making successful authentication via this <code>LoginModule</code> mandatory.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>The JNDI name, relative to <code>java:comp/env/</code> to lookup to obtain the <code>javax.sql.DataSource</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="5"></i><b>5</b></td>
<td>The name of the table holding the user authenication information.</td>
</tr>
<tr>
<td><i class="conum" data-value="6"></i><b>6</b></td>
<td>The name of the column holding the user name.</td>
</tr>
<tr>
<td><i class="conum" data-value="7"></i><b>7</b></td>
<td>The name of the column holding the user credential.</td>
</tr>
<tr>
<td><i class="conum" data-value="8"></i><b>8</b></td>
<td>The name of the table holding the user authorization information.</td>
</tr>
<tr>
<td><i class="conum" data-value="9"></i><b>9</b></td>
<td>The name of the column holding the user name.</td>
</tr>
<tr>
<td><i class="conum" data-value="10"></i><b>10</b></td>
<td>The name of the column holding the user role.</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="og-propertyfileloginmodule"><a class="anchor" href="#og-propertyfileloginmodule"></a><a class="link" href="#og-propertyfileloginmodule">PropertyFileLoginModule</a></h5>
<div class="paragraph">
<p>With this login module implementation, the authentication and role information is read from a property file.</p>
</div>
<div class="listingblock">
<div class="content">
<pre>props { <i class="conum" data-value="1"></i><b>(1)</b>
org.eclipse.jetty.jaas.spi.PropertyFileLoginModule required <i class="conum" data-value="2"></i><b>(2)</b><i class="conum" data-value="3"></i><b>(3)</b>
file="/somewhere/somefile.props"; <i class="conum" data-value="4"></i><b>(4)</b>
};</pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The name of the configuration.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The name of the <code>LoginModule</code> class.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>A standard JAAS flag making successful authentication via this <code>LoginModule</code> mandatory.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>The location of a properties file containing the authentication and authorization information.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The property file must be of the format:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-text subs=verbatim" data-lang="text subs=verbatim">&lt;username&gt;: &lt;password&gt; [,&lt;rolename&gt; ...]</code></pre>
</div>
</div>
<div class="paragraph">
<p>Here&#8217;s an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-ini" data-lang="ini">fred: OBF:1xmk1w261u9r1w1c1xmq,user,admin
harry: changeme,user,developer
tom: MD5:164c88b302622e17050af52c89945d44,user
dick: CRYPT:adpexzg3FUZAk,admin</code></pre>
</div>
</div>
<div class="paragraph">
<p>The contents of the file are fully read in and cached in memory the first time a user requests authentication.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-ldaploginmodule"><a class="anchor" href="#og-ldaploginmodule"></a><a class="link" href="#og-ldaploginmodule">LdapLoginModule</a></h5>
<div class="paragraph">
<p>The <code>org.eclipse.jetty.jaas.spi.LdapLoginModule</code> uses LDAP to access authentication and authorization information stored in a directory.
The LDAP connection information and structure of the authentication/authorization data can be configured.</p>
</div>
<div class="paragraph">
<p>Here&#8217;s an example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-ini" data-lang="ini">example { <i class="conum" data-value="1"></i><b>(1)</b>
org.eclipse.jetty.jaas.spi.LdapLoginModule required <i class="conum" data-value="2"></i><b>(2)</b><i class="conum" data-value="3"></i><b>(3)</b>
contextFactory="com.sun.jndi.ldap.LdapCtxFactory" <i class="conum" data-value="4"></i><b>(4)</b>
hostname="ldap.example.com" <i class="conum" data-value="5"></i><b>(5)</b>
port="389" <i class="conum" data-value="6"></i><b>(6)</b>
bindDn="cn=Directory Manager" <i class="conum" data-value="7"></i><b>(7)</b>
bindPassword="directory" <i class="conum" data-value="8"></i><b>(8)</b>
authenticationMethod="simple" <i class="conum" data-value="9"></i><b>(9)</b>
useLdaps="true" <i class="conum" data-value="10"></i><b>(10)</b>
userBaseDn="ou=people,dc=alcatel" <i class="conum" data-value="11"></i><b>(11)</b>
userRdnAttribute="uid" <i class="conum" data-value="12"></i><b>(12)</b>
userIdAttribute="cn" <i class="conum" data-value="13"></i><b>(13)</b>
userPasswordAttribute="userPassword" <i class="conum" data-value="14"></i><b>(14)</b>
userObjectClass="inetOrgPerson" <i class="conum" data-value="15"></i><b>(15)</b>
roleBaseDn="ou=groups,dc=example,dc=com" <i class="conum" data-value="16"></i><b>(16)</b>
roleNameAttribute="cn" <i class="conum" data-value="17"></i><b>(17)</b>
roleMemberAttribute="uniqueMember" <i class="conum" data-value="18"></i><b>(18)</b>
roleObjectClass="groupOfUniqueNames"; <i class="conum" data-value="19"></i><b>(19)</b>
forceBindingLogin="false" <i class="conum" data-value="20"></i><b>(20)</b>
debug="false" <i class="conum" data-value="21"></i><b>(21)</b>
};</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The name of the configuration.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The name of the <code>LoginModule</code> class.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>A standard JAAS flag making successful authentication via this <code>LoginModule</code> mandatory.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>The name of the context factory to use for the LDAP connection.</td>
</tr>
<tr>
<td><i class="conum" data-value="5"></i><b>5</b></td>
<td>The hostname for the LDAP connection. Optional.</td>
</tr>
<tr>
<td><i class="conum" data-value="6"></i><b>6</b></td>
<td>The port for the LDAP connection. Optional.</td>
</tr>
<tr>
<td><i class="conum" data-value="7"></i><b>7</b></td>
<td>The caller security Principal. Optional.</td>
</tr>
<tr>
<td><i class="conum" data-value="8"></i><b>8</b></td>
<td>The caller security credential. Optional.</td>
</tr>
<tr>
<td><i class="conum" data-value="9"></i><b>9</b></td>
<td>The security level for the LDAP connection environment. Optional.</td>
</tr>
<tr>
<td><i class="conum" data-value="10"></i><b>10</b></td>
<td>If true, use <code>ldaps</code> instead of <code>ldap</code> for the connection url.</td>
</tr>
<tr>
<td><i class="conum" data-value="11"></i><b>11</b></td>
<td>The distinguished name of the directory to search for user information.</td>
</tr>
<tr>
<td><i class="conum" data-value="12"></i><b>12</b></td>
<td>The name of the attribute for the user roles.</td>
</tr>
<tr>
<td><i class="conum" data-value="13"></i><b>13</b></td>
<td>The name of the attribute for the user id.</td>
</tr>
<tr>
<td><i class="conum" data-value="14"></i><b>14</b></td>
<td>The name of the attribute for the user password.</td>
</tr>
<tr>
<td><i class="conum" data-value="15"></i><b>15</b></td>
<td>The <code>ObjectClass</code> for users.</td>
</tr>
<tr>
<td><i class="conum" data-value="16"></i><b>16</b></td>
<td>The distinguished name of the directory to search for role information.</td>
</tr>
<tr>
<td><i class="conum" data-value="17"></i><b>17</b></td>
<td>The name of the attribute for roles.</td>
</tr>
<tr>
<td><i class="conum" data-value="18"></i><b>18</b></td>
<td>The name of the attribute storing the user for the roles <code>ObjectClass</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="19"></i><b>19</b></td>
<td>The name of the <code>ObjectClass</code> for roles.</td>
</tr>
<tr>
<td><i class="conum" data-value="20"></i><b>20</b></td>
<td>If true, the authentication proceeds on the basis of a successful LDAP binding using the username and credential provided by the user.
If false, then authentication proceeds based on username and password information retrieved from LDAP.</td>
</tr>
<tr>
<td><i class="conum" data-value="21"></i><b>21</b></td>
<td>If true, failed login attempts are logged on the server.</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-jmx"><a class="anchor" href="#og-jmx"></a><a class="link" href="#og-jmx">Eclipse Jetty Monitoring &amp; Management</a></h3>
<div class="paragraph">
<p>Monitoring and management of a Jetty server is important because it allows you to monitor the status of the server (<em>"Is the server processing requests?"</em>) and to manage&#8201;&#8212;&#8201;i.e. read and possibly change&#8201;&#8212;&#8201;its configuration.</p>
</div>
<div class="paragraph">
<p>The ability to read and change the Jetty configuration is very important for troubleshooting Jetty&#8201;&#8212;&#8201;please refer to the <a href="#og-troubleshooting">troubleshooting section</a> for more information.</p>
</div>
<div class="paragraph">
<p>Jetty relies on the Java Management Extensions (JMX) APIs included in OpenJDK to provide monitoring and management.</p>
</div>
<div class="paragraph">
<p>The JMX APIs support a JVM-local <code>MBeanServer</code>, accessible only from within the JVM itself (or by tools that can <em>attach</em> to a running JVM), and a way to expose the <code>MBeanServer</code> to remote clients via Java&#8217;s RMI (Remote Method Invocation).</p>
</div>
<div class="sect3">
<h4 id="og-jmx-local"><a class="anchor" href="#og-jmx-local"></a><a class="link" href="#og-jmx-local">Enabling Local JMX Support</a></h4>
<div class="paragraph">
<p>As with many other Jetty features, local JMX support is enabled with the <code>jmx</code> Jetty module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=jmx</pre>
</div>
</div>
<div class="paragraph">
<p>With the <code>jmx</code> Jetty module enabled, Jetty components will be exported as JMX <em>MBeans</em> to the JVM platform <code>MBeanServer</code>, so that they can be accessed by JMX compliant tools.</p>
</div>
<div class="paragraph">
<p>Each Jetty component will export to its correspondent MBean relevant configuration parameters, so that a JMX tool can read and possibly change the component configuration through the MBean.</p>
</div>
<div class="paragraph">
<p>Note that the Jetty MBeans are registered into the platform <code>MBeanServer</code>, but are not available to remote clients: they are <em>local</em> to the JVM.</p>
</div>
<div class="paragraph">
<p>This configuration is useful when you develop and test your Jetty server locally.</p>
</div>
<div class="paragraph">
<p>JMX compliant tools such as <a href="https://adoptopenjdk.net/jmc.html">Java Mission Control (JMC)</a> can be started locally on your machine and can attach to other JVMs running on your machine, showing you the registered MBeans among which you will find the Jetty MBeans.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Enabling only the local JMX support is the most secure option for monitoring and management, but only users that have local access to the JVM will be able to browse the MBeans.
If you need to access the MBeans from a remote machine, read <a href="#og-jmx-remote">this section</a>.
</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="og-jmx-remote"><a class="anchor" href="#og-jmx-remote"></a><a class="link" href="#og-jmx-remote">Enabling Remote JMX Support</a></h4>
<div class="paragraph">
<p>There are two ways to configure a Jetty server so that it is possible to access the JVM platform MBeans from remote clients:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Use the <code>com.sun.management.jmxremote</code> and related system properties when starting Jetty.
Unfortunately, this solution does not work well with firewalls, and will not be discussed further.</p>
</li>
<li>
<p>Use the <code>jmx-remote</code> Jetty module.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Both ways use Java&#8217;s Remote Method Invocation (RMI) to communicate between the client and the server.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="title">Refresher: How RMI Works</div>
<div class="paragraph">
<p>A server application that wants to make an object available to remote clients must <em>export</em> the object.</p>
</div>
<div class="paragraph">
<p>Exporting an object creates an RMI <em>stub</em> that contains the host/port of the RMI <em>server</em> that accepts incoming invocations from clients and forwards them to the object.
During the creation of the RMI stub, the host stored in the RMI stub is retrieved from the local name resolution system (for example, in Linux, from <code>/etc/hosts</code>).</p>
</div>
<div class="paragraph">
<p>The RMI stub is then sent, along with a name that uniquely identifies the object, to the RMI <em>registry</em>.
The RMI registry is a service that maps names to RMI stubs; it may be external to both clients and server, although often it is part of the server JVM.</p>
</div>
<div class="paragraph">
<p>When a client application wants to connect to the server object using RMI, it first connects to the RMI registry to download the RMI stub for the RMI server; recall that the RMI stub contains the host/port to connect to the RMI server.
Then, the client uses the RMI stub to connect to the RMI server, typically to a host/port that may be different from the RMI registry host/port (in particular, by default the RMI server port will be different from the RMI registry port).</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Remote access to the platform MBeans, and therefore the Jetty MBeans, is enabled by the <code>jmx-remote</code> Jetty module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=jmx-remote</pre>
</div>
</div>
<div class="paragraph">
<p>This command creates the <code>jmx-remote.ini</code> file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code>JETTY_BASE
└── start.d
└── <mark>jmx-remote.ini</mark></code></pre>
</div>
</div>
<div class="paragraph">
<p>Enabling the <code>jmx-remote</code> module transitively enables the <a href="#og-jmx-local"><code>jmx</code> module</a> as well.</p>
</div>
<div class="paragraph">
<p>The configuration for the RMI registry and the RMI server is specified by a <code>JMXServiceURL</code>.
The string format of an RMI <code>JMXServiceURL</code> is the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>service:jmx:rmi://&lt;rmi_server_host&gt;:&lt;rmi_server_port&gt;/jndi/rmi://&lt;rmi_registry_host&gt;:&lt;rmi_registry_port&gt;/jmxrmi</pre>
</div>
</div>
<div class="paragraph">
<p>Below you can find examples of <code>JMXServiceURL</code>s:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code><strong>service:jmx:rmi:///jndi/rmi:///jmxrmi</strong>
where:
rmi_server_host = local host address
rmi_server_port = randomly chosen
rmi_registry_host = local host address
rmi_registry_port = 1099
<strong>service:jmx:rmi://0.0.0.0:1099/jndi/rmi://0.0.0.0:1099/jmxrmi</strong>
where:
rmi_server_host = any address
rmi_server_port = 1099
rmi_registry_host = any address
rmi_registry_port = 1099
<strong>service:jmx:rmi://localhost:1100/jndi/rmi://localhost:1099/jmxrmi</strong>
where:
rmi_server_host = loopback address
rmi_server_port = 1100
rmi_registry_host = loopback address
rmi_registry_port = 1099</code></pre>
</div>
</div>
<div class="paragraph">
<p>The default <code>JMXServiceURL</code> configured by the <code>jmx-remote</code> module is the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>service:jmx:rmi://localhost:1099/jndi/rmi://localhost:1099/jmxrmi</pre>
</div>
</div>
<div class="paragraph">
<p>With the default configuration, only clients that are local to the server machine can connect to the RMI registry and RMI server - this is done for security reasons.
However, even with this local-only configuration, it would still be possible to access the MBeans from remote using an SSH tunnel, as explained in <a href="#og-jmx-remote-ssh-tunnel">this section</a>.</p>
</div>
<div class="paragraph">
<p>By specifying an appropriate <code>JMXServiceURL</code>, you can fine tune the network address the RMI registry and the RMI server bind to, and the ports that the RMI registry and the RMI server listen to.
The RMI server and RMI registry hosts and ports can be the same (as in the default configuration) because RMI is able to multiplex traffic arriving to one port to multiple RMI objects.</p>
</div>
<div class="paragraph">
<p>If you need to allow JMX remote access through a firewall, you must open both the RMI registry and the RMI server ports.
The default configuration simplifies the firewall configuration because you only need to open port <code>1099</code>.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>When Jetty is started with the <code>jmx-remote</code> module enabled, the RMI stub of the Jetty component that provides access to the MBeans is exported to the RMI registry.</p>
</div>
<div class="paragraph">
<p>The RMI stub contains the host/port to connect to the RMI server, but the host is typically the machine host name, not the host specified in the <code>JMXServiceURL</code> (the latter is only used to specify the network address the RMI server binds to).</p>
</div>
<div class="paragraph">
<p>To control the host stored in the RMI stub you need to set the system property <code>java.rmi.server.hostname</code> with the desired value in the module configuration file, <code>jmx-remote.ini</code>.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
If your client cannot connect to the server, the most common cause is a mismatch between the RMI server host of the <code>JMXServiceURL</code> and the RMI server host of the RMI stub.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>You can customize the RMI server host/port, the RMI registry host/port and the system property <code>java.rmi.server.hostname</code> by editing the <code>jmx-remote.ini</code> configuration file.
Further information about the <code>jmx-remote</code> module configuration can be found <a href="#og-module-jmx-remote">here</a>.</p>
</div>
<div class="sect4">
<h5 id="og-jmx-remote-ssh-tunnel"><a class="anchor" href="#og-jmx-remote-ssh-tunnel"></a><a class="link" href="#og-jmx-remote-ssh-tunnel">Remote JMX Access with Port Forwarding via SSH Tunnel</a></h5>
<div class="paragraph">
<p>You can access JMX MBeans on a remote machine when the RMI ports are not open, for example because of firewall policies, but you have SSH access to the machine, using local port forwarding via an SSH tunnel.</p>
</div>
<div class="paragraph">
<p>In this case you want to configure the <code>JMXServiceURL</code> that binds the RMI server and the RMI registry to the loopback interface only and to the same port:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>service:jmx:rmi://localhost:1099/jndi/rmi://localhost:1099/jmxrmi</pre>
</div>
</div>
<div class="paragraph">
<p>You must set the system property <code>-Djava.rmi.server.hostname=localhost</code> so that the RMI stub contains <code>localhost</code> as the host name to connect to.
This is, incidentally, the default configuration of the <code>jmx-remote</code> module.</p>
</div>
<div class="paragraph">
<p>Then you setup the local port forwarding with the SSH tunnel:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ ssh -L 1099:localhost:1099 &lt;user&gt;@&lt;machine_host&gt;</pre>
</div>
</div>
<div class="paragraph">
<p>Thanks to the local port forwarding of the SSH tunnel, when the client connects to <code>localhost:1099</code> on your local computer, the traffic will be forwarded to <code>machine_host</code> and when there, the SSH daemon will forward the traffic to <code>localhost:1099</code> on <code>machine_host</code>, which is exactly where the RMI server and the RMI registry listens to.</p>
</div>
<div class="paragraph">
<p>The client first contacts the RMI registry, so it connects to <code>localhost:1099</code> on your local computer; the traffic is forwarded to <code>machine_host</code> through the SSH tunnel, connects to the RMI registry and the RMI stub is downloaded to the client.</p>
</div>
<div class="paragraph">
<p>Then the client uses the RMI stub to connect to the RMI server. The RMI stub contains <code>localhost</code> as the RMI server host because that is what you have configured with the system property <code>java.rmi.server.hostname</code>.</p>
</div>
<div class="paragraph">
<p>The client will connect again to <code>localhost:1099</code> on your local computer, this time to contact the RMI server; the traffic is forwarded to <code>machine_host</code> through the SSH tunnel, arrives to <code>machine_host</code> and connects to the RMI server.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-jmx-remote-auth"><a class="anchor" href="#og-jmx-remote-auth"></a><a class="link" href="#og-jmx-remote-auth">Remote JMX Access Authentication &amp; Authorization</a></h5>
<div class="paragraph">
<p>The standard <code>javax.management.remote.JMXConnectorServer</code> class, used by the <code>jmx-remote</code> module to provide remote JMX access to Jetty MBeans, provides several options to authenticate and authorize users.
For a complete guide to controlling authentication and authorization in JMX, see <a href="https://docs.oracle.com/en/java/javase/11/management/monitoring-and-management-using-jmx-technology.html">the official JMX documentation</a>.</p>
</div>
<div class="paragraph">
<p>The simplest way to control JMX authentication and authorization is to specify two files: one contains username and password pairs, and the other contains username and permission pairs.</p>
</div>
<div class="paragraph">
<p>This is achieved by enbling the <code>jmx-remote-auth</code> Jetty module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=jmx-remote-auth</pre>
</div>
</div>
<div class="paragraph">
<p>Enabling the <code>jmx-remote-auth</code> Jetty module creates the following files:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$JETTY_BASE
├── etc
│ ├── jmxremote.access
│ ├── jmxremote.password
│ └── jmx-remote-auth.xml
└── start.d
├── jmx-remote-auth.ini
└── jmx-remote.ini</pre>
</div>
</div>
<div class="paragraph">
<p>Then you edit the <code>$JETTY_BASE/etc/jmxremote.password</code> file, adding the username/password pairs that you need:</p>
</div>
<div class="listingblock">
<div class="title">$JETTY_BASE/etc/jmxremote.password</div>
<div class="content">
<pre># The file format is: &lt;username&gt; &lt;password&gt;
alice wonderland
bob marley</pre>
</div>
</div>
<div class="paragraph">
<p>You must also edit the <code>$JETTY_BASE/etc/jmxremote.access</code> file to give permissions to your users:</p>
</div>
<div class="listingblock">
<div class="title">$JETTY_BASE/etc/jmxremote.access</div>
<div class="content">
<pre># The file format is: &lt;username&gt; &lt;readonly|readwrite&gt;
alice readwrite
bob readonly</pre>
</div>
</div>
<div class="paragraph">
<p>The above files define user <code>alice</code> with password <code>wonderland</code> to have <code>readwrite</code> access, and user <code>bob</code> with password <code>marley</code> to have <code>readonly</code> access.</p>
</div>
</div>
<div class="sect4">
<h5 id="og-jmx-remote-secure"><a class="anchor" href="#og-jmx-remote-secure"></a><a class="link" href="#og-jmx-remote-secure">Securing Remote JMX Access with TLS</a></h5>
<div class="paragraph">
<p>The JMX communication via RMI happens by default in clear-text, but it is possible to secure the JMX communication via RMI with TLS.</p>
</div>
<div class="paragraph">
<p>If you want to reuse the configuration that you are using for the <a href="#og-protocols-https"><code>https</code> module</a>, you can just enable the <code>jmx-remote-ssl.xml</code> Jetty module:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ java -jar $JETTY_HOME/start.jar --add-module=jmx-remote-ssl</pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The <code>jmx-remote-ssl</code> Jetty module depends on the <code>ssl</code> Jetty module that in turn requires a KeyStore (read <a href="#og-protocols-ssl">this section</a> for more information).</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The KeyStore must contain a valid certificate signed by a Certification Authority.
Having certificates signed by a Certification Authority simplifies by a lot the configuration needed to get the RMI communication over TLS working properly.</p>
</div>
<div class="paragraph">
<p>The RMI mechanic is the usual one: the RMI client (typically a monitoring console) will connect first to the RMI registry (using TLS), download the RMI stub that contains the address and port of the RMI server to connect to, then connect to the RMI server (using TLS).</p>
</div>
<div class="paragraph">
<p>This also mean that if the RMI registry and the RMI server are on different hosts, the RMI client must have available the cryptographic material to validate the certificates from both hosts.
This is where having certificates signed by a Certification Authority simplifies the configuration: if they are signed by a well known Certification Authority, the client does not need any extra configuration&#8201;&#8212;&#8201;everything will be handled by the Java runtime.</p>
</div>
<div class="paragraph">
<p>If the certificates are not signed by a Certification Authority (for example the certificate is self-signed), then you need to specify the TLS system properties that allow RMI (especially when acting as an RMI client) to retrieve the cryptographic material necessary to establish the TLS connection.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="paragraph">
<p>When the RMI server exports the <code>JMXConnectorServer</code> it acts as an RMI <em>client</em> towards the RMI registry, and as such you must specify the TLS system properties as detailed below.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>You must edit the <code>$JETTY_BASE/start.d/jmx-remote-ssl.ini</code> file and add the TrustStore path and password:</p>
</div>
<div class="listingblock">
<div class="title">$JETTY_BASE/start.d/jmx-remote-ssl.ini</div>
<div class="content">
<pre>--module=jmx-remote-ssl
# System properties necessary for non-trusted certificates.
-Djavax.net.ssl.trustStore=/path/to/trustStore.p12
-Djavax.net.ssl.trustStorePassword=password</pre>
</div>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
<div class="paragraph">
<p>The TrustStore must contain the certificate you want to trust.</p>
</div>
<div class="paragraph">
<p>If you are using self-signed certificates, the KeyStore already contains the self-signed certificate and therefore the KeyStore can be used as a TrustStore, and the system properties above can refer to the KeyStore path and password.</p>
</div>
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>JMX compliant tools that offer a graphical user interface also must be started specifying the TrustStore path and password.</p>
</div>
<div class="paragraph">
<p>For example, to launch <a href="https://adoptopenjdk.net/jmc.html">Java Mission Control (JMC)</a>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre>$ jmc -vmargs -Djavax.net.ssl.trustStore=/path/to/trustStore.p12 -Djavax.net.ssl.trustStorePassword=password</pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="og-troubleshooting"><a class="anchor" href="#og-troubleshooting"></a><a class="link" href="#og-troubleshooting">Eclipse Jetty Troubleshooting</a></h3>
<div class="paragraph">
<p>TODO</p>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Version 11.0.0<br>
Last updated 2020-12-02 15:32:18 -0600
</div>
</div>
</body>
</html>