blob: ce34f9ac050f6e4d4ecbb7a27cf47085c1aa1b7d [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Persistent Sessions: JDBC</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="session-management.html" title="Chapter&nbsp;10.&nbsp;Session Management"><link rel="prev" href="configuring-sessions-file-system.html" title="Persistent Sessions: File System"><link rel="next" href="configuring-sessions-mongo.html" title="Persistent Sessions: MongoDB"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script>
hljs.initHighlightingOnLoad();
</script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
Version: 9.4.28-SNAPSHOT</span></td><td style="width: 50%"></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Persistent Sessions: JDBC</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="configuring-sessions-file-system.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;10.&nbsp;Session Management<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="configuring-sessions-mongo.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at
<span class="website">www.webtide.com</span></a></h5><p>
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ...
scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="configuring-sessions-jdbc"></a>Persistent Sessions: JDBC</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="configuring-sessions-jdbc.html#_enabling_jdbc_sessions">Enabling JDBC Sessions</a></span></dt><dt><span class="section"><a href="configuring-sessions-jdbc.html#_configuring_jdbc_session_properties">Configuring JDBC Session Properties</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_enabling_jdbc_sessions"></a>Enabling JDBC Sessions</h3></div></div></div><p>When using the Jetty distribution, you will first need to enable the <code class="literal">session-store-jdbc</code> <a class="link" href="startup-modules.html" title="Managing Startup Modules">module</a> for your <a class="link" href="startup-base-and-home.html" title="Managing Jetty Base and Jetty Home">Jetty base</a> using the <code class="literal">--add-to-start</code> argument on the command line.</p><div class="screenexample"><pre class="screen">$ java -jar ../start.jar --create-startd
INFO : Base directory was modified
$ java -jar ../start.jar --add-to-start=session-store-jdbc
INFO : server transitively enabled, ini template available with --add-to-start=server
INFO : sessions transitively enabled, ini template available with --add-to-start=sessions
INFO : sessions/jdbc/datasource dynamic dependency of session-store-jdbc
INFO : session-store-jdbc initialized in ${jetty.base}/start.d/session-store-jdbc.ini
INFO : Base directory was modified</pre></div><p>Doing this enables the JDBC Session module and any dependent modules or files needed for it to run on the server.
The example above is using a fresh <code class="literal">${jetty.base}</code> with nothing else enabled.</p><p>When the <code class="literal">--add-to-start</code> argument was added to the command line, it enabled the the <code class="literal">session-store-jdbc</code> module as well as the <code class="literal">sessions</code> and <code class="literal">server</code> modules, which are required for JDBC session management to operate.</p><p>In addition to adding these modules to the classpath of the server, several ini configuration files were added to the <code class="literal">${jetty.base}/start.d</code> directory.</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_configuring_jdbc_session_properties"></a>Configuring JDBC Session Properties</h3></div></div></div><p>Opening the <code class="literal">start.d/session-store-jdbc.ini</code> will show a list of all the configurable options for the JDBC module:</p><div class="screenexample"><pre class="screen"># ---------------------------------------
# Module: session-store-jdbc
# Enables JDBC persistent/distributed session storage.
# ---------------------------------------
--module=session-store-jdbc
##
##JDBC Session properties
##
#jetty.session.gracePeriod.seconds=3600
## Connection type:Datasource
db-connection-type=datasource
#jetty.session.jdbc.datasourceName=/jdbc/sessions
## Connection type:driver
#db-connection-type=driver
#jetty.session.jdbc.driverClass=
#jetty.session.jdbc.driverUrl=
## Session table schema
#jetty.session.jdbc.schema.accessTimeColumn=accessTime
#jetty.session.jdbc.schema.contextPathColumn=contextPath
#jetty.session.jdbc.schema.cookieTimeColumn=cookieTime
#jetty.session.jdbc.schema.createTimeColumn=createTime
#jetty.session.jdbc.schema.expiryTimeColumn=expiryTime
#jetty.session.jdbc.schema.lastAccessTimeColumn=lastAccessTime
#jetty.session.jdbc.schema.lastSavedTimeColumn=lastSavedTime
#jetty.session.jdbc.schema.idColumn=sessionId
#jetty.session.jdbc.schema.lastNodeColumn=lastNode
#jetty.session.jdbc.schema.virtualHostColumn=virtualHost
#jetty.session.jdbc.schema.maxIntervalColumn=maxInterval
#jetty.session.jdbc.schema.mapColumn=map
#jetty.session.jdbc.schema.table=JettySessions</pre></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">jetty.session.gracePeriod.seconds</span></dt><dd>Amount of time, in seconds, to wait for other nodes to be checked to verify an expired session is in fact expired throughout the cluster before closing it.</dd><dt><span class="term">jetty.session.savePeriod.seconds=0</span></dt><dd><p class="simpara">By default whenever the last concurrent request leaves a session, that session is always persisted via the <code class="literal">SessionDataStore</code>, even if the only thing that changed on the session is its updated last access time.
A non-zero value means that the <code class="literal">SessionDataStore</code> will skip persisting the session if only the access time changed, and it has been less than <code class="literal">savePeriod</code> seconds since the last time the session was written.</p><div class="blockquote"><blockquote class="blockquote"><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><i class="fa fa-asterisk" aria-hidden="true"></i> Note</h3><p>Configuring <code class="literal">savePeriod</code> is useful if your persistence technology is very slow/costly for writes.
In a clustered environment, there is a risk of the last access time of the session being out-of-date in the shared store for up to <code class="literal">savePeriod</code> seconds.
This allows the possibility that a node may prematurely expire the session, even though it is in use by another node.
Thorough consideration of the <code class="literal">maxIdleTime</code> of the session when setting the <code class="literal">savePeriod</code> is imperative - there is no point in setting a <code class="literal">savePeriod</code> that is larger than the <code class="literal">maxIdleTime</code>.</p></div></blockquote></div></dd><dt><span class="term">db-connection-type</span></dt><dd>Set to either <code class="literal">datasource</code> or <code class="literal">driver</code> depending on the type of connection being used.</dd><dt><span class="term">jetty.session.jdbc.datasourceName</span></dt><dd>Name of the remote datasource.</dd><dt><span class="term">jetty.session.jdbc.driverClass</span></dt><dd>Name of the JDBC driver that controls access to the remote database, such as <code class="literal">com.mysql.jdbc.Driver</code></dd><dt><span class="term">jetty.session.jdbc.driverUrl</span></dt><dd>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 class="literal">jdbc:mysql://127.0.0.1:3306/sessions?user=sessionsadmin</code>.</dd></dl></div><p>The <code class="literal">jetty.sessionTableSchema</code> values represent the names for the columns in the JDBC database and can be changed to suit your environment.</p></div></div><script type="text/javascript">
SyntaxHighlighter.all()
</script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="configuring-sessions-file-system.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="session-management.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="configuring-sessions-mongo.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Persistent Sessions: File System&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Persistent Sessions: MongoDB</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
See an error or something missing?
<span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at
<span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2020-03-10)</i></span></div></p></body></html>