static { try { mletName = new ObjectName("x:type=mlet"); } catch (Exception e) { e.printStackTrace(); throw new Error(); } }
public static void main(String[] args) throws Exception { System.out.println( "Test that target MBean class loader is used " + "before JMX Remote API class loader"); ClassLoader jmxRemoteClassLoader = JMXServiceURL.class.getClassLoader(); if (jmxRemoteClassLoader == null) { System.out.println( "JMX Remote API loaded by bootstrap " + "class loader, this test is irrelevant"); return; } if (!(jmxRemoteClassLoader instanceof URLClassLoader)) { System.out.println("TEST INVALID: JMX Remote API not loaded by " + "URLClassLoader"); System.exit(1); } URLClassLoader jrcl = (URLClassLoader) jmxRemoteClassLoader; URL[] urls = jrcl.getURLs(); PrivateMLet mlet = new PrivateMLet(urls, null, false); Class shadowClass = mlet.loadClass(JMXServiceURL.class.getName()); if (shadowClass == JMXServiceURL.class) { System.out.println("TEST INVALID: MLet got original " + "JMXServiceURL not shadow"); System.exit(1); } MBeanServer mbs = MBeanServerFactory.newMBeanServer(); mbs.registerMBean(mlet, mletName); final String[] protos = {"rmi", "iiop", "jmxmp"}; boolean ok = true; for (int i = 0; i < protos.length; i++) { try { ok &= test(protos[i], mbs); } catch (Exception e) { System.out.println("TEST FAILED WITH EXCEPTION:"); e.printStackTrace(System.out); ok = false; } } if (ok) System.out.println("Test passed"); else { System.out.println("TEST FAILED"); System.exit(1); } }