In Java EE we often need to obtain information such as host and port of the current server, such as in a complex EJB program, make some remote calls, or access a WebService component in this machine, in WebLogic, If ListenAddress is set, then localhost this hostname is inaccessible, and we can get information from the server via Mbean to get the IP and port of the server as an example:
objectname rs = null;
Mbeanserver mbeanserver= (mbeanserver) context.lookup ("Java:comp/env/jmx/runtime");
String Runtime_service_mbean = "com.bea:name=runtimeservice,type= Weblogic.management.mbeanservers.runtime.RuntimeServiceMBean ";
rs = new objectname (Runtime_service_mbean);
ObjectName SERVERRT = (objectname) mbeanserver.getattribute (RS, "serverruntime");
String listenaddr = (string) mbeanserver.getattribute (SERVERRT, "listenaddress");
string[] tempaddr = Listenaddr.split ("/");
if (tempaddr.length = 1) {
Listenaddr = tempaddr[0];
else if (Tempaddr[tempaddr.length-1].trim (). Length ()!= 0) {
Listenaddr = tempaddr[tempaddr.length-1];
else if (Tempaddr.length > 2) {
Listenaddr = tempaddr[tempaddr.length-2];
String listenport = string.valueof (Mbeanserver.getattribute (SERVERRT, "Listenport"));
Since ListenAddress is likely to get a weblogic T3 URL, you should split the address and take the last available addresses.
By obtaining the serverreference, we can get more information about the server, refer to the related documentation of WebLogic:
Http://download.oracle.com/docs/cd/E11035_01/wls100/wlsmbeanref/core/index.html
Http://e-docs.bea.com/wls/docs81/jmx/overview.html