0 Replies Latest reply on Apr 12, 2013 9:10 AM by 923189

    How to get application's state on weblogic server using jmx.

    923189
      I want to get application state using JMX, I am able to get application list, name but not able to find its state. Some code snippet mentioned below. Please let me know if I can use some other MBean
      Thanks in advance..

      static {
      try {
      service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
      }catch (MalformedObjectNameException e) {
      throw new AssertionError(e.getMessage());
      }
      }

      /*
      * Initialize connection to the Domain Runtime MBean Server
      */
      public static void initConnection(String hostname, String portString, String username, String password) throws IOException, MalformedURLException
      {
      String protocol = "t3";

      int port = Integer.parseInt(portString);
      String jndiroot = "/jndi/";
      String mserver = "weblogic.management.mbeanservers.domainruntime";
      JMXServiceURL serviceURL= new JMXServiceURL(protocol,hostname, port, jndiroot+mserver);


      // JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, portString, 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();
      }

      /*
      * Get an array of ServerRuntimeMBeans
      */
      public static ObjectName[] getServerRuntimes() throws Exception {
      return (ObjectName[]) connection.getAttribute(service,
      "ServerRuntimes");
      }

      /*
      * Get an array of WebAppComponentRuntimeMBeans
      */
      public void getApplicationData() throws Exception {
      ObjectName[] serverRT = getServerRuntimes();
      int length = (int) serverRT.length;
      for (int i = 0; i < length; i++) {
      ObjectName[] appRT =
      (ObjectName[]) connection.getAttribute(serverRT,
      "ApplicationRuntimes");
      int appLength = (int) appRT.length;
      for (int x = 0; x < appLength; x++) {
      System.out.println("Application name: " +
      (String)connection.getAttribute(appRT[x], "Name")+"Application Status"+(String)connection.getAttribute(appRT[x], "State"));



      ……….
      public static void main(String[] args) throws Exception {
      String hostname = "*****.us.oracle.com";
      String portString = "*****";
      String username = "***";
      String password = "****";

      JMXUtil s = new JMXUtil();
      initConnection(hostname, portString, username, password);
      s.getApplicationData();
      connector.close();
      }
      }