【问题标题】:Is it possible to access WebSphere variables using java AdminClient without AdminOperations?是否可以使用没有 AdminOperations 的 java AdminClient 访问 WebSphere 变量?
【发布时间】:2014-02-10 14:10:42
【问题描述】:

我正在编写一个工具来验证 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"});

}

【问题讨论】:

    标签: java websphere remote-access


    【解决方案1】:

    具有 Monitor 角色的用户可以使用 ConfigService 的 queryConfigObjects API 和其他 configservice API 从配置(而不是运行时)访问变量。

    信息中心链接: 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

    sn-p 示例如下:

            //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);
                    }
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      • 1970-01-01
      相关资源
      最近更新 更多