使用脚本编制为会话管理配置应用程序

本任务提供了使用 AdminConfig 对象为应用程序配置会话管理器的示例。

准备工作

必须将应用程序安装在运行中的服务器上。

有关此任务

可以使用 AdminConfig 对象来设置应用程序中的配置。 某些配置设置不可用于 AdminConfig 对象。

过程

  1. 启动 wsadmin 脚本编制工具。
  2. 识别应用程序的部署配置对象,并将其指定给 deployment 变量。
    注: OSGi 应用程序不需要执行此步骤。
    例如:
    • 使用 Jacl:
      test
      set deployments [$AdminConfig getid /Deployment:myApp/]
    • 使用 Jython:
      deployments = AdminConfig.getid('/Deployment:myApp/')
      print deployments
    其中:
    表 1。 getid 命令元素 运行 getid 命令以识别部署对象。
    元素 描述
    set 是 Jacl 命令
    deployments 是变量名
    $ 是使用其值替换变量名的 Jacl 运算符
    AdminConfig 是表示 WebSphere® Application Server 配置的对象
    getid 是 AdminConfig 命令
    部署 是属性
    myApp 是属性的值
    示例输出如下所示:
    myApp(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#Deployment_1)
  3. 检索应用程序部署对象并将它指定给 appDeploy 变量。
    例如:
    • 使用 Jacl:
      set appDeploy [$AdminConfig showAttribute $deployments deployedObject]
    • 使用 Jython:
      appDeploy = AdminConfig.showAttribute(deployments, 'deployedObject')
      print appDeploy
    注: 对于 OSGi 应用程序,请将以下 Jython 代码用于此步骤:
    appDeploy = AdminTask.getOSGiApplicationDeployedObject('-cuName cu_name')
    其中:
    表 2。 set 命令元素 运行 set 命令以对部署对象指定一个值。
    元素 描述
    set 是 Jacl 命令
    appDeploy 是变量名
    $ 是使用其值替换变量名的 Jacl 运算符
    AdminConfig 是表示 WebSphere Application Server 配置的对象
    showAttribute 是 AdminConfig 命令
    deployments 对步骤 1 中指定的部署对象标识所求的值
    deployedObject 是属性
    cu_name 是组合单元的名称
    示例输出如下所示:
    (cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#ApplicationDeployment_1)
  4. 要获取可以为会话管理器设置的属性列表,请使用 attributes 命令。 例如:
    • 使用 Jacl:
      $AdminConfig attributes SessionManager
    • 使用 Jython:
      print AdminConfig.attributes('SessionManager')
    其中:
    表 3。 attributes 命令元素 运行 attributes 命令以列示会话管理器的属性。
    元素 描述
    $ 是使用其值替换变量名的 Jacl 运算符
    AdminConfig 是表示 WebSphere Application Server 配置的对象
    属性 是 AdminConfig 命令
    SessionManager 是属性
    示例输出如下所示:
    "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"

    为会话管理配置应用程序时,建议您指定每个属性。

    避免麻烦: 如果要为集群设置会话管理属性,那么在为 sessionManagment 元素指定的设置生效之前,还必须为集群更新 AdminConfig 对象的 targetMappings 元素。 如果不更新 targetMappings 元素,那么即使这些设置出现在 deployment.xml 文件中也不会生效。
  5. 设置会话管理器的属性。

    以下示例设置会话管理器中的四个顶级属性。 可以修改该示例以设置会话管理器的其他属性,包括 DRSSettings、SessionDataPersistence 和 TuningParms 对象类型中的嵌套属性。

    避免麻烦:

    会话管理器使用您可以设置的 defaultCookie设置和 tuningParams 属性来初始化应用程序。 从 V 9.0.0.4开始,如果未设置这些属性,那么会话管理器将使用缺省会话和 cookie 设置来初始化应用程序。

    在 9.0.0.4之前的版本中,会话管理器要求您先设置 defaultCookie设置和 tuningParams 属性,然后再初始化应用程序。 如果不设置这些属性,那么会话管理器将不能初始化应用程序,并且应用程序将不启动。

    要列示这些对象类型的属性,使用 AdminConfig 对象的 attributes 命令。

    • 使用 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]
      
      使用 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]]
      使用 Jython 的示例输出:
      [[sessionManagement, [[enableSecurityIntegration, true], [maxWaitTime, 30], [sessionPersistenceMode, NONE], 
      [defaultCookieSettings [[maximumAge, -1]]]]
    其中:
    表 4。 set 命令元素 运行 set 命令以设置会话管理器的属性。
    元素 描述
    set 是 Jacl 命令
    attr1、attr2、attr3、attrs、sessionMgr 是变量名
    $ 是使用其值替换变量名的 Jacl 运算符
    enableSecurityIntegration 是属性
    是 enableSecurityIntegration 属性的值
    maxWaitTime 是属性
    30 是 maxWaitTime 属性的值
    sessionPersistenceMode 是属性
    是 sessionPersistenceMode 属性的值
  6. 请执行下列其中一项操作:
    • 创建应用程序的会话管理器。 例如:
      • 使用 Jacl:
        $AdminConfig create ApplicationConfig $appDeploy [list $sessionMgr]
      • 使用 Jython:
        print AdminConfig.create('ApplicationConfig', appDeploy, sessionMgr)
      其中:
      表 5。 create command 元素 运行 create 命令以创建会话管理器。
      元素 描述
      $ 是使用其值替换变量名的 Jacl 运算符
      AdminConfig 是表示 WebSphere Application Server 配置的对象
      create 是 AdminConfig 命令
      ApplicationConfig 是属性
      appDeploy 对步骤 2 中指定的已部署应用程序标识所求的值
      列表 是 Jacl 命令
      sessionMgr 对步骤 4 中指定的会话管理器标识所求的值
      示例输出如下所示:
      (cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#ApplicationConfig_1)
    • 如果会话管理器已存在,请使用 AdminConfig 对象的 modify 命令来更新该会话管理器的配置。 例如:
      • 使用 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. 保存配置更改。
    请使用以下命令示例来保存配置更改:
    AdminConfig.save()
  8. 使节点同步。
    使用 AdminNodeManagement 脚本库中的 syncActiveNode 或 syncNode 脚本将配置更改传播至一个或多个节点。
    • 使用 syncActiveNodes 脚本将更改传播至单元中的每个节点,如以下示例所示:
      AdminNodeManagement.syncActiveNodes()
    • 使用 syncNode 脚本将更改传播至特定节点,如以下示例所示:
      AdminNodeManagement.syncNode("myNode")