Reputation: 61
I would like to get the value of the Websphere variable ORB_LISTENER_PORT from a java class. How it can be done?
I have read topik and understood it. I think i must use some value instead "expandVariable". But what kind of the value?
Upvotes: 4
Views: 1826
Reputation: 61
I solved the problem by yourself. The following code sample and the result of his work.
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>");
}
}
Listing of function is:
Upvotes: 2