+

Search Tips   |   Advanced Search

Configure applications for session management in web modules

Use scripting and wsadmin.sh to configure applications for session management in web modules.

We can use the AdminApp object to set configurations in an application. Some configuration settings are not available through the AdminApp object. The following task uses the AdminConfig object to configure a session manager for a web module in the application.

  1. Start the wsadmin scripting tool.

  2. Identify the deployment configuration object for the application and assign it to the deployment variable. For example:

    • Jacl:

        set deployments [$AdminConfig getid /Deployment:myApp/]

    • Jython:

      deployments = AdminConfig.getid('/Deployment:myApp/')
      print deployments

    where:

    Element Definition
    set is a Jacl command
    deployments is a variable name
    $ is a Jacl operator for substituting a variable name with its value
    AdminConfig is an object that represents the WAS configuration
    getid is an AdminConfig command
    Deployment is an attribute
    myApp is the value of the attribute

    Example output:

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

  3. Get all the modules in the application and assign them to the modules variable. For example:

    • Jacl:

      set appDeploy [$AdminConfig showAttribute $deployments deployedObject]
      set mod1 [$AdminConfig showAttribute $appDeploy modules]
      set mod1 [lindex $mod1 0]

      Example output:

      (cells/mycell/applications/myApp.ear/deployments/myApp:deployment.xml#WebModuleDeployment_1)
      (cells/mycell/applications/myApp.ear/deployments/myApp:deployment.xml#EJBModuleDeployment_1)
      (cells/mycell/applications/myApp.ear/deployments/myApp:deployment.xml#WebModuleDeployment_2)

    • Jython:

      appDeploy = AdminConfig.showAttribute(deployments, 'deployedObject')
      mod1 = AdminConfig.showAttribute(appDeploy, 'modules')
      print mod1

      Example output:

      [(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#WebModuleDeployment_1)  (cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#EJBModuleDeployment_1)
      (cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#EJBModuleDeployment_2)]

    where:

    following table describes the elements of the showAttribute AdminConfig
    Element Definition
    set is a Jacl command
    appDeploy is a variable name
    mod1 is a variable name
    $ is a Jacl operator for substituting a variable name with its value
    AdminConfig is an object that represents the WAS configuration
    showAttribute is an AdminConfig command
    deployments evaluates the ID of the deployment object specified in step number 1
    deployedObject is an attribute

  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:

    following table describes the elements for the attributes AdminConfig
    Element Definition
    $ is a Jacl operator for substituting a variable name with its value
    AdminConfig is an object that represents the WAS configuration
    attributes is an AdminConfig command
    SessionManager is an 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"

  5. Set up the attributes for session manager. The following example sets four top-level attributes in the session manager.

    We can modify the example to set other attributes in the session manager, including the nested attributes in Cookie, DRSSettings, SessionDataPersistence, and TuningParms object types. To list the attributes for those object types, use the attributes command of AdminConfig object.

    The session manager requires 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. gotcha

    • Jacl:

      set attr0 [list enable true]
      set attr1 [list enableSecurityIntegration true]
      set attr2 [list maxWaitTime 30]
      set attr3 [list sessionPersistenceMode NONE]
      set attr4 [list enableCookies true]
      set attr5 [list invalidationTimeout 45]
      set tuningParmsDetailList [list $attr5]
      set tuningParamsList [list tuningParams $tuningParmsDetailList]
      set pwdList [list password 95ee608]
      set userList [list userId Administrator]
      set dsNameList [list datasourceJNDIName jdbc/session]
      set dbPersistenceList [list $dsNameList $userList $pwdList]
      set sessionDBPersistenceList [list $dbPersistenceList]
      set sessionDBPersistenceList [list sessionDatabasePersistence $dbPersistenceList]
      set kuki [list maximumAge 1000]
      set cookie [list $kuki]
      set cookieSettings [list defaultCookieSettings $cookie]
      set sessionManagerDetailList [list $attr0 $attr1 $attr2 $attr3 $attr4 $cookieSettings  $tuningParamsList $sessionDBPersistenceList]
      set sessionMgr [list sessionManagement $sessionManagerDetailList]
      set id [$AdminConfig create ApplicationConfig $appDeploy [list $sessionMgr] configs]
      set targetMappings [lindex [$AdminConfig showAttribute $appDeploy targetMappings] 0]
      set attrs [list config $id]
      $AdminConfig modify $targetMappings [list $attrs]

      Supported configurations: The last five lines in the previous sample assumes that you deployed the web module to only one target server. We can target a module to multiple servers or clusters, by using a loop, to apply the update to each target. Replace the last six lines of the previous sample with the following code to apply updates to multiple targets:

      set id [$AdminConfig create ApplicationConfig $appDeploy [list $sessionMgr] configs]
       set targetMappings [lindex [$AdminConfig showAttribute $appDeploy targetMappings] 0]
       foreach target $targetMappings {
          if {[regexp DeploymentTargetMapping $target] == 1} {
              set attrs [list config $id]
              $AdminConfig modify $target [list $attrs]
          }
      }
      sptcfg

      Example output using Jacl:

        sessionManagement {{enableSecurityIntegration true} {maxWaitTime 30} {sessionPersistenceMode NONE} {enabled true}}

    • Jython:

      attr0 = ['enable', 'true']
      attr1 = ['enableSecurityIntegration', 'true']
      attr2 = ['maxWaitTime', 30]
      attr3 = ['sessionPersistenceMode', 'NONE']
      attr4 = ['enableCookies', 'true']
      attr5 = ['invalidationTimeout', 45]
      tuningParmsDetailList = [attr5]
      tuningParamsList = ['tuningParams', tuningParmsDetailList]
      pwdList = ['password', '95ee608']
      userList = ['userId', 'Administrator']
      dsNameList = ['datasourceJNDIName', 'jdbc/session']
      dbPersistenceList = [dsNameList, userList, pwdList]
      sessionDBPersistenceList = [dbPersistenceList]
      sessionDBPersistenceList = ['sessionDatabasePersistence', dbPersistenceList]
      kuki = ['maximumAge', 1000]
      cookie = [kuki]
      cookieSettings = ['defaultCookieSettings', cookie]
      sessionManagerDetailList = [attr0, attr1, attr2, attr3, attr4, cookieSettings,  tuningParamsList, sessionDBPersistenceList]
      sessionMgr = ['sessionManagement', sessionManagerDetailList]
      id = AdminConfig.create('ApplicationConfig', appDeploy,[sessionMgr], 'configs')
      targetMappings = AdminConfig.showAttribute(appDeploy, 'targetMappings')
      targetMappings = targetMappings[1:len(targetMappings)-1]
      print targetMappings
      attrs = ['config', id]
      AdminConfig.modify(targetMappings,[attrs])

      Supported configurations: The last six lines in the previous sample assumes that you deployed the web module to only one target server. We can target a module to multiple servers or clusters, by using a loop, to apply the update to each target. Replace the last six lines of the previous sample with the following code to apply updates to multiple targets:

      id = AdminConfig.create('ApplicationConfig', appDeploy,[sessionMgr], 'configs')
       targetMappings = AdminConfig.showAttribute(appDeploy, 'targetMappings')
      targetMappings = targetMappings[1:len(targetMappings)-1].split(" ")
      for target in targetMappings:
       if target.find('DeploymentTargetMapping') != -1:
        attrs = ['config', id]
        AdminConfig.modify(target,[attrs])
       #endif
      #endfor
      sptcfg

      Example output using Jython:

        [sessionManagement, [[enableSecurityIntegration, true], [maxWaitTime, 30], [sessionPersistenceMode, NONE]]

  6. Set up the attributes for the web module. For example:

    • Jacl:

      set nameAttr [list name myWebModuleConfig]
      set descAttr [list description "Web Module config post create"]
      set webAttrs [list $nameAttr $descAttr $sessionMgr]

      Example output:

        {name myWebModuleConfig} {description {Web Module config post create}} {sessionManagement {{enableSecurityIntegration true} {maxWaitTime 30} {sessionPersistenceMode NONE} {enabled true}}}

    • Jython:

      nameAttr = ['name', 'myWebModuleConfig']
      descAttr = ['description', "Web Module config post create"]
      webAttrs = [nameAttr, descAttr, sessionMgr]

      Example output:

        [[name, myWebModuleConfig], [description, "Web Module config post create"], [sessionManagement, [[enableSecurityIntegration, true], [maxWaitTime, 30], [sessionPersistenceMode, NONE], [enabled, true]]]]

    where:

    Element Definition
    set is a Jacl command
    nameAttr, descAttr, webAttrs are variable names
    $ is a Jacl operator for substituting a variable name with its value
    name is an attribute
    myWebModuleConfig is a value of the name attribute
    description is an attribute
    Web Module config post create is a value of the description attribute

  7. Create the session manager for each web module in the application. We can modify the following example to set other attributes of the session manager in a web module configuration. We must also define a target mapping for this step.

    • Jacl:

      foreach module $mod1 {
       if {[regexp WebModuleDeployment $module] == 1} {
        set moduleConfig [$AdminConfig create WebModuleConfig $module $webAttrs]
        set targetMappings [lindex [$AdminConfig showAttribute $module targetMappings] 0]
        set attrs [list config $moduleConfig]
        $AdminConfig modify $targetMappings [list $attrs]
       }
      }

      Supported configurations: We can add an optional, additional loop to assign new web module configuration to each target, if the web module is deployed to more than one target server:

      foreach module $mod1 {      if {[regexp WebModuleDeployment $module] == 1} {          set moduleConfig [$AdminConfig create WebModuleConfig $module $webAttrs]          set targetMappings [lindex [$AdminConfig showAttribute $module targetMappings] 0]
              foreach target $targetMappings {
              if {[regexp DeploymentTargetMapping $target] == 1} {
                  set attrs [list config $moduleConfig]              $AdminConfig modify $target [list $attrs]
              }      }
      }
      sptcfg

    • Jython:

      arrayModules = mod1[1:len(mod1)-1].split(" ")
      for module in arrayModules:
       if module.find('WebModuleDeployment') != -1:
        AdminConfig.create('WebModuleConfig', module, webAttrs)
        targetMappings = targetMappings[1:len(targetMappings)-1]
        attrs = ['config', moduleConfig]
        AdminConfig.modify (targetMappings, [attrs])

      Supported configurations: We can add an optional, additional loop to assign new web module configuration to each target, if the web module is deployed to more than one target server:

      arrayModules = mod1[1:len(mod1)-1].split(" ")
      for module in arrayModules:
        if module.find('WebModuleDeployment') != -1:
          moduleConfig = AdminConfig.create('WebModuleConfig', module, webAttrs)
          attrs = ['config', moduleConfig]
          targetMappings = AdminConfig.showAttribute(appDeploy, 'targetMappings')
          targetMappings = targetMappings[1:len(targetMappings)-1].split(" ")
          for target in targetMappings:
              if target.find('DeploymentTargetMapping') != -1:
                  attrs = ['config', moduleConfig]
                  AdminConfig.modify(target,[attrs])
      sptcfg

    Example output:

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

    If we do not specify the tuningParamsList attribute when creating the session manager, you will receive an error when you start the deployed application.

  8. Save the configuration changes.

    Use the following command example to save the configuration changes:

      AdminConfig.save()

  9. In a network deployment environment only, 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 concepts

  • Session management support


    Related tasks

  • Start the wsadmin scripting client
  • Configure applications for session management
  • Configure session management by level
  • Develop session management in servlets
  • Use the script library to automate the application serving environment
  • Use the wsadmin scripting AdminConfig object for scripted administration