4 Replies Latest reply on Oct 12, 2011 10:03 AM by 848914

    How to access "Active Sessions" using MBeans

    848914
      Hi all,

      I have deployed an application at EM (Enterprise Manager).
      when I logged into EM and click the application I can see the number of active sessions under "Servlets and JSPs" topic.

      how can I access that parameter at application level..??
      (I want to access that parameter *"x"* at my web application and display Logged in users : x )

      EM shows that the number of active sessions. it updates too.. so there must be some bean or record for that parameter..
      how can I access that....??

      Regards,
      Dinuka.
        • 1. Re: How to access "Active Sessions" using MBeans
          René van Wijk
          You can use something like the following:
          package middleware.magic;
          
          import javax.management.MBeanServerConnection;
          import javax.management.ObjectName;
          import javax.management.remote.JMXConnector;
          import javax.management.remote.JMXConnectorFactory;
          import javax.management.remote.JMXServiceURL;
          import javax.naming.Context;
          import java.io.IOException;
          import java.util.Hashtable;
          
          public class Browse {
              private String hostname = "172.31.0.106";
              private Integer port = 7001;
              private String username = "weblogic";
              private String password = "transfer11g";
          
              private String protocol = "t3";
              private String jndiRoot = "/jndi/";
          
              private String mBeanServer = "weblogic.management.mbeanservers.domainruntime";
              private String serviceName = "com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean";
          
              private JMXConnector connector;
          
              public static void main(String[] args) {
                  Browse test = new Browse();
                  try {
                      MBeanServerConnection connection = test.getMBeanServerConnection();
                      test.getSomeInformation(connection);
                      test.closeJmxConnector();
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          
              public void getSomeInformation(MBeanServerConnection connection) throws Exception {
                  ObjectName service = new ObjectName(serviceName);
                  ObjectName[] serverRunTimes = (ObjectName[]) connection.getAttribute(service, "ServerRuntimes");
          
                  for (int i = 0; i < serverRunTimes.length; i++) {
                      String name = (String) connection.getAttribute(serverRunTimes, "Name");
          String version = (String) connection.getAttribute(serverRunTimes[i], "WeblogicVersion");
          String state = (String) connection.getAttribute(serverRunTimes[i], "State");
          System.out.println("Server name: " + name + ", Version: " + version + ", Server state: " + state);
          }

          for (int i = 0; i < serverRunTimes.length; i++) {
          ObjectName[] applicationRuntimes = (ObjectName[]) connection.getAttribute(serverRunTimes[i], "ApplicationRuntimes");
          for (int j = 0; j < applicationRuntimes.length; j++) {
          String name = (String) connection.getAttribute(applicationRuntimes[j], "Name");
          ObjectName[] componentRuntimes = (ObjectName[]) connection.getAttribute(applicationRuntimes[j], "ComponentRuntimes");
          System.out.println("Application name: " + name);
          for (int k = 0; k < componentRuntimes.length; k++) {
          if (connection.getAttribute(componentRuntimes[k], "Type").equals("WebAppComponentRuntime")) {
          String componentName = (String) connection.getAttribute(componentRuntimes[k], "Name");
          Integer sessionsCurrent = (Integer) connection.getAttribute(componentRuntimes[k], "OpenSessionsCurrentCount");
          Integer sessionsHigh = (Integer) connection.getAttribute(componentRuntimes[k], "OpenSessionsHighCount");
          System.out.println(" - Component Name: " + componentName + ", Sessions Current: " + sessionsCurrent + ", Sessions High: " + sessionsHigh);
          }
          }
          }
          }
          }

          public MBeanServerConnection getMBeanServerConnection() throws IOException {
          return getJmxConnector().getMBeanServerConnection();
          }

          public JMXConnector getJmxConnector() throws IOException {
          JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiRoot + mBeanServer);

          Hashtable hashtable = new Hashtable();
          hashtable.put(Context.SECURITY_PRINCIPAL, username);
          hashtable.put(Context.SECURITY_CREDENTIALS, password);
          hashtable.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote");

          connector = JMXConnectorFactory.connect(serviceURL, hashtable);
          return connector;
          }

          public void closeJmxConnector() throws IOException {
          connector.close();
          }
          }
          Information regarding runtimeMBean can be found here: http://download.oracle.com/docs/cd/E12839_01/apirefs.1111/e13951/core/index.html.
          Open the tree Runtime MBeans, ServerRuntimeMBean and click attributes to see the available attributes (such as Name, WeblogicVersion, State etcetera).
          
          An example output of the program above:
          Server name: AdminServer, Version: WebLogic Server 10.3.2.0 Tue Oct 20 12:16:15 PDT 2009 1267925 , Server state: RUNNING
          Server name: soa_server1, Version: WebLogic Server 10.3.2.0 Tue Oct 20 12:16:15 PDT 2009 1267925 , Server state: RUNNING
          Application name: FMW Welcome Page Application_11.1.0.0.0
          - Component Name: AdminServer__11.1.0.0.0, Sessions Current: 0, Sessions High: 0
          Application name: Module-FMWDFW
          Application name: bea_wls_internal
          - Component Name: AdminServer_/bea_wls_internal, Sessions Current: 0, Sessions High: 0
          Application name: mds-soa
          Application name: bea_wls_deployment_internal
          - Component Name: AdminServer_/bea_wls_deployment_internal, Sessions Current: 0, Sessions High: 0
          Application name: wsil-wls
          - Component Name: AdminServer_/inspection.wsil, Sessions Current: 0, Sessions High: 0
          Application name: bea_wls_diagnostics
          - Component Name: AdminServer_/bea_wls_diagnostics, Sessions Current: 0, Sessions High: 0
          Application name: mejb
          Application name: bea_wls9_async_response
          - Component Name: AdminServer_/_async, Sessions Current: 0, Sessions High: 0
          Application name: uddiexplorer
          - Component Name: AdminServer_/uddiexplorer, Sessions Current: 0, Sessions High: 0
          Application name: mds-owsm
          Application name: bea_wls_management_internal2
          - Component Name: AdminServer_/bea_wls_management_internal2, Sessions Current: 0, Sessions High: 0
          Application name: consoleapp
          - Component Name: AdminServer_/console, Sessions Current: 0, Sessions High: 2
          - Component Name: AdminServer_/consolehelp, Sessions Current: 0, Sessions High: 1
          Application name: DMS Application_11.1.1.1.0
          - Component Name: AdminServer_/dms_11.1.1.1.0, Sessions Current: 0, Sessions High: 0
          Application name: em
          - Component Name: AdminServer_/em, Sessions Current: 0, Sessions High: 0
          Application name: uddi
          - Component Name: AdminServer_/uddi, Sessions Current: 0, Sessions High: 0
          Application name: MQSeriesAdapter
          Application name: OraSDPMDataSource
          Application name: JmsAdapter
          Application name: uddi
          - Component Name: soa_server1_/uddi, Sessions Current: 0, Sessions High: 0
          Application name: wsil-wls
          - Component Name: soa_server1_/inspection.wsil, Sessions Current: 0, Sessions High: 0
          Application name: SOAJMSModule
          Application name: DbAdapter
          Application name: bea_wls9_async_response
          - Component Name: soa_server1_/_async, Sessions Current: 0, Sessions High: 0
          Application name: composer
          - Component Name: soa_server1_/soa/composer, Sessions Current: 0, Sessions High: 0
          Application name: DMS Application_11.1.1.1.0
          - Component Name: soa_server1_/dms_11.1.1.1.0, Sessions Current: 0, Sessions High: 0
          Application name: Module-FMWDFW
          Application name: usermessagingdriver-email
          - Component Name: soa_server1_/sdpmessagingdriver/email-mbeanlifecycle, Sessions Current: 0, Sessions High: 0
          Application name: UMSJMSSystemResource
          Application name: AqAdapter
          Application name: FtpAdapter
          Application name: OracleBamAdapter
          Application name: SOADataSource
          Application name: usermessagingserver
          - Component Name: soa_server1_/sdpmessaging/mbeanlifecycle, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/sdpmessaging/parlayx, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/sdpmessaging/userprefs-ui, Sessions Current: 0, Sessions High: 0
          Application name: bea_wls_internal
          - Component Name: soa_server1_/bea_wls_internal, Sessions Current: 0, Sessions High: 0
          Application name: SocketAdapter
          Application name: SOALocalTxDataSource
          Application name: FileAdapter
          Application name: DefaultToDoTaskFlow
          - Component Name: soa_server1_/DefaultToDoTaskFlow, Sessions Current: 0, Sessions High: 0
          Application name: soa-infra
          - Component Name: soa_server1_/soa-infra, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/TaskService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/TaskMetadataService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/TaskQueryService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/TaskReportService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/IdentityService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/UserMetadataService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/RuntimeConfigService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/TaskEvidenceService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/CompositeMetadataService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/b2b, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/b2b, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/AGMetadataService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/AGQueryService, Sessions Current: 0, Sessions High: 0
          - Component Name: soa_server1_/integration/services/AGAdminService, Sessions Current: 0, Sessions High: 0
          Application name: wsm-pm
          - Component Name: soa_server1_/wsm-pm, Sessions Current: 0, Sessions High: 0
          Application name: mds-owsm
          Application name: b2bui
          - Component Name: soa_server1_/b2bconsole, Sessions Current: 0, Sessions High: 0
          Application name: bea_wls_diagnostics
          - Component Name: soa_server1_/bea_wls_diagnostics, Sessions Current: 0, Sessions High: 0
          Application name: bea_wls_cluster_internal
          - Component Name: soa_server1_/bea_wls_cluster_internal, Sessions Current: 0, Sessions High: 0
          Application name: EDNLocalTxDataSource
          Application name: EDNDataSource
          Application name: uddiexplorer
          - Component Name: soa_server1_/uddiexplorer, Sessions Current: 0, Sessions High: 0
          Application name: bea_wls_deployment_internal
          - Component Name: soa_server1_/bea_wls_deployment_internal, Sessions Current: 0, Sessions High: 0
          Application name: worklistapp
          - Component Name: soa_server1_/integration/worklistapp, Sessions Current: 0, Sessions High: 0
          Application name: mds-soa
          Application name: OracleAppsAdapter
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
          • 2. Re: How to access "Active Sessions" using MBeans
            848914
            Hi Mr.René van Wijk,

            thanks a lot for your response.
            I got your code and changed username , password , hostname parameters..
            when I run the below code,
            connector = JMXConnectorFactory.connect(serviceURL, hashtable);
            following error occurs..
            java.io.IOException
                 at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:196)
                 at weblogic.management.remote.common.ClientProviderBase.newJMXConnector(ClientProviderBase.java:84)
                 at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:338)
                 at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:247)
                 at javascriptapp.view.beans.MyClass.getJmxConnector(MyClass.java:114)
                 at javascriptapp.view.beans.MyClass.getMBeanServerConnection(MyClass.java:100)
                 at javascriptapp.view.beans.MyClass.main(MyClass.java:40)
            Caused by: javax.naming.CommunicationException [Root exception is java.net.ConnectException: t3://172.25.xx.xxx:7001: Destination unreachable; nested exception is: 
                 java.net.ProtocolException: unrecognized response from proxy: 'HTTP/1.0 403 Forbidden'; No available router to destination]
                 at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:40)
                 at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:788)
                 at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:366)
                 at weblogic.jndi.Environment.getContext(Environment.java:315)
                 at weblogic.jndi.Environment.getContext(Environment.java:285)
                 at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117)
                 at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
                 at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
                 at javax.naming.InitialContext.init(InitialContext.java:223)
                 at javax.naming.InitialContext.<init>(InitialContext.java:197)
                 at weblogic.management.remote.common.ClientProviderBase.makeConnection(ClientProviderBase.java:178)
                 ... 6 more
            Caused by: java.net.ConnectException: t3://172.25.xx.xxx:7001: Destination unreachable; nested exception is: 
                 java.net.ProtocolException: unrecognized response from proxy: 'HTTP/1.0 403 Forbidden'; No available router to destination
                 at weblogic.rjvm.RJVMFinder.findOrCreateInternal(RJVMFinder.java:216)
                 at weblogic.rjvm.RJVMFinder.findOrCreate(RJVMFinder.java:170)
                 at weblogic.rjvm.ServerURL.findOrCreateRJVM(ServerURL.java:153)
                 at weblogic.jndi.WLInitialContextFactoryDelegate$1.run(WLInitialContextFactoryDelegate.java:345)
                 at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
                 at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
                 at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:340)
                 ... 14 more
            Caused by: java.rmi.ConnectException: Destination unreachable; nested exception is: 
                 java.net.ProtocolException: unrecognized response from proxy: 'HTTP/1.0 403 Forbidden'; No available router to destination
                 at weblogic.rjvm.ConnectionManager.bootstrap(ConnectionManager.java:470)
                 at weblogic.rjvm.ConnectionManager.bootstrap(ConnectionManager.java:321)
                 at weblogic.rjvm.RJVMManager.findOrCreateRemoteInternal(RJVMManager.java:254)
                 at weblogic.rjvm.RJVMManager.findOrCreate(RJVMManager.java:197)
                 at weblogic.rjvm.RJVMFinder.findOrCreateRemoteServer(RJVMFinder.java:238)
                 at weblogic.rjvm.RJVMFinder.findOrCreateInternal(RJVMFinder.java:200)
                 ... 20 more
            Process exited with exit code 0.
            Do you have any idea about this error Mr.René van Wijk...?

            Thanks a lot for your reply.
            Dinuka.
            • 3. Re: How to access "Active Sessions" using MBeans
              John Stegeman
              Looks like you're using a proxy in between your machine and the WLS.
              1 person found this helpful
              • 4. Re: How to access "Active Sessions" using MBeans
                848914
                Hi Mr.John,

                Thanks a lot.... That is the issue...
                I removed the proxy at JDeveloper (Tools --> Preferences --> Web Browser and Proxy)
                Now it is working well...
                Thanks a lot. :D
                Dinuka.