Getting server information in WebLogic

Source: Internet
Author: User
Tags split

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.