我想从 java 类中获取 Websphere 变量 ORB_LISTENER_PORT 的值。怎么做?
我已经阅读了topik并理解了它。我认为我必须使用一些值而不是“expandVariable”。但是什么样的价值呢?
我自己解决了这个问题。以下代码示例和他的工作结果。
import com.ibm.websphere.management.Session;
import com.ibm.websphere.management.configservice.ConfigService;
import com.ibm.websphere.management.configservice.ConfigServiceFactory;
import com.ibm.websphere.management.configservice.ConfigServiceHelper;
public void readWebsphereConfiguration( PrintWriter out ){
try{
out.println("<p>Using ConfigService to get the hostName and port of this server.</p>");
Session session = new Session();
ConfigService cs = ConfigServiceFactory.getConfigService();
ObjectName[] serverIndexONs = cs.resolve(session, "ServerIndex=");
String hostName = (String) cs.getAttribute(session, serverIndexONs[0], "hostName");
out.println("<p>HostName: " + hostName + "</p>");
ObjectName[] namedEndPointsONs = cs.queryConfigObjects(session, serverIndexONs[0], ConfigServiceHelper.createObjectName(null, "NamedEndPoint"), null);
for (int i = 0; i < namedEndPointsONs.length; ++i){
String str = (String) cs.getAttribute(session, namedEndPointsONs[i], "endPointName");
ObjectName[] theEndPoints = cs.queryConfigObjects(session, namedEndPointsONs[i], ConfigServiceHelper.createObjectName(null, "EndPoint"), null);
String szValue = "";
if(theEndPoints != null && theEndPoints.length > 0){
szValue = ((Integer) cs.getAttribute(session, theEndPoints[0], "port")).toString();
}
out.println("<p>" + str + "=" + szValue +"</p>");
}
}catch(Exception e){
out.println("<p>Exception while trying to fetch the hostname and port information.: " + e.getMessage() + "</p>");
out.println("<p>Exception:" + e.getStackTrace() + "</p>");
}
}
功能清单是: