Set applications for session management using scripting


 

+

Search Tips   |   Advanced Search

This task uses wsadmin with AdminConfig to configure a session manager for an application.

 

Using Jython

### get_session.py
###
### wsadmin.bat -lang jython -user wasadmin -password wasadmin -f get_session.py

### Identify the deployment configuration object for the application 
### and assign it to the deployment variable.  
deployments = AdminConfig.getid('/Deployment:SamplesGallery/') 
print deployments

### Retrieve the application deployment object  
appDeploy = AdminConfig.showAttribute(deployments, 'deployedObject') 
print appDeploy

### Obtain list of attributes to set for a session manager 
print AdminConfig.attributes('SessionManager')

### Output:
### accessSessionOnTimeout  boolean
### allowSerializedSessionAccess   boolean
### context  ServiceContext@
### defaultCookieSettings   Cookie
### enable boolean
### enableCookies boolean
### enableProtocolSwitchRewriting  boolean
### enableSSLTracking  boolean
### enableSecurityIntegration boolean
### enableUrlRewriting    boolean
### maxWaitTime   int
### properties Property(TypedProperty, DescriptiveProperty)*
### sessionDRSPersistence DRSSettings
### sessionDatabasePersistence SessionDatabasePersistence
### sessionPersistenceMode ENUM(DATABASE, DATA_REPLICATION, NONE)
### tuningParams TuningParams

### Set up the attributes for the session manager.  
###
### The following example sets four top-level attributes in the session manager. 
### We can modify the example to set other attributes of the session manager, 
### including the nested attributes in...
###
###  DRSSettings
###  SessionDataPersistence
###  TuningParms 
###

### attr1 = ['enableSecurityIntegration', 'true']
### attr2 = ['maxWaitTime', 30]
### attr3 = ['sessionPersistenceMode', 'NONE']
### kuki = ['maximumAge', -1] 
### cookie = [kuki] 
### cookieSettings = ['defaultCookieSettings', cookie] 
### attrs = [attr1, attr2, attr3, cookieSettings]
### sessionMgr = [['sessionManagement', attrs]]

### Example output:
### 
### [[sessionManagement, [
###   [enableSecurityIntegration, true], 
###   [maxWaitTime, 30], 
###   [sessionPersistenceMode, NONE], 
###   [defaultCookieSettings [[maximumAge, -1]]]
### ]

### Create the session manager for the application print AdminConfig.create('ApplicationConfig', appDeploy, sessionMgr)

### If a session manager already exists, update the configuration 
 configs = AdminConfig.showAttribute (appDeploy, 'configs')
 appConfig = configs[1:len(configs)-1] 
 SM = AdminConfig.showAttribute (appConfig, 'sessionManagement') 
 AdminConfig.modify (SM, attrs)

### Save the configuration changes.
 AdminConfig.save()

### Synchronize the node. 
###
### Use syncActiveNode or syncNode scripts in the AdminNodeManagement 

### To use syncActiveNodes...
 AdminNodeManagement.syncActiveNodes()

### To use syncNode 
 AdminNodeManagement.syncNode("myNode")

 

Using Jacl

### get_session.jacl

### Identify the deployment configuration object for the application 
### and assign it to the deployment variable.  
set deployments [$AdminConfig getid /Deployment:SamplesGallery/]

### Retrieve the application deployment object  
set appDeploy [$AdminConfig showAttribute $deployments deployedObject]

### Obtain list of attributes to set for a session manager

$AdminConfig attributes SessionManager

### Example output:
###
### "accessSessionOnTimeout Boolean"
### "allowSerializedSessionAccess Boolean"
### "context ServiceContext@"
### "defaultCookieSettings Cookie"
### "enable Boolean"
### "enableCookies Boolean"
### "enableProtocolSwitchRewriting Boolean"
### "enableSSLTracking Boolean"
### "enableSecurityIntegration Boolean"
### "enableUrlRewriting Boolean"
### "maxWaitTime Integer"
### "properties Property(TypedProperty)*"
### "sessionDRSPersistence DRSSettings"
### "sessionDatabasePersistence SessionDatabasePersistence"
### "sessionPersistenceMode ENUM(DATABASE, DATA_REPLICATION, NONE)"
### "tuningParams TuningParams"

### Set up the attributes for the session manager.  
###
### 

The following example sets four top-level attributes in the session manager. ### We can modify the example to set other attributes of the session manager, ### including the nested attributes in... ### ### DRSSettings ### SessionDataPersistence ### TuningParms ### set attr1 [list enableSecurityIntegration true] set attr2 [list maxWaitTime 30] set attr3 [list sessionPersistenceMode NONE] set kuki [list maximumAge -1] set cookie [list $kuki] Set cookieSettings [list defaultCookieSettings $cookie] set attrs [list $attr1 $attr2 $attr3 $cookieSettings] set sessionMgr [list sessionManagement $attrs] ### Example output: ### ### sessionManagement { ### {enableSecurityIntegration true} ### {maxWaitTime 30} ### {sessionPersistenceMode NONE} ### {defaultCookieSettings { {maximumAge -1} }} ### } ### Create the session manager for the application $AdminConfig create ApplicationConfig $appDeploy [list $sessionMgr] ### appDeploy evaluates the ID of the deployed application ### sessionMgr evaluates the ID of the session manager ### Example output: ### ### (cells/mycell/applications/SamplesGallery.ear/deployments/SamplesGallery|deployment.xml#ApplicationConfig_1) ### If a session manager already exists, update the configuration set configs [lindex [$AdminConfig showAttribute $appDeploy configs] 0] set appConfig [lindex $configs 0] set SM [$AdminConfig showAttribute $appConfig sessionManagement] $AdminConfig modify $SM $attrs

 

Related tasks

Session management support
Set applications for session management in Web modules using scripting
Set session management by level
Develop session management in servlets
Use the script library to automate the application serving environment
Use AdminConfig for scripted administration