Session Servlet Example: Difference between revisions
No edit summary |
|||
Line 5: | Line 5: | ||
=Overview= | =Overview= | ||
A simple JEE servlet that can be deployed within a JEE container and used to test continuity, load balancing, failover, session stickiness, etc. It has been tested to work with WildFly/EAP and with Tomcat. One of the design constraints was to avoid container-specific dependencies. | |||
=Source Code= | =Source Code= | ||
Line 11: | Line 13: | ||
:https://github.com/NovaOrdis/playground/tree/master/jee/servlet/session-servlet | :https://github.com/NovaOrdis/playground/tree/master/jee/servlet/session-servlet | ||
</blockquote> | </blockquote> | ||
=Build= | |||
<pre> | |||
mvn clean package | |||
</pre> | |||
=Deploy= | |||
Copy ./target/session-servlet.war into the deployment directory of the application server. | |||
=Usage= | |||
For more details, see [[#HTTP_Session_Support|HTTP Session Support]]. | |||
=Authentication= | |||
The default build produces a servlet that *does NOT require authentication*. | |||
If you want authentication, do this (JBoss 5 procedure, may need to be updated for WildFly): | |||
1. Un-comment <tt>web.xml</tt> section starting with <security-constraint> and ending with </security-role>. | |||
2. Replace "admin" with a valid role. The replacement must be done in both places where <role-name> is mentioned. For example, if deployed on JBoss 5, pick up an appropriate role from <tt>$JBOSS_HOME/server/$JBOSS_PROFILE/conf/props/jmx-console-roles.properties</tt>. | |||
3. Enable <security-domain> in <tt>jboss-web.xml</tt> and make sure it points to the correct one on the server. | |||
=HTTP Session Support= | |||
The servlet will NOT establish a HTTP session by default. | |||
If you wish it to establish a session, call it with "establish-session" parameter on the first request. | |||
Example: http://locahost:8080/session-servlet?establish-session | |||
After the first request, obviously there's no need for "establish-session" anymore, the browser/server ensemble maintain the one that was established. The current implementation will throw an exception if it sees "?establish-session" again. | |||
In order to store a key/value pair into the session, use http://locahost:8080/session-servlet/put?key=something&value=somethingelse. In order to retrieve a key/value pair from the session, use http://locahost:8080/session-servlet/get?key=something | |||
### Enable HTTP Session Replication | |||
##Root Context | |||
You can change the root context as follows: | |||
###On JBoss | |||
####Method One | |||
Simply deploy the WAR under the desired name. | |||
####Method Two | |||
TODO: use jboss-web.xml and root-context. | |||
###On Tomcat | |||
Simply deploy the WAR under the desired name. | |||
##Test Plan | |||
###1. Simple Availability | |||
Build and deploy. | |||
Go to http://<server-address>:<server-port>/session-servlet | |||
It will return a simple HTTP page listing relevant information regarding the execution. | |||
###2. Session Experiments | |||
Establish a session with http://<server-address>:<server-port>/session-servlet?establish-session | |||
Then drop the parameter, the browser/server should maintain the session until it expires. |
Revision as of 15:49, 9 June 2016
Internal
Overview
A simple JEE servlet that can be deployed within a JEE container and used to test continuity, load balancing, failover, session stickiness, etc. It has been tested to work with WildFly/EAP and with Tomcat. One of the design constraints was to avoid container-specific dependencies.
Source Code
Build
mvn clean package
Deploy
Copy ./target/session-servlet.war into the deployment directory of the application server.
Usage
For more details, see HTTP Session Support.
Authentication
The default build produces a servlet that *does NOT require authentication*.
If you want authentication, do this (JBoss 5 procedure, may need to be updated for WildFly):
1. Un-comment web.xml section starting with <security-constraint> and ending with </security-role>.
2. Replace "admin" with a valid role. The replacement must be done in both places where <role-name> is mentioned. For example, if deployed on JBoss 5, pick up an appropriate role from $JBOSS_HOME/server/$JBOSS_PROFILE/conf/props/jmx-console-roles.properties.
3. Enable <security-domain> in jboss-web.xml and make sure it points to the correct one on the server.
HTTP Session Support
The servlet will NOT establish a HTTP session by default.
If you wish it to establish a session, call it with "establish-session" parameter on the first request.
Example: http://locahost:8080/session-servlet?establish-session
After the first request, obviously there's no need for "establish-session" anymore, the browser/server ensemble maintain the one that was established. The current implementation will throw an exception if it sees "?establish-session" again.
In order to store a key/value pair into the session, use http://locahost:8080/session-servlet/put?key=something&value=somethingelse. In order to retrieve a key/value pair from the session, use http://locahost:8080/session-servlet/get?key=something
- Enable HTTP Session Replication
- Root Context
You can change the root context as follows:
- On JBoss
- Method One
Simply deploy the WAR under the desired name.
- Method Two
TODO: use jboss-web.xml and root-context.
- On Tomcat
Simply deploy the WAR under the desired name.
- Test Plan
- 1. Simple Availability
Build and deploy.
Go to http://<server-address>:<server-port>/session-servlet
It will return a simple HTTP page listing relevant information regarding the execution.
- 2. Session Experiments
Establish a session with http://<server-address>:<server-port>/session-servlet?establish-session
Then drop the parameter, the browser/server should maintain the session until it expires.