简体   繁体   中英

How to find the weblogic jmx attributes for a objectname

I am writing simple client application to connect to weblogic and list all the libraries that a webapp is depending on.However, I am having difficulty in finding the right attributes for a objectname. For example,

If you look at the below sample code given on oracle.com to connect MBeanServer

public static void initConnection(String hostname, String portString,
  String username, String password) throws IOException,
  MalformedURLException {

  String protocol = "t3";
  Integer portInteger = Integer.valueOf(portString);
  int port = portInteger.intValue();
  String jndiroot = "/jndi/";
  String mserver = "weblogic.management.mbeanservers.edit";

  JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port,
  jndiroot + mserver);

  Hashtable h = new Hashtable();
  h.put(Context.SECURITY_PRINCIPAL, username);
  h.put(Context.SECURITY_CREDENTIALS, password);
  h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
     "weblogic.management.remote");
     connector = JMXConnectorFactory.connect(serviceURL, h);
     connection = connector.getMBeanServerConnection();


}

public ObjectName startEditSession() throws Exception {
  // Get the object name for ConfigurationManagerMBean.
  ObjectName cfgMgr = (ObjectName) connection.getAttribute(service,
     "ConfigurationManager");



  // Instruct MBeanServerConnection to invoke
  // ConfigurationManager.startEdit(int waitTime int timeout).
  // The startEdit operation returns a handle to DomainMBean, which is
  // the root of the edit hierarchy.
  ObjectName domainConfigRoot = (ObjectName) 
     connection.invoke(cfgMgr,"startEdit", 
     new Object[] { new Integer(60000),
     new Integer(120000) }, new String[] { "java.lang.Integer",
     "java.lang.Integer" });
  if (domainConfigRoot == null) {
     // Couldn't get the lock
     throw new Exception("Somebody else is editing already");
  }
  return domainConfigRoot;




}

The line

ObjectName cfgMgr = (ObjectName) connection.getAttribute(service, " ConfigurationManager ");

Is referring to a JMX attribute ConfigurationManger . How can we find all the attributes that are under a given objectname in weblogic?

Thanks for your help!!

Nevermind! I found the solution.

You get attributes for a ObjectName by calling getBeanInfo on the ServerConnection!

Example: MBeanAttributeInfo[] beanInfo = (connection.getMBeanInfo(objectName)).getAttributes();

for(MBeanAttributeInfo info:beanInfo) System.out.println(info.getType()+" "+info.getName());

也许WebLogic Classloader分析工具(CAT)可以提供其他开箱即用的见解...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM