The Session Service was created to allow Turbine based applications to access information about the current sessions in the application's context. Some of the most obvious uses would include
The service is implemented by using a listener configured in your application's deployment descriptor. The listener class is used by the container to notify the service when sessions are created or destroyed.
You will need to modify a few files in order to activate the service. The first modification will be in your TurbineResources.properties. See the example below for two settings that need to be present in order for the service to work.
# ------------------------------------------------------------------- # # S E R V I C E S # # ------------------------------------------------------------------- # Classes for Turbine Services should be defined here. # Format: services.[name].classname=[implementing class] # # To specify properties of a service use the following syntax: # service.[name].[property]=[value] services.SessionService.classname=org.apache.turbine.services.session.TurbineSessionService . . . # ------------------------------------------------------------------- # # S E S S I O N S E R V I C E # # ------------------------------------------------------------------- services.SessionService.earlyInit=true
The next modification will be your application's deployment descriptor (web.xml). Here we will configure the listener class.
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <listener> <listener-class>org.apache.turbine.services.session.SessionListener</listener-class> </listener> <servlet> <servlet-name>MyServletName</servlet-name> <servlet-class>org.apache.turbine.Turbine</servlet-class> <init-param> <param-name>properties</param-name> <param-value>/WEB-INF/conf/TurbineResources.properties</param-value> </init-param> </servlet> </web-app>
There is also a pull tool avilable for accessing this service. To make it available for use in your velocity templates, add the following line to your TR.props file.
tool.session.sessionmgt = org.apache.turbine.services.session.SessionTool