在 Java 中以编程方式创建 WebSphere 变量
Create WebSphere Variable programatically in Java
我正在编写 Java 代码来创建应用程序所需的服务器资源。我在 Jython 中完成了它,我在 Java 中也做了类似的事情,但它不起作用。我需要 Java 代码来使用 ConfigServiceProxy 创建 websphere 变量。
我试过了
1. configService.createConfigData(session, varMap, "VariableSubstitutionEntry", "VariableSubstitutionEntry",attributeList)
configService.createConfigData(session, varMap, "entries", "VariableSubstitutionEntry",attributeList)
尝试在 VarMap 中添加 websphere 条目
您可以尝试使用以下示例代码在服务器级别的 VariableMap 上创建 VariableSubstitutionEntry:
ObjectName server = configService.resolve(session, "Node=" + nodeName + ":Server=" + serverName)[0];
ObjectName vm = ConfigServiceHelper.createObjectName(null, "VariableMap", null);
ObjectName[] vms = configService.queryConfigObjects(session, server, vm, null);
AttributeList attrList = new AttributeList();
attrList.add(新属性("symbolicName", "WAS_SERVER_NAME"));
attrList.add(新属性("value", "dmgr"));
ObjectName vse = configService.createConfigData(session, vms[0], "entries", "VariableSubstitutionEntry", attrList);
如果要删除一个VariableSubstitutionEntry,可以试试下面的代码:
if (vms.length != 0) {
ObjectName vm2 = ConfigServiceHelper.createObjectName(null, "VariableSubstitutionEntry", null);
ObjectName[] vms2 = configService.queryConfigObjects(session, vms2[0], vm2, null);
for (int i = 0; i < vms2.length; i++) {
ObjectName vse = vms2[i];
String name = (String) configService.getAttribute(session, vse, "symbolicName");
if (name.equals("WAS_SERVER_NAME")) {
configService.deleteConfigData(session, vse);
configService.save(session, false);
}
}
}
要更新值:
for (int i = 0; i < vms2.length; i++) {
ObjectName vse = vms2[i];
String name = (String) configService.getAttribute(session, vse, "symbolicName");
if (name.equals("WAS_SERVER_NAME")) {
AttributeList newVal = new AttributeList();
String newValue = "dmgr2";
newVal.add(new Attribute("value", newValue));
configService.setAttributes(session, vse, newVal);
configService.save(session, false);
}
}
我正在编写 Java 代码来创建应用程序所需的服务器资源。我在 Jython 中完成了它,我在 Java 中也做了类似的事情,但它不起作用。我需要 Java 代码来使用 ConfigServiceProxy 创建 websphere 变量。
我试过了 1. configService.createConfigData(session, varMap, "VariableSubstitutionEntry", "VariableSubstitutionEntry",attributeList)
configService.createConfigData(session, varMap, "entries", "VariableSubstitutionEntry",attributeList)
尝试在 VarMap 中添加 websphere 条目
您可以尝试使用以下示例代码在服务器级别的 VariableMap 上创建 VariableSubstitutionEntry:
ObjectName server = configService.resolve(session, "Node=" + nodeName + ":Server=" + serverName)[0];
ObjectName vm = ConfigServiceHelper.createObjectName(null, "VariableMap", null);
ObjectName[] vms = configService.queryConfigObjects(session, server, vm, null);
AttributeList attrList = new AttributeList(); attrList.add(新属性("symbolicName", "WAS_SERVER_NAME")); attrList.add(新属性("value", "dmgr"));
ObjectName vse = configService.createConfigData(session, vms[0], "entries", "VariableSubstitutionEntry", attrList);
如果要删除一个VariableSubstitutionEntry,可以试试下面的代码:
if (vms.length != 0) { ObjectName vm2 = ConfigServiceHelper.createObjectName(null, "VariableSubstitutionEntry", null); ObjectName[] vms2 = configService.queryConfigObjects(session, vms2[0], vm2, null);
for (int i = 0; i < vms2.length; i++) {
ObjectName vse = vms2[i];
String name = (String) configService.getAttribute(session, vse, "symbolicName");
if (name.equals("WAS_SERVER_NAME")) {
configService.deleteConfigData(session, vse);
configService.save(session, false);
}
}
}
要更新值:
for (int i = 0; i < vms2.length; i++) {
ObjectName vse = vms2[i];
String name = (String) configService.getAttribute(session, vse, "symbolicName");
if (name.equals("WAS_SERVER_NAME")) {
AttributeList newVal = new AttributeList();
String newValue = "dmgr2";
newVal.add(new Attribute("value", newValue));
configService.setAttributes(session, vse, newVal);
configService.save(session, false);
}
}