Search code examples
jakarta-eeweblogicjndijmxweblogic12c

Accessing managed server host name and port from webapp


I am working on web application which will be deployed in Weblogic. In this application I need to access the port and host of the managed server. After searching a bit found that JMX with JNDI can help in getting the server details but not sure if host and port details can be accessed in this way, could not find much help in online docs available. Can someone please help me figuring out this?


Solution

  •     //Get ServerConfiguration
        ctx = new InitialContext();
        MBeanServer mBeanServer = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");
        ObjectName ServerConfiguration = (ObjectName) mBeanServer
                .getAttribute(new ObjectName(RuntimeServiceMBean.OBJECT_NAME), "ServerConfiguration");
        // Get ListenPort 
        port = mBeanServer.getAttribute(ServerConfiguration, "ListenPort").toString();