Configure applications for session management using scripting
This task provides an example that uses the AdminConfig object to configure a session manager for the application. Before starting this task, the wsadmin tool must be running. See the Start the wsadmin scripting client article for more information.
Overview
You can use the AdminApp object to set configurations in an application. Some configuration settings are not available through the AdminApp object.
Procedure
- Identify the deployment configuration object for the application and assign it to the deployment variable. For example:
- Use Jacl:
set deployments [$AdminConfig getid /Deployment:myApp/]
- Use Jython:
deployments = AdminConfig.getid('/Deployment:myApp/') print deploymentswhere:
set Jacl command deployments variable name $ Jacl operator for substituting a variable name with its value AdminConfig object representing the WebSphere Application Server configuration getid AdminConfig command Deployment attribute myApp value of the attribute Example output:
myApp(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#Deployment_1)
- Retrieve the application deployment object and assign it to the appDeploy variable. For example:
- Use Jacl:
set appDeploy [$AdminConfig showAttribute $deployments deployedObject]
- Use Jython:
appDeploy = AdminConfig.showAttribute(deployments, 'deployedObject') print appDeploywhere:
set Jacl command appDeploy variable name $ Jacl operator for substituting a variable name with its value AdminConfig object that represents the WebSphere Application Server configuration showAttribute AdminConfig command deployments evaluates the ID of the deployment object that is specified in step number 1 deployedObject attribute Example output:
(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#ApplicationDeployment_1)
- To obtain a list of attributes that you can set for a session manager, use the attributes command. For example:
- Use Jacl:
$AdminConfig attributes SessionManager
- Use Jython:
print AdminConfig.attributes('SessionManager')where:
$ Jacl operator for substituting a variable name with its value AdminConfig object that represents the WebSphere Application Server configuration attributes AdminConfig command SessionManager attribute 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"When you configure and application for session management, it is recommended specified each attribute.
- Set up the attributes for the session manager. The following example sets four top-level attributes in the session manager. You can modify the example to set other attributes of the session manager, including the nested attributes in DRSSettings, SessionDataPersistence, and TuningParms object types. To list the attributes for those object types, use the attributes command of the AdminConfig object.
- Use Jacl:
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 using Jacl:sessionManagement {{enableSecurityIntegration true} {maxWaitTime 30} {sessionPersistenceMode NONE} {defaultCookieSettings {{maximumAge -1}}}}
- Use Jython:
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 using Jython:[[sessionManagement, [[enableSecurityIntegration, true], [maxWaitTime, 30], [sessionPersistenceMode, NONE], [defaultCookieSettings [[maximumAge, -1]]]]where:
set Jacl command attr1, attr2, attr3, attrs, sessionMgr are variable names $ Jacl operator for substituting a variable name with its value enableSecurityIntegration attribute true value of the enableSecurityIntegration attribute maxWaitTime attribute 30 value of the maxWaitTime attribute sessionPersistenceMode attribute NONE value of the sessionPersistenceMode attribute
- Perform one of the following:
- Create the session manager for the application. For example:
- Use Jacl:
$AdminConfig create ApplicationConfig $appDeploy [list $sessionMgr]
- Use Jython:
print AdminConfig.create('ApplicationConfig', appDeploy, sessionMgr)where:
$ Jacl operator for substituting a variable name with its value AdminConfig object that represents the WebSphere Application Server configuration create AdminConfig command ApplicationConfig attribute appDeploy evaluates the ID of the deployed application that is specified in step number 2 list Jacl command sessionMgr evaluates the ID of the session manager that is specified in step number 4 Example output:
(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#ApplicationConfig_1)
- If a session manager already exists, use the modify command of the AdminConfig object to update the configuration of the session manager. For example:
- Use Jacl:
set configs [lindex [$AdminConfig showAttribute $appDeploy configs] 0] set appConfig [lindex $configs 0] set SM [$AdminConfig showAttribute $appConfig sessionManagement] $AdminConfig modify $SM $attrs
- Use Jython:
configs = AdminConfig.showAttribute (appDeploy, 'configs') appConfig = configs[1:len(configs)-1] SM = AdminConfig.showAttribute (appConfig, 'sessionManagement') AdminConfig.modify (SM, attrs)
- Save the configuration changes. See the Saving configuration changes with the wsadmin tool article for more information.
- In a network deployment environment only, synchronize the node. See the Synchronizing nodes with the wsadmin tool article for more information.