Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Jetty/Howto/SessionIds"
(11 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{Jetty Howto | {{Jetty Howto | ||
| introduction = | | introduction = | ||
− | |||
+ | {{Jetty Redirect|http://www.eclipse.org/jetty/documentation/current/session-management.html}} | ||
+ | |||
+ | The following configuration can be applied to modify the session characteristics of a web application: | ||
+ | | steps = | ||
+ | ===Init Parameters=== | ||
<table> | <table> | ||
<tr> | <tr> | ||
− | <td><b>Context Parameter Name</b></td> | + | <td><b>Context Parameter Name</b></td> |
− | <td><b>Default Value</b></td> | + | <td><b>Default Value</b></td> |
<td><b>Description</b></td> | <td><b>Description</b></td> | ||
</tr><tr> | </tr><tr> | ||
− | <td>org. | + | <td>org.eclipse.jetty.servlet.SessionCookie</td> |
<td>JSESSIONID</td> | <td>JSESSIONID</td> | ||
− | <td>Session cookie name | + | <td>Session cookie name defaults to JSESSIONID, but can be set for a particular webapp with this context param.</td> |
</tr><tr> | </tr><tr> | ||
− | <td>org. | + | <td>org.eclipse.jetty.servlet.SessionIdPathParameterName</td> |
<td>jsessionid</td> | <td>jsessionid</td> | ||
<td>Session URL parameter name. Defaults to jsessionid, but can be set for a particular webapp with this context param. Set to "none" to disable URL rewriting.</td> | <td>Session URL parameter name. Defaults to jsessionid, but can be set for a particular webapp with this context param. Set to "none" to disable URL rewriting.</td> | ||
</tr><tr> | </tr><tr> | ||
− | <td>org. | + | <td>org.eclipse.jetty.servlet.SessionDomain</td> |
<td>-</td> | <td>-</td> | ||
<td>Session Domain. If this property is set as a ServletContext param, then it is used as the domain for session cookies.If it is not set, then no domain is specified for the session cookie.</td> | <td>Session Domain. If this property is set as a ServletContext param, then it is used as the domain for session cookies.If it is not set, then no domain is specified for the session cookie.</td> | ||
</tr><tr> | </tr><tr> | ||
− | <td>org. | + | <td>org.eclipse.jetty.servlet.SessionPath</td> |
<td>-</td> | <td>-</td> | ||
<td>Session Path. If this property is set as a ServletContext param, then it is used as the path for the session cookie. If it is not set, then the context path is used as the path for the cookie.</td> | <td>Session Path. If this property is set as a ServletContext param, then it is used as the path for the session cookie. If it is not set, then the context path is used as the path for the cookie.</td> | ||
</tr><tr> | </tr><tr> | ||
− | <td>org. | + | <td>org.eclipse.jetty.servlet.MaxAge</td> |
<td>-1</td> | <td>-1</td> | ||
<td>Session Max Age. If this property is set as a ServletContext param, then it is used as the max age for the session cookie. If it is not set, then a max age of -1 is used.</td> | <td>Session Max Age. If this property is set as a ServletContext param, then it is used as the max age for the session cookie. If it is not set, then a max age of -1 is used.</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>org.eclipse.jetty.servlet.CheckingRemoteSessionIdEncoding</td> | ||
+ | <td>false</td> | ||
+ | <td></td> | ||
</tr> | </tr> | ||
</table> | </table> | ||
+ | ===Example=== | ||
The above can either be set as <context-param>s in a web application's <tt>WEB-INF/web.xml</tt> file like so: | The above can either be set as <context-param>s in a web application's <tt>WEB-INF/web.xml</tt> file like so: | ||
<source lang="xml"> | <source lang="xml"> | ||
− | + | <?xml version="1.0" encoding="ISO-8859-1"?> | |
− | + | <web-app | |
− | + | xmlns="http://java.sun.com/xml/ns/javaee" | |
− | + | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
− | + | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | |
− | + | version="2.5"> | |
− | + | ... | |
− | + | <context-param> | |
− | + | <param-name>org.eclipse.jetty.servlet.SessionCookie</param-name> | |
− | + | <param-value>XSESSIONID</param-value> | |
− | + | </context-param> | |
− | + | <context-param> | |
− | + | <param-name>org.eclipse.jetty.servlet.SessionIdPathParameterName</param-name> | |
− | + | <param-value>xsessionid</param-value> | |
− | + | </context-param> | |
− | + | ... | |
− | + | </web-app> | |
</source> | </source> | ||
− | or, they can be | + | or, they can be configured on a web application, either in code, or in a Jetty context xml file equivalent: |
<source lang="xml"> | <source lang="xml"> | ||
− | + | <Configure class="org.eclipse.jetty.webapp.WebAppContext"> | |
− | + | <Set name="contextPath">/test</Set> | |
− | + | <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test</Set> | |
− | + | ... | |
− | + | <Call name="setInitParameter"> | |
− | + | <Arg>org.eclipse.jetty.servlet.SessionCookie</Arg> | |
− | + | <Arg>XSESSIONID</Arg> | |
− | < | + | </Call> |
− | < | + | <Call name="setInitParameter"> |
− | + | <Arg>org.eclipse.jetty.servlet.SessionIdPathParameterName</Arg> | |
− | + | <Arg>xsessionid</Arg> | |
− | < | + | </Call> |
− | < | + | </Configure> |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</source> | </source> | ||
+ | |||
+ | or they can be configured directly on a SessionManager instance, either in code or the equivalent in xml: | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <Configure class="org.eclipse.jetty.webapp.WebAppContext"> | ||
+ | <Set name="contextPath">/test</Set> | ||
+ | <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test</Set> | ||
+ | |||
+ | ... | ||
+ | |||
+ | <Get name="sessionHandler"> | ||
+ | <Set name="sessionManager"> | ||
+ | <New class="org.eclipse.jetty.server.session.HashSessionManager"> | ||
+ | <Set name="sessionCookie">XSESSIONID</Set> | ||
+ | <Set name="sessionIdPathParameterName">xsessionid</Set> | ||
+ | </New> | ||
+ | </Set> | ||
+ | </Get> | ||
+ | </Configure> | ||
+ | </source> | ||
+ | |||
+ | To see more about params look at the class org.eclipse.jetty.server.SessionManager source : http://download.eclipse.org/jetty/stable-7/xref/org/eclipse/jetty/server/SessionManager.html | ||
+ | |||
+ | | more = | ||
+ | For more information, please see the [[Jetty/Feature/Session Clustering|Session Clustering]] tutorial. | ||
}} | }} |
Latest revision as of 14:43, 23 April 2013
Introduction
The following configuration can be applied to modify the session characteristics of a web application:
Steps
Init Parameters
Context Parameter Name | Default Value | Description |
org.eclipse.jetty.servlet.SessionCookie | JSESSIONID | Session cookie name defaults to JSESSIONID, but can be set for a particular webapp with this context param. |
org.eclipse.jetty.servlet.SessionIdPathParameterName | jsessionid | Session URL parameter name. Defaults to jsessionid, but can be set for a particular webapp with this context param. Set to "none" to disable URL rewriting. |
org.eclipse.jetty.servlet.SessionDomain | - | Session Domain. If this property is set as a ServletContext param, then it is used as the domain for session cookies.If it is not set, then no domain is specified for the session cookie. |
org.eclipse.jetty.servlet.SessionPath | - | Session Path. If this property is set as a ServletContext param, then it is used as the path for the session cookie. If it is not set, then the context path is used as the path for the cookie. |
org.eclipse.jetty.servlet.MaxAge | -1 | Session Max Age. If this property is set as a ServletContext param, then it is used as the max age for the session cookie. If it is not set, then a max age of -1 is used. |
org.eclipse.jetty.servlet.CheckingRemoteSessionIdEncoding | false |
Example
The above can either be set as <context-param>s in a web application's WEB-INF/web.xml file like so:
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> ... <context-param> <param-name>org.eclipse.jetty.servlet.SessionCookie</param-name> <param-value>XSESSIONID</param-value> </context-param> <context-param> <param-name>org.eclipse.jetty.servlet.SessionIdPathParameterName</param-name> <param-value>xsessionid</param-value> </context-param> ... </web-app>
or, they can be configured on a web application, either in code, or in a Jetty context xml file equivalent:
<Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/test</Set> <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test</Set> ... <Call name="setInitParameter"> <Arg>org.eclipse.jetty.servlet.SessionCookie</Arg> <Arg>XSESSIONID</Arg> </Call> <Call name="setInitParameter"> <Arg>org.eclipse.jetty.servlet.SessionIdPathParameterName</Arg> <Arg>xsessionid</Arg> </Call> </Configure>
or they can be configured directly on a SessionManager instance, either in code or the equivalent in xml:
<Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/test</Set> <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test</Set> ... <Get name="sessionHandler"> <Set name="sessionManager"> <New class="org.eclipse.jetty.server.session.HashSessionManager"> <Set name="sessionCookie">XSESSIONID</Set> <Set name="sessionIdPathParameterName">xsessionid</Set> </New> </Set> </Get> </Configure>
To see more about params look at the class org.eclipse.jetty.server.SessionManager source : http://download.eclipse.org/jetty/stable-7/xref/org/eclipse/jetty/server/SessionManager.html
Additional Resources
For more information, please see the Session Clustering tutorial.