Is it possible to access WebSphere variables using java AdminClient without AdminOperations?

StackOverflow https://stackoverflow.com/questions/21632853

  •  08-10-2022
  •  | 
  •  

Pergunta

I am writing a tool that will validate WebSphere settings of a web application. I want to be able to look up all possible values of a WebSphere variable (all scopes) by remotely connecting to the server through the java AdminClient object. I have already read another post about this and although I think I now have the correct code I am not able to use the AdminOperations MBean because the WebSphere account I have to use is not granted admin privileges. I would like to know if there is a way to resolve WebSphere variables without using AdminOperations. Thanks!

Here is my code so far (again, does not work due to privilege issues):

private static String expandVariable(AdminClient client, String s)
    throws Exception 
{ 
    Set result = client.queryNames(new ObjectName("*:*,type=AdminOperations,process=exampleProcess"), null);

    return (String)client.invoke((javax.management.ObjectName) 
    result.iterator().next(),"expandVariable",new Object[] 
    {"${"+s+"}"}, new String[] {"java.lang.String"});

}
Foi útil?

Solução

A User with Monitor role can use ConfigService's queryConfigObjects API and other configservice APIs to access the variables from configuration(not runtime).

Infocenter link : http://pic.dhe.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=%2Fcom.ibm.websphere.javadoc.doc%2Fweb%2Fapidocs%2Fcom%2Fibm%2Fwebsphere%2Fmanagement%2Fconfigservice%2Fpackage-summary.html&resultof=%22ConfigServiceProxy%22%20%22configserviceproxi%22%20

Sample snippet as below:

        //name of variable that needs to be expanded
        String varName ="DERBY_JDBC_DRIVER_PATH";
        //create a configservice proxy
        configService = new ConfigServiceProxy(adminClient);
        //create a session
        Session session = new Session();
        //ObjectName for the variables.xml
        ObjectName varMapObjName = ConfigServiceHelper.createObjectName(null, "VariableMap", null);
        //query all variables.xml under cell.scope is null
        ObjectName[] variableMaps = configService.queryConfigObjects(session, null, varMapObjName, null);

        for (int i = 0; i < variableMaps.length; i++) {
            ObjectName varMap = (ObjectName) variableMaps[i];
            //retrieve each variable entry
            AttributeList varEntries = configService.getAttributes(session, varMap, new String[]{"entries"}, false);
            List entryList = (List) ConfigServiceHelper.getAttributeValue(varEntries, "entries");
            //Iterate through each entry and get the value for the specified variable(symbolicName) name.
            for (int j = 0; j < entryList.size(); j++) {
                ObjectName varObj = (ObjectName)entryList.get(j);
                String symbolicName=  (String)configService.getAttribute(session, varObj, "symbolicName");
                String value = null;
                if (symbolicName.equals(varName)){
                    value= (String)configService.getAttribute(session, varObj, "value");
                    System.out.println(symbolicName+"="+value);
                }
            }
        }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top