Monday, July 25, 2016

Weblogic 12.2.1:Java - JMX to get the Server Name and port

 The following section of code discusses how to get the Server Name and Port for the managed server or a cluster where the API is deployed.

     public static Integer getPort() {
       Integer port=null; 
       try {
            InitialContext ctx = new InitialContext();
            String serverName = System.getProperty("weblogic.Name");

            MBeanServer server =
                (MBeanServer)ctx.lookup("java:comp/env/jmx/runtime");

            ObjectName objName =
                new ObjectName("com.bea:Name=" + serverName + ",Type=Server");
            port = (Integer)server.getAttribute(objName, "ListenPort");
            
            ctx.close();
             
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        return port;
    }

OCI Knowledge Series: OCI Infrastructure components

  Oracle Cloud Infrastructure (OCI) provides a comprehensive set of infrastructure services that enable you to build and run a wide range of...