Where to get Weblogic server port information in weblogic.jar
I'm trying to instrument few classes of weblogic to monitor the application performance.
开发者_运维百科I'm facing few issues while trying to find the weblogic's server port(that listens to http/https requests) information.
Looking into weblogic javadocs, ServerMBean's setListenPort(int port) can be used to identify the port. However, this is called for all the configured servers. But setListenPort is not called when listen-port is not configured for the element in Config.xml.
Of course, the value inside the MBean impl defaults to 7001 when listen-port is not configured.
Is there a better way to find the web server port of weblogic?
The following code queries the MBeanServer for the URL of the runtime environment it is running in:
JVMID jvmid = JVMID.localID();
String serverName = jvmid.getServerName();
String serverAddress = jvmid.getAddress();
InitialContext ctx = new InitialContext();
MBeanServer server = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");
// weblogic.management.configuration.ServerMBean
ObjectName objName = new ObjectName("com.bea:Name=" + serverName + ",Type=Server");
// weblogic.management.configuration.SSLMBean
ObjectName sslObjName = new ObjectName("com.bea:Name=" + serverName + ",Type=SSL,Server=AdminServer");
int port = (Integer) server.getAttribute(objName, "ListenPort");
boolean https = (Boolean) server.getAttribute(sslObjName, "Enabled");
return "http" + (https ? "s" : "") + "://" + serverAddress + ":" + port + "/";
The place I've always looked is the output of the Admin Server startup - the log file is often nice enough to leave a record right before the "Server status is now RUNNING" message that lists the IP and port number that the admin console is listening on...
精彩评论