0 Replies Latest reply on Jul 4, 2014 11:35 AM by Sri chilukuri

    Unable to retrieve scheme, port information using Mbeans from Jboss EAP 6.1

    Sri chilukuri Newbie

      I am trying to retrieve scheme, port information from mbean.  I am able retrieve those in jboss-eap-5.1.2 using "*:type=Connector,*". I need to retrieve the same in Jboss EAP 6.1 and this information is available in following mbeans(jboss.as:subsystem=web,virtual-server=default-host    jboss.as:socket-binding-group=standard-sockets,socket-binding=http).

       

       

      I am able to retrieve it from MBeanServerConnection and unable to retrieve subsystem related mbean attributes using MbeanServer. Any pointers appreciated . Please find the example below.

       

      import javax.management.MBeanServer;

      import javax.management.MBeanServerConnection;

      import javax.management.MBeanServerFactory;

      import javax.management.ObjectName;

      import javax.management.remote.JMXConnector;

      import javax.management.remote.JMXConnectorFactory;

      import javax.management.remote.JMXServiceURL;

       

      public class TestMbeans {

       

      private String jbossHost;

      private int jbossMgmtPort;

      private MBeanServerConnection connection;

      private JMXConnector jmxConnector;

       

      public TestMbeans(String jbossHost,int jbossMgmtPort)throws Exception

      {

                this.jbossMgmtPort=jbossMgmtPort;

                this.jbossHost=jbossHost;

                String urlString ="service:jmx:remoting-jmx://" + jbossHost + ":" + jbossMgmtPort;

                JMXServiceURL serviceURL = new JMXServiceURL(urlString);

                jmxConnector = JMXConnectorFactory.connect(serviceURL, null);

                connection = jmxConnector.getMBeanServerConnection();

      }

       

      public void showSessionDetails() throws Exception

      {

      ObjectName objectName=new ObjectName("jboss.as:subsystem=web,connector=http"); 

      System.out.println("\n\n********************* Details of "+objectName+" *********************");

                //Integer sessionMaxAliveTime=(Integer)connection.getAttribute(objectName, "protocol");

      Object attribute = connection.getAttribute(objectName, "scheme");

      ObjectName socketBindingObjName=new ObjectName("jboss.as:socket-binding-group=standard-sockets,socket-binding=http");

                System.out.println("    scheme = "+attribute);

                System.out.println("    protocol = "+connection.getAttribute(objectName, "protocol"));

                System.out.println("    redirectPort     = "+connection.getAttribute(objectName, "redirectPort"));

                System.out.println("    proxyPort = "+connection.getAttribute(objectName, "proxyPort"));

                System.out.println("    port = "+connection.getAttribute(socketBindingObjName, "port"));

       

      }

       

      public void showSessionDetailsWithPlatformMbeanServer() throws Exception

      {

                 MBeanServer platformMBeanServer = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);

                 System.out.println(platformMBeanServer);

                 ObjectName objectName=new ObjectName("jboss.as:subsystem=web,connector=http"); 

                 System.out.println("\n\n********************* Details of "+objectName+" *********************");

                 Object attribute = platformMBeanServer.getAttribute(objectName, "scheme");

      ObjectName socketBindingObjName=new ObjectName("jboss.as:socket-binding-group=standard-sockets,socket-binding=http");

      System.out.println("      scheme     = "+attribute);

      System.out.println("      protocol     = "+platformMBeanServer.getAttribute(objectName, "protocol"));

      System.out.println("      redirectPort     = "+platformMBeanServer.getAttribute(objectName, "redirectPort"));

      System.out.println("      proxyPort     = "+platformMBeanServer.getAttribute(objectName, "proxyPort"));

      System.out.println("      port     = "+platformMBeanServer.getAttribute(socketBindingObjName, "port"));

       

      }

       

       

       

      public static void main(String[] args) throws Exception {

      String jbossHost="localhost";

      int jbossMgmtPort=9999;

      TestMbeans client=new TestMbeans(jbossHost,jbossMgmtPort);

      client.showSessionDetails();

      client.showSessionDetailsWithPlatformMbeanServer();

      client.jmxConnector.close();

      }

       

      }

       

      Output: client.showSessionDetails()

       

      - XNIO Version 3.0.7.GA-redhat-1

      - XNIO NIO Implementation Version 3.0.7.GA-redhat-1

      - JBoss Remoting version 3.2.16.GA-redhat-1

       

       

      ********************* Details of jboss.as:subsystem=web,connector=http *********************

             scheme     = http

             protocol     = HTTP/1.1

             redirectPort     = 443

             proxyPort     = null

             port     = 8080

       

       

       

       

      Output: client.showSessionDetailsWithPlatformMbeanServer()

      - XNIO Version 3.0.7.GA-redhat-1

      - XNIO NIO Implementation Version 3.0.7.GA-redhat-1

      - JBoss Remoting version 3.2.16.GA-redhat-1

      1. com.sun.jmx.mbeanserver.JmxMBeanServer@b6e39f

       

       

      ********************* Details of jboss.as:subsystem=web,connector=http *********************

      Exception in thread "main" javax.management.InstanceNotFoundException: jboss.as:subsystem=web,connector=http

             at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)

             at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)

             at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:639)

             at com.pega.pegarules.priv.management.TestMbeans.showSessionDetailsWithPlatformMbeanServer(TestMbeans.java:49)

             at com.pega.pegarules.priv.management.TestMbeans.main(TestMbeans.java:65)