Search code examples
javaweblogicweblogic-10.x

Get the name of the server in which I am receiving requests to my app on weblogic?


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;

Solution

  • 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");