Configure stateful session bean failover at the module level
Use scripting and wsadmin.sh to configure applications for stateful session bean failover.
Before starting this task, wsadmin.sh must be running.
We can use the AdminConfig object to set configurations in an application. In this task, use theAdminConfig object to display the stateful session bean failover configuration for an EJB module in the application. Then, use the AdminConfig object to modify the stateful session bean failover configuration for a web module in the same application.
- Use the AdminConfig object to display the stateful session bean failover configuration for an EJB module in the application.
- Start the wsadmin scripting client.
- Jacl
wsadmin
- Jython
wsadmin -lang Jython
- Identify the deployment configuration object for the application, and assign it to a variable; for example:
- Jacl
set app [$ AdminConfig getid /Deployment:EJBinWARTest/] set depObj [$ AdminConfig showAttribute $app deployedObject]
- Jython
app = AdminConfig.getid("/Deployment:EJBinWARTest/" ) depObj = AdminConfig.showAttribute(app, "deployedObject" )
- Get the list of modules for the application.
- Jacl
set modules [lindex [$ AdminConfig showAttribute $depObj modules] 0]
- Jython
modules = AdminConfig.showAttribute(depObj, "modules" ) modules = modules.replace('[','').replace(']','') modules = modules.split(' ')
- In this example, the EJB module, EJBBean.jar, contains an enterprise bean, and the web module, EJB2xInWARBean.war,contains another enterprise bean. The following code shows how to modify the stateful session bean configuration for each of these enterprise beans.
- Jacl
# Assign the EJB and web module configuration IDs to variables ejbmod and webmod: foreach module $modules { set moduleName [$ AdminConfig show $module uri] if { [string first "EJBBean.jar" $moduleName] >= 0} { set ejbmod $module } if { [string first "EJB2xInWARBean.war" $moduleName] >= 0} { set webmod $module } }
- Jython
# Assign the EJB and web module configuration IDs to variables ejbmod and webmod: for module in modules: moduleName = AdminConfig.showAttribute(module, 'uri') if moduleName.find('EJBBean.jar') >= 0: ejbmod = module if moduleName.find('EJB2xInWARBean.war') >= 0 : webmod = module
- Get the EJB module configuration object.
- Jacl
# Get the single EJB module configuration object associated with the pure EJB module: set ejbConfig [lindex [$ AdminConfig showAttribute $ejbmod configs] 0] if { ($ejbConfig == "") } { puts "\nejbConfig not present - creating one" set ejbConfig [$ AdminConfig create EJBModuleConfiguration $ejbmod {{enableSFSBFailover true} {overrideDefaultDRSSettings false}}] set attrs [list config $ejbConfig] set targetMappings [lindex [$ AdminConfig showAttribute $ejbmod targetMappings] 0] $ AdminConfig modify $targetMappings [list $attrs] } else { puts "\nejbConfig present" }
- Jython
# Get the list of configuration objects associated with the pure EJB module: ejbmodConfigs = AdminConfig.showAttribute (ejbmod, 'configs') if (ejbmodConfigs): print "\nejbmodConfigs present" # Extract the single EJB module configuration object: ejbConfig = ejbmodConfigs.replace('[','').replace(']','') print "\nejbConfig:" print AdminConfig.show(ejbConfig) else: print "\nejbmodConfigs not present - creating one" ecAttrs = [] attr1 = ["enableSFSBFailover", "true"] attr2 = ["overrideDefaultDRSSettings", "false"] ecAttrs.append(attr1) ecAttrs.append(attr2) ejbConfig = AdminConfig.create('EJBModuleConfiguration', ejbmod, ecAttrs) tmAttrs = ['config', ejbConfig] targetMappings = AdminConfig.showAttribute (ejbmod, 'targetMappings') targetMappings = targetMappings[1:len(targetMappings)-1] AdminConfig.modify(targetMappings, [tmAttrs])
- Display the stateful session bean failover configuration settings of the EJB module.
- Jacl
# Show the Stateful session bean failover configuration of the EJB module: puts "\nStateful session bean failover settings of the EJB module" puts [$ AdminConfig show $ejbConfig] # Show the drsSettings of the EJB module: set drsSettings [$ AdminConfig showAttribute $ejbConfig drsSettings] if { ($drsSettings == "") } { puts "drsSettings not present on the EJB module." } else { puts "\ndrsSettings of the EJB module:" puts [$ AdminConfig show $drsSettings] }
- Jython
# Show the Stateful session bean failover configuration of the EJB module: print AdminConfig.show(ejbConfig) # Show the drsSettings of the EJB module: drsSettings = AdminConfig.showAttribute (ejbConfig, 'drsSettings') if (drsSettings): print "\ndrsSettings of the EJB module:" print AdminConfig.show(drsSettings) else: print "\ndrsSettings not present on the EJB module." drsSettings = AdminConfig.showAttribute (ejbConfig, 'drsSettings') if (drsSettings): print "\ndrsSettings of the EJB module:" print AdminConfig.show(drsSettings) else: print "\ndrsSettings not present on the EJB module."
- Use the AdminConfig object to modify the stateful session bean failover configuration for an enterprise bean within a web module in the same application. For an EJB module packaged in a WAR file, the steps are similar, with the added step of extracting the EJB module from the list of configuration objects.
- Given the web module configuration ID in step 4, get the EJB module configuration object that is associated with the Web module.
- Jacl
# Get the web module configuration object: set webmodConfig [lindex [$ AdminConfig showAttribute $webmod configs] 0] # Extract the EJB module configuration object associated with the web module. set ejbInWarConfig [$ AdminConfig showAttribute $webmodConfig ejbModuleConfiguration]
- Jython
# Get the list of configuration objects associated with the web module: webmodConfigs = AdminConfig.showAttribute (webmod, 'configs') # Extract the single web module configuration object: webmodConfig = webmodConfigs.replace('[','').replace(']','') # Extract the EJB module configuration object associated with the web module. ejbInWarConfig = AdminConfig.showAttribute (webmodConfig, 'ejbModuleConfiguration')
- Display the stateful session bean configuration settings.
- Jacl
# Show the configuration of the EJB module within the web module: puts "\nStateful session bean failover settings of the EJB within the web module:" puts [$ AdminConfig show $ejbInWarConfig] # Get the SFSB failover settings of the EJB module within the web module: set drsSettings [$ AdminConfig showAttribute $ejbInWarConfig drsSettings] if { ($drsSettings == "") } { puts "drsSettings not present on the EJB within the Web module." } else { puts "\ndrsSettings of the EJB within the Web module:" puts [$ AdminConfig show $drsSettings] }
- Jython
print "\nStateful session bean failover configuration of the EJB module within the web module:" print AdminConfig.show(ejbInWarConfig) drsSettings = AdminConfig.showAttribute(ejbInWarConfig, 'drsSettings') if (drsSettings): print "\ndrsSettings of the EJB module within the web module:" print AdminConfig.show(drsSettings) else: print "\ndrsSettings not present on the EJB module within the web module." print "\ndrsSettings of the EJB module within the Web module:"
- Modify the stateful session bean configuration settings.
- Jacl
# To enable SFSB failover for the EJB within the web module: $ AdminConfig modify $ejbInWarConfig {{enableSFSBFailover "true"}}
- Jython
# Enable SFSB failover for the EJB within the web module: AdminConfig.modify(ejbInWarConfig, [['enableSFSBFailover', 'true']])
Related concepts
Stateful session bean failover for the EJB container
Related tasks
Enable or disable stateful session bean failover at the EJB module level using the administrative console Enable or disable stateful session bean failover with the EJB container panel
Stateful session beans failover settings (EJB modules)