Configuring session persistence in websphere application server

IBM WebSphere Application Server
#-- Configuring session manager for Web container 
set aServer [$AdminConfig getid /Node:$nodeName/Server:$serverName/]
set aSessionMgr [$AdminConfig list SessionManager $aServer]
puts "Configure session serialization access"
set serialAccessAttr [list allowSerializedSessionAccess true]
set waitTimeAttr [list maxWaitTime 125000]
set timeoutAttr [list accessSessionOnTimeout true]
set attrs [list $serialAccessAttr $waitTimeAttr $timeoutAttr]
$AdminConfig modify $aSessionMgr $attrs

puts "Configure to track session with cookies"
set cookieAttr [list enableCookies true]
set protocolAttr [list enableProtocolSwitchRewriting false]
set urlAttr [list enableUrlRewriting false]
set sslAttr [list enableSSLTracking false]
# valid session persistence mode values are NONE, DATABASE, and DATA_REPLICATION]
set sessionPersistenceAttr [list sessionPersistenceMode DATABASE]
set attrs [list $cookieAttr $urlAttr $sslAttr $protocolAttr]
$AdminConfig modify $aSessionMgr $attrs

# setting up Cookie attributes
set domainAttr [list domain myDomain]
# set cookie maximum age to use current browser session
set maxAgeAttr [list maximumAge -1]
set nameAttr [list name myCookie]
set pathAttr [list path "/"]
set secureAttr [list secure true]
set cookieAttrs [list $domainAttr $maxAgeAttr $nameAttr $pathAttr $secureAttr]

# get the cookie config object name for the above SessionManager
set cookie [$AdminConfig showAttribute $aSessionMgr defaultCookieSettings]
# check if there is existing cookie properties
if {[llength $cookie] != 0} {
# modifying existing cookie
puts "Modify existing cookie"
$AdminConfig modify $cookie $cookieAttrs
puts [$AdminConfig showall $cookie]
} else {
# create a cookie
puts "Create a cookie"
set cookie [$AdminConfig create Cookie $aSessionMgr $cookieAttrs]
puts [$AdminConfig showall $cookie]

# setting up database session persistence
puts "Configure for database session persistence"
set dsJndiAttr [list datasourceJNDIName jdbc/mySession]
set userAttr [list userId myUser]
set pwdAttr [list password myPassword]
set sessionDbPersAttrs [list $dsJndiAttr $userAttr $pwdAttr]

# get session database persistence config object name
set aSessionDbPers [$AdminConfig showAttribute $aSessionMgr sessionDatabasePersistence]
if {[llength $aSessionDbPers] != 0} {
puts "Modify existing session database persistence"
$AdminConfig modify $aSessionDbPers $sessionDbPersAttrs
puts [$AdminConfig showall $aSessionDbPers]
} else {
puts "Create a session database persistence object"
set aSessionDbPers [$AdminConfig create SessionDatabasePersistence $aSessionMgr $sessionDbPersAttrs]
puts [$AdminConfig showall $aSessionDbPers]

# setting up attributes for TuningParams
set aofAttr [list allowOverflow true]
set isAttr [list invalidationSchedule [list [list firstHour 2] [list secondHour 5]]]
set itAttr [list invalidationTimeout 10]
set mimscAttr [list maxInMemorySessionCount 5]
set siAttr [list scheduleInvalidation true]
set umrsAttr [list usingMultiRowSchema true]
set wcAttr [list writeContents ONLY_UPDATED_ATTRIBUTES]
set wfAttr [list writeFrequency END_OF_SERVLET_SERVICE]
set wiAttr [list writeInterval 5]
set tuningParamAttrs [list $aofAttr $isAttr $itAttr $mimscAttr $siAttr $umrsAttr $wcAttr $wfAttr $wiAttr]

# get tuning params config object name
set tp [$AdminConfig showAttribute $aSessionMgr tuningParams]

# check if there is existing tuning params
if {[llength $tp] != 0} {
# modifying TuningParams attributes
puts "Modify existing tuning params"
$AdminConfig modify $tp $tuningParamAttrs
puts [$AdminConfig showall $tp]
} else {
# create a turning params object
puts "Create a tuning params object"
set tp [$AdminConfig create TuningParams $aSessionMgr $tuningParamAttrs]
puts [$AdminConfig showall $tp]
$AdminConfig save

In case of any ┬ęCopyright or missing credits issue please check CopyRights page for faster resolutions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.