Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-25937

[GSS](7.4.z) Thread's context classloader for ServiceMBeanSupport startService is not application module

XMLWordPrintable

    • False
    • None
    • False
    • ?
    • Hide

      workaround#1(recommended): call ManagementFactory.getPlatformMBeanServer() instead of Remote JMX to access local MBean server on JBoss EAP 7

      MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
      ObjectName objectName = ObjectName.getInstance("jboss.as:management-root=server");
      String attributeName = "serverState";
      Object result = mBeanServer.getAttribute(objectName, attributeName);
      System.out.println("serverState = " + result);
      

      workaround#2: override thread'scontext classloader from org.jboss.as.sar to deployment.<deployment-name>.sar, then add jboss-deployment-structure.xml

      ClassLoader old = Thread.currentThread().getContextClassLoader();
      try {
          Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
          JMXServiceURL serviceURL = new JMXServiceURL(JMX_URL);
          try (JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null)) {
              MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
              ObjectName objectName = ObjectName.getInstance("jboss.as:management-root=server");
              String attributeName = "serverState";
              Object result = connection.getAttribute(objectName, attributeName);
              System.out.println("serverState = " + result);
      }
      } finally {
          Thread.currentThread().setContextClassLoader(old);
      }
      

      META-INF/jboss-deployment-structure.xml

      <?xml version='1.0' encoding='UTF-8'?>
      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
          <deployment>
              <dependencies>
                  <module name="org.jboss.remoting-jmx" services="import"/>
              </dependencies>
          </deployment>
      </jboss-deployment-structure>
      
      Show
      workaround#1(recommended): call ManagementFactory.getPlatformMBeanServer() instead of Remote JMX to access local MBean server on JBoss EAP 7 MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); ObjectName objectName = ObjectName.getInstance( "jboss.as:management-root=server" ); String attributeName = "serverState" ; Object result = mBeanServer.getAttribute(objectName, attributeName); System .out.println( "serverState = " + result); workaround#2: override thread'scontext classloader from org.jboss.as.sar to deployment.<deployment-name>.sar, then add jboss-deployment-structure.xml ClassLoader old = Thread .currentThread().getContextClassLoader(); try { Thread .currentThread().setContextClassLoader( this .getClass().getClassLoader()); JMXServiceURL serviceURL = new JMXServiceURL(JMX_URL); try (JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null )) { MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); ObjectName objectName = ObjectName.getInstance( "jboss.as:management-root=server" ); String attributeName = "serverState" ; Object result = connection.getAttribute(objectName, attributeName); System .out.println( "serverState = " + result); } } finally { Thread .currentThread().setContextClassLoader(old); } META-INF/jboss-deployment-structure.xml <?xml version= '1.0' encoding= 'UTF-8' ?> <jboss-deployment-structure xmlns= "urn:jboss:deployment-structure:1.3" > <deployment> <dependencies> <module name= "org.jboss.remoting-jmx" services= " import " /> </dependencies> </deployment> </jboss-deployment-structure>
    • Hide

      Start JBoss EAP 7.4.13 and deploy the attached SampleMBean.sar. We can see MalformedURLException as the following. On JBoss EAP 7.2.9 and earlier, MalformedURLException is not thrown.

      16:12:11,980 WARN  [org.jboss.example.mbean.support.ConfigService] (MSC service thread 1-4) WFLYSYSJMX0006: Starting failed jboss.support:name=ConfigBean: java.net.MalformedURLException: Unsupported protocol: remote+http
      	at java.management/javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:366)
      	at java.management/javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:269)
      	at deployment.SampleMBean.sar//org.jboss.example.mbean.support.ConfigService.startService(ConfigService.java:22)
      	at org.jboss.as.system-jmx@7.4.13.GA-redhat-00001//org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:255)
              ... 
      
      Show
      Start JBoss EAP 7.4.13 and deploy the attached SampleMBean.sar. We can see MalformedURLException as the following. On JBoss EAP 7.2.9 and earlier, MalformedURLException is not thrown. 16:12:11,980 WARN [org.jboss.example.mbean.support.ConfigService] (MSC service thread 1-4) WFLYSYSJMX0006: Starting failed jboss.support:name=ConfigBean: java.net.MalformedURLException: Unsupported protocol: remote+http at java.management/javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:366) at java.management/javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:269) at deployment.SampleMBean.sar//org.jboss.example.mbean.support.ConfigService.startService(ConfigService.java:22) at org.jboss.as.system-jmx@7.4.13.GA-redhat-00001//org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:255) ...

      Thread's context classloader while running ServiceMBeanSupport.startService() is org.jboss.as.sar, not "deployment.*.sar". In sar deployments with POJO classes and ejb-jar deployments, the thread context classloader is set to "deployment.<archive-name>", but while in ServiceMBeanSupport it is set to "org.jboss.as.sar".

      This is usually not a problem, however, if a custom MBean with ServiceMBeanSupport contains remote JMX call, sar deployment succeeds up to EAP 7.2.9, but fails with the following error from EAP 7.3.0 or later:

      16:12:11,980 WARN  [org.jboss.example.mbean.support.ConfigService] (MSC service thread 1-4) WFLYSYSJMX0006: Starting failed jboss.support:name=ConfigBean: java.net.MalformedURLException: Unsupported protocol: remote+http
      	at java.management/javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:366)
      	at java.management/javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:269)
      	at deployment.SampleMBean.sar//org.jboss.example.mbean.support.ConfigService.startService(ConfigService.java:22)
      	at org.jboss.as.system-jmx@7.4.13.GA-redhat-00001//org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:255)
              ...
      

      This could be a backward compatibility issue between 7.2.9 and 7.3.0, also reproduceed in the latest EAP 7.4.13.

      The implementation of sar deployment has been moved from org.jboss.as.jmx to org.jboss.as.sar module by WFCORE-4179 and WFLY-11239 fixed in JBoss EAP 7.3.0. As of JBoss EAP 7.2.9 and earlier, the thread context classloader for ServiceMBeanSupport is org.jboss.as.jmx, not application deployment module. But org.jboss.as.jmx module had a dependency on org.jboss.remoting-jmx. As a consequence, prior to JBoss EAP 7.2.9, remote JMX calls are available from custom MBeans with ServiceMBeanSupport.

      jboss-eap-7.2/modules/system/layers/base/.overlays/layer-base-jboss-eap-7.2.9.CP/org/jboss/as/jmx/main/module.xml

      <module name="org.jboss.as.jmx" xmlns="urn:jboss:module:1.8">
      ...
          <dependencies>
      ...
              <module name="org.jboss.msc"/>
              <module name="org.jboss.logging"/>
              <module name="org.jboss.remoting-jmx" services="import" optional="true"/>   <<<===
          </dependencies>
      </module>
      

              rhn-engineering-lgao Lin Gao
              rhn-support-nagetsum Norito Agetsuma
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: