我正在编写一个工具来验证Web应用程序的WebSphere设置。我希望能够通过java AdminClient对象远程连接到服务器来查找WebSphere变量(所有范围)的所有可能值。我已经阅读了another post about this,虽然我认为我现在拥有正确的代码但是我无法使用AdminOperations MBean,因为我必须使用的WebSphere帐户未被授予管理员权限。我想知道是否有办法在不使用AdminOperations的情况下解析WebSphere变量。谢谢!
到目前为止,这是我的代码(再次,由于权限问题而无效):
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"});
}
答案 0 :(得分:2)
具有Monitor角色的用户可以使用ConfigService的queryConfigObjects API和其他配置服务API来从配置(而非运行时)访问变量。
示例摘录如下:
//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);
}
}
}