Reputation: 506
I need to know from which server is my app responding at any web request. I'm trying to make local connection with ServerMBeans, but I only get the AdminServer at any port. here is the code:
String serverName = "";
MBeanHome mbean = null;
try {
InitialContext ctx = new InitialContext();
mbean = (MBeanHome) ctx.lookup("java:comp/env/jmx/runtime");
serverName = mbean.getMBeanServer().getServerName();
} catch (Exception ex) {
serverName = ex.getMessage();
}
return serverName;
Upvotes: 1
Views: 8843
Reputation: 9318
Just tested the following excerpt in WebLogic 11g and worked like a charm. Could that be an option for you? I guess it also works in previous versions.
String serverName = System.getProperty("weblogic.Name");
Upvotes: 8