Search code examples
webspherejythonwsadmin

websphere Jython scripting : querying custom properties of activation specifications


how can I iterate on custom properties of Activation specification ? In fact I want to get the value of "WAS_EndpointInitialState".

asList = AdminConfig.list('J2CActivationSpec').splitlines()
for as in asList:
    asName = AdminConfig.showAttribute(as, 'name')
    # beyond this point it does not work
    propSet = AdminConfig.showAttribute(as, 'resourceProperties')
    propList = AdminConfig.list('J2EEResourceProperty', propSet).splitlines()
    for prop in propList:
        print 'name = ' + AdminConfig.showAttribute(prop, 'name')
        print 'value = ' + AdminConfig.showAttribute(prop, 'value')

Solution

  • The resourceProperties attribute is a space-separated string, surrounded by square parentheses. The following script should work for you:

    asList = AdminConfig.list('J2CActivationSpec').splitlines()
    for as in asList:
        asName = AdminConfig.showAttribute(as, 'name')
        propList = AdminConfig.showAttribute(as, 'resourceProperties')[1:-1].split()
        for prop in propList :
            print 'name = ' + AdminConfig.showAttribute(prop, 'name')
            print 'value = ' + AdminConfig.showAttribute(prop, 'value')
    

    It may break though if property names have any white spaces in their object IDs.

    You can handle all the edge cases with regular expressions or try WDR library (http://wdr.github.io/WDR/ https://github.com/WDR/WDR) which does that already. Plus, it makes your scripts more readable and maintainable.

    With WDR the script would look like this:

    asList = listConfigObjects('J2CActivationSpec')
    for as in asList:
        asName = as.name
        propList = as.resourceProperties
        for prop in propList :
            print 'name = ' + prop.name
            print 'value = ' + prop.value