+

Search Tips   |   Advanced Search

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.

An application must be installed on a running server.

Use the AdminConfig object to set configurations in an application. Some configuration settings are not available through the AdminConfig object.


Tasks

  1. Start the wsadmin scripting tool.
  2. Identify the deployment configuration object for the application and assign it to the deployment variable.

    This step is not needed for an OSGi application. For example:

    • Jacl:
      test
      
      set deployments [$AdminConfig getid /Deployment:myApp/]
      
    • Jython:
      deployments = AdminConfig.getid('/Deployment:myApp/')
      print deployments
      

    where:

    Element Description
    set Jacl command
    deployments Variable name
    $ Jacl operator for substituting a variable name with its value
    AdminConfig is an 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)
    

  3. Retrieve the application deployment object and assign it to the appDeploy variable. For example:

    • Jacl:
      set appDeploy [$AdminConfig showAttribute $deployments deployedObject]
      
    • Jython:
      appDeploy = AdminConfig.showAttribute(deployments, 'deployedObject')
      print appDeploy
      

    For an OSGi application, use the following jython code for this step:

    appDeploy = AdminTask.getOSGiApplicationDeployedObject('-cuName cu_name')
    

    where:

    Element Description
    set Jacl command
    appDeploy variable name
    $ Jacl operator for substituting a variable name with its value
    AdminConfig object that represents the WAS configuration
    showAttribute n AdminConfig command
    deployments Evaluate the ID of the deployment object specified in step number 1
    deployedObject Attribute
    cu_name Name of the composition unit

    Example output:

    (cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#ApplicationDeployment_1)
    

  4. To obtain a list of attributes that we can set for a session manager, use the attributes command. For example:

    • Jacl:
      $AdminConfig attributes SessionManager
      
    • Jython:
      print AdminConfig.attributes('SessionManager')
      

    where:

    Element Description
    $ Jacl operator for substituting a variable name with its value
    AdminConfig object that represents the WAS configuration
    attributes n 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 we configure an application for session management, IBM recommends specified each attribute.

    If we are setting up the session management attributes for a cluster, we must also update the targetMappings element of the AdminConfig object for the cluster before the settings we specify for the sessionManagment element become effective. If we do not update the targetMappings element, the settings are not effective even though they appear in the deployment.xml file.

  5. Set up the attributes for the session manager.

    Set 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, and TuningParms object types.

    The session manager requires that we set both the defaultCookieSettings and tuningParams attributes before you initialize an application. If we do not set these attributes, the session manager cannot initialize the application, and the application does not start..

    To list the attributes for those object types, use the attributes command of the AdminConfig object.

    • 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}}}}
      
    • 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:

    Element Description
    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

  6. Perform one of the following:

    • Create the session manager for the application. For example:

      • Jacl:
        $AdminConfig create ApplicationConfig $appDeploy [list $sessionMgr]
        
      • Jython:
        print AdminConfig.create('ApplicationConfig', appDeploy, sessionMgr)
        

      where:

      Element Description
      $ Jacl operator for substituting a variable name with its value
      AdminConfig object that represents the WAS configuration
      create n AdminConfig command
      ApplicationConfig Attribute
      appDeploy Evaluate the ID of the deployed application specified in step number 2
      list Jacl command
      sessionMgr Evaluate the ID of the session manager 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:

      • Jacl:
        set configs [lindex [$AdminConfig showAttribute $appDeploy configs] 0]
        set appConfig [lindex $configs 0]
        set SM [$AdminConfig showAttribute $appConfig sessionManagement]
        $AdminConfig modify $SM $attrs
        
      • Jython:
        configs = AdminConfig.showAttribute (appDeploy, 'configs')
        appConfig = configs[1:len(configs)-1] 
        SM = AdminConfig.showAttribute (appConfig, 'sessionManagement') 
        AdminConfig.modify (SM, attrs)
        

  7. Save the configuration changes.
    AdminConfig.save()
    
  8. Synchronize the node.

    Use the syncActiveNode or syncNode scripts in the AdminNodeManagement script library to propagate the configuration changes to node or nodes.

    • Use the syncActiveNodes script to propagate the changes to each node in the cell:
      AdminNodeManagement.syncActiveNodes()
      

    • Use the syncNode script to propagate the changes to a specific node:
      AdminNodeManagement.syncNode("myNode")
      


Related:

  • Session management support
  • Start the wsadmin scripting client
  • Configure applications for session management in web modules using scripting
  • Configure session management by level
  • Develop session management in servlets
  • Use the script library to automate the application serving environment
  • wsadmin AdminConfig