diff --git a/jdk/src/share/classes/com/sun/jmx/remote/internal/IIOPHelper.java b/jdk/src/share/classes/com/sun/jmx/remote/internal/IIOPHelper.java index b598a9c4f3b..eabe73962c2 100644 --- a/jdk/src/share/classes/com/sun/jmx/remote/internal/IIOPHelper.java +++ b/jdk/src/share/classes/com/sun/jmx/remote/internal/IIOPHelper.java @@ -26,13 +26,8 @@ package com.sun.jmx.remote.internal; import java.util.Properties; +import java.io.IOException; import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.NoSuchObjectException; - -import java.util.Properties; -import java.rmi.Remote; -import java.rmi.RemoteException; import java.rmi.NoSuchObjectException; import java.security.AccessController; @@ -115,9 +110,10 @@ public final class IIOPHelper { * Connects the Stub to the given ORB. */ public static void connect(Object stub, Object orb) - throws RemoteException + throws IOException { - ensureAvailable(); + if (proxy == null) + throw new IOException("Connection to ORB failed, RMI/IIOP not available"); proxy.connect(stub, orb); } @@ -125,15 +121,17 @@ public final class IIOPHelper { * Returns true if the given object is an ORB. */ public static boolean isOrb(Object obj) { - ensureAvailable(); - return proxy.isOrb(obj); + return (proxy == null) ? false : proxy.isOrb(obj); } /** * Creates, and returns, a new ORB instance. */ - public static Object createOrb(String[] args, Properties props) { - ensureAvailable(); + public static Object createOrb(String[] args, Properties props) + throws IOException + { + if (proxy == null) + throw new IOException("ORB initialization failed, RMI/IIOP not available"); return proxy.createOrb(args, props); } @@ -166,24 +164,27 @@ public final class IIOPHelper { /** * Makes a server object ready to receive remote calls */ - public static void exportObject(Remote obj) throws RemoteException { - ensureAvailable(); + public static void exportObject(Remote obj) throws IOException { + if (proxy == null) + throw new IOException("RMI object cannot be exported, RMI/IIOP not available"); proxy.exportObject(obj); } /** * Deregisters a server object from the runtime. */ - public static void unexportObject(Remote obj) throws NoSuchObjectException { - ensureAvailable(); + public static void unexportObject(Remote obj) throws IOException { + if (proxy == null) + throw new NoSuchObjectException("Object not exported"); proxy.unexportObject(obj); } /** * Returns a stub for the given server object. */ - public static Remote toStub(Remote obj) throws NoSuchObjectException { - ensureAvailable(); + public static Remote toStub(Remote obj) throws IOException { + if (proxy == null) + throw new NoSuchObjectException("Object not exported"); return proxy.toStub(obj); } } diff --git a/jdk/src/share/classes/javax/management/remote/JMXConnectorFactory.java b/jdk/src/share/classes/javax/management/remote/JMXConnectorFactory.java index 02a32e745f2..3cea5d44879 100644 --- a/jdk/src/share/classes/javax/management/remote/JMXConnectorFactory.java +++ b/jdk/src/share/classes/javax/management/remote/JMXConnectorFactory.java @@ -137,8 +137,10 @@ import com.sun.jmx.remote.util.EnvHelp; * JAR conventions for service providers, where the service * interface is JMXConnectorProvider.

* - *

Every implementation must support the RMI connector protocols, - * specified with the string rmi or + *

Every implementation must support the RMI connector protocol with + * the default RMI transport, specified with string rmi. + * An implementation may optionally support the RMI connector protocol + * with the RMI/IIOP transport, specified with the string * iiop.

* *

Once a provider is found, the result of the diff --git a/jdk/src/share/classes/javax/management/remote/JMXConnectorServerFactory.java b/jdk/src/share/classes/javax/management/remote/JMXConnectorServerFactory.java index 658369c56c8..8ad3a94123c 100644 --- a/jdk/src/share/classes/javax/management/remote/JMXConnectorServerFactory.java +++ b/jdk/src/share/classes/javax/management/remote/JMXConnectorServerFactory.java @@ -129,8 +129,10 @@ import javax.management.MBeanServer; * JAR conventions for service providers, where the service * interface is JMXConnectorServerProvider.

* - *

Every implementation must support the RMI connector protocols, - * specified with the string rmi or + *

Every implementation must support the RMI connector protocol with + * the default RMI transport, specified with string rmi. + * An implementation may optionally support the RMI connector protocol + * with the RMI/IIOP transport, specified with the string * iiop.

* *

Once a provider is found, the result of the diff --git a/jdk/src/share/classes/javax/management/remote/rmi/RMIConnector.java b/jdk/src/share/classes/javax/management/remote/rmi/RMIConnector.java index 1dda90571bd..b3a4558d4b2 100644 --- a/jdk/src/share/classes/javax/management/remote/rmi/RMIConnector.java +++ b/jdk/src/share/classes/javax/management/remote/rmi/RMIConnector.java @@ -238,10 +238,21 @@ public class RMIConnector implements JMXConnector, Serializable, JMXAddressable //-------------------------------------------------------------------- // implements JMXConnector interface //-------------------------------------------------------------------- + + /** + * @throws IOException if the connection could not be made because of a + * communication problem, or in the case of the {@code iiop} protocol, + * that RMI/IIOP is not supported + */ public void connect() throws IOException { connect(null); } + /** + * @throws IOException if the connection could not be made because of a + * communication problem, or in the case of the {@code iiop} protocol, + * that RMI/IIOP is not supported + */ public synchronized void connect(Map environment) throws IOException { final boolean tracing = logger.traceOn(); diff --git a/jdk/src/share/classes/javax/management/remote/rmi/RMIConnectorServer.java b/jdk/src/share/classes/javax/management/remote/rmi/RMIConnectorServer.java index 923ea9a8d67..faa949cca38 100644 --- a/jdk/src/share/classes/javax/management/remote/rmi/RMIConnectorServer.java +++ b/jdk/src/share/classes/javax/management/remote/rmi/RMIConnectorServer.java @@ -337,7 +337,8 @@ public class RMIConnectorServer extends JMXConnectorServer { * @exception IllegalStateException if the connector server has * not been attached to an MBean server. * @exception IOException if the connector server cannot be - * started. + * started, or in the case of the {@code iiop} protocol, that + * RMI/IIOP is not supported. */ public synchronized void start() throws IOException { final boolean tracing = logger.traceOn(); diff --git a/jdk/src/share/classes/javax/management/remote/rmi/package.html b/jdk/src/share/classes/javax/management/remote/rmi/package.html index a0a1725ac32..8492a05bebf 100644 --- a/jdk/src/share/classes/javax/management/remote/rmi/package.html +++ b/jdk/src/share/classes/javax/management/remote/rmi/package.html @@ -36,8 +36,8 @@ questions. that different implementations of the RMI connector can interoperate.

-

The RMI connector supports both the JRMP and the IIOP transports - for RMI.

+

The RMI connector supports the JRMP transport for RMI, and + optionally the IIOP transport.

Like most connectors in the JMX Remote API, an RMI connector usually has an address, which diff --git a/jdk/test/javax/management/remote/mandatory/connection/AddressableTest.java b/jdk/test/javax/management/remote/mandatory/connection/AddressableTest.java index dce8bb1d0c8..049fef08497 100644 --- a/jdk/test/javax/management/remote/mandatory/connection/AddressableTest.java +++ b/jdk/test/javax/management/remote/mandatory/connection/AddressableTest.java @@ -45,19 +45,36 @@ public class AddressableTest { private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer(); + private static boolean isProtocolSupported(String protocol) { + if (protocol.equals("rmi")) + return true; + if (protocol.equals("iiop")) { + try { + Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie"); + return true; + } catch (ClassNotFoundException x) { } + } + return false; + } + public static void main(String[] args) throws Exception { System.out.println(">>> test the new interface Addressable."); boolean ok = true; for (int i = 0; i < protocols.length; i++) { - try { - test(protocols[i], prefixes[i]); - - System.out.println(">>> Test successed for "+protocols[i]); - } catch (Exception e) { - System.out.println(">>> Test failed for "+protocols[i]); - e.printStackTrace(System.out); - ok = false; + String protocol = protocols[i]; + if (isProtocolSupported(protocol)) { + try { + test(protocol, prefixes[i]); + System.out.println(">>> Test successed for "+protocols[i]); + } catch (Exception e) { + System.out.println(">>> Test failed for "+protocols[i]); + e.printStackTrace(System.out); + ok = false; + } + } else { + System.out.format(">>> Test skipped for %s, protocol not supported%n", + protocol); } } @@ -65,7 +82,7 @@ public class AddressableTest { System.out.println(">>> All Test passed."); } else { System.out.println(">>> Some TESTs FAILED"); - System.exit(1); + throw new RuntimeException("See log for details"); } } diff --git a/jdk/test/javax/management/remote/mandatory/connection/CloseableTest.java b/jdk/test/javax/management/remote/mandatory/connection/CloseableTest.java index 93d1b92e8ca..00451da7e81 100644 --- a/jdk/test/javax/management/remote/mandatory/connection/CloseableTest.java +++ b/jdk/test/javax/management/remote/mandatory/connection/CloseableTest.java @@ -42,7 +42,6 @@ import javax.management.remote.rmi.RMIConnector; import javax.management.remote.rmi.RMIIIOPServerImpl; import javax.management.remote.rmi.RMIJRMPServerImpl; import javax.management.remote.rmi.RMIServerImpl; -import org.omg.stub.javax.management.remote.rmi._RMIConnection_Stub; public class CloseableTest { private static final Class closeArray[] = { @@ -51,26 +50,43 @@ public class CloseableTest { RMIConnection.class, RMIConnectionImpl.class, RMIConnectionImpl_Stub.class, - _RMIConnection_Stub.class, RMIServerImpl.class, RMIIIOPServerImpl.class, RMIJRMPServerImpl.class }; + + static int error; + + static void test(Class c) { + System.out.println("\nTest " + c); + if (Closeable.class.isAssignableFrom(c)) { + System.out.println("Test passed!"); + } else { + error++; + System.out.println("Test failed!"); + } + } + + static void test(String cn) { + try { + test(Class.forName(cn)); + } catch (ClassNotFoundException ignore) { + System.out.println("\n" + cn + " not tested."); + } + } + public static void main(String[] args) throws Exception { System.out.println("Test that all the JMX Remote API classes that " + "define\nthe method \"void close() throws " + "IOException;\" extend\nor implement the " + "java.io.Closeable interface."); - int error = 0; - for (Class c : closeArray) { - System.out.println("\nTest " + c); - if (Closeable.class.isAssignableFrom(c)) { - System.out.println("Test passed!"); - } else { - error++; - System.out.println("Test failed!"); - } + for (Class c : closeArray) { + test(c); } + + // Stub classes not present if RMI-IIOP not supported + test("org.omg.stub.javax.management.remote.rmi._RMIConnection_Stub"); + if (error > 0) { final String msg = "\nTest FAILED! Got " + error + " error(s)"; System.out.println(msg); diff --git a/jdk/test/javax/management/remote/mandatory/connection/ConnectionListenerNullTest.java b/jdk/test/javax/management/remote/mandatory/connection/ConnectionListenerNullTest.java index c7b0208c2a3..62027b4f844 100644 --- a/jdk/test/javax/management/remote/mandatory/connection/ConnectionListenerNullTest.java +++ b/jdk/test/javax/management/remote/mandatory/connection/ConnectionListenerNullTest.java @@ -39,33 +39,22 @@ import javax.management.NotificationListener; import java.util.Map; public class ConnectionListenerNullTest { - static final boolean optionalFlag; - static { - Class genericClass = null; + static boolean isPresent(String cn) { try { - genericClass = - Class.forName("javax.management.remote.generic.GenericConnector"); + Class.forName(cn); + return true; } catch (ClassNotFoundException x) { - // NO optional package + return false; } - optionalFlag = (genericClass != null); } - final static String[] mandatoryList = { - "service:jmx:rmi://", "service:jmx:iiop://" - }; - - final static String[] optionalList = { - "service:jmx:jmxmp://" - }; - - public static int test(String[] urls) { + public static int test(String... urls) { int errCount = 0; for (int i=0;i)null); final NotificationListener nl = null; final NotificationFilter nf = null; final Object h = null; @@ -121,12 +110,19 @@ public class ConnectionListenerNullTest { public static void main(String args[]) { int errCount = 0; - errCount += test(mandatoryList); - if (optionalFlag) errCount += test(optionalList); + + // mandatory + errCount += test("service:jmx:rmi://"); + + // optional + if (isPresent("javax.management.remote.rmi._RMIConnectionImpl_Tie")) + errCount += test("service:jmx:iiop://"); + if (isPresent("javax.management.remote.generic.GenericConnector")) + errCount += test("service:jmx:jmxmp://"); + if (errCount > 0) { - System.err.println("ConnectionListenerNullTest failed: " + - errCount + " error(s) reported."); - System.exit(1); + throw new RuntimeException("ConnectionListenerNullTest failed: " + + errCount + " error(s) reported."); } System.out.println("ConnectionListenerNullTest passed."); } diff --git a/jdk/test/javax/management/remote/mandatory/connection/IIOPURLTest.java b/jdk/test/javax/management/remote/mandatory/connection/IIOPURLTest.java index 0899a0c2709..bca8396e11c 100644 --- a/jdk/test/javax/management/remote/mandatory/connection/IIOPURLTest.java +++ b/jdk/test/javax/management/remote/mandatory/connection/IIOPURLTest.java @@ -49,17 +49,24 @@ public class IIOPURLTest { public static void main(String[] args) throws Exception { JMXServiceURL inputAddr = new JMXServiceURL("service:jmx:iiop://"); - JMXConnectorServer s = - JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, - null); + JMXConnectorServer s; + try { + s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null); + } catch (java.net.MalformedURLException x) { + try { + Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie"); + throw new RuntimeException("MalformedURLException thrown but iiop appears to be supported"); + } catch (ClassNotFoundException expected) { } + System.out.println("IIOP protocol not supported, test skipped"); + return; + } MBeanServer mbs = MBeanServerFactory.createMBeanServer(); mbs.registerMBean(s, new ObjectName("a:b=c")); s.start(); JMXServiceURL outputAddr = s.getAddress(); if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) { - System.out.println("URL path should start with \"/ior/IOR:\": " + - outputAddr); - System.exit(1); + throw new RuntimeException("URL path should start with \"/ior/IOR:\": " + + outputAddr); } System.out.println("IIOP URL path looks OK: " + outputAddr); JMXConnector c = JMXConnectorFactory.connect(outputAddr); diff --git a/jdk/test/javax/management/remote/mandatory/connection/IdleTimeoutTest.java b/jdk/test/javax/management/remote/mandatory/connection/IdleTimeoutTest.java index b6599f5f7ac..854a211a7b0 100644 --- a/jdk/test/javax/management/remote/mandatory/connection/IdleTimeoutTest.java +++ b/jdk/test/javax/management/remote/mandatory/connection/IdleTimeoutTest.java @@ -52,21 +52,27 @@ import javax.management.remote.JMXServiceURL; import com.sun.jmx.remote.util.EnvHelp; public class IdleTimeoutTest { + + static boolean isPresent(String cn) { + try { + Class.forName(cn); + return true; + } catch (ClassNotFoundException x) { + return false; + } + } + public static void main(String[] args) throws Exception { boolean ok = true; List protos; if (args.length > 0) protos = Arrays.asList(args); else { - protos = - new ArrayList(Arrays.asList(new String[] {"rmi", "iiop"})); - try { - Class.forName("javax.management.remote.jmxmp." + - "JMXMPConnectorServer"); + protos = new ArrayList(Arrays.asList(new String[] {"rmi"})); + if (isPresent("javax.management.remote.rmi._RMIConnectionImpl_Tie")) + protos.add("iiop"); + if (isPresent("javax.management.remote.jmxmp.JMXMPConnectorServer")) protos.add("jmxmp"); - } catch (ClassNotFoundException e) { - // OK: Optional JMXMP support is not present - } } for (Iterator it = protos.iterator(); it.hasNext(); ) { String proto = (String) it.next(); @@ -81,13 +87,13 @@ public class IdleTimeoutTest { } } if (!ok) { - System.out.println("SOME TESTS FAILED"); - System.exit(1); + throw new RuntimeException("Some tests failed - see log for details"); } } private static long getIdleTimeout(MBeanServer mbs, JMXServiceURL url) - throws Exception { + throws Exception + { JMXConnectorServer server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); server.start(); diff --git a/jdk/test/javax/management/remote/mandatory/connection/MultiThreadDeadLockTest.java b/jdk/test/javax/management/remote/mandatory/connection/MultiThreadDeadLockTest.java index 0204afb1665..5f1584c032d 100644 --- a/jdk/test/javax/management/remote/mandatory/connection/MultiThreadDeadLockTest.java +++ b/jdk/test/javax/management/remote/mandatory/connection/MultiThreadDeadLockTest.java @@ -253,4 +253,3 @@ public class MultiThreadDeadLockTest { System.out.println("===Leave the method: " + m); } } - diff --git a/jdk/test/javax/management/remote/mandatory/connectorServer/SetMBeanServerForwarder.java b/jdk/test/javax/management/remote/mandatory/connectorServer/SetMBeanServerForwarder.java index 9f8779f1314..5075f392f34 100644 --- a/jdk/test/javax/management/remote/mandatory/connectorServer/SetMBeanServerForwarder.java +++ b/jdk/test/javax/management/remote/mandatory/connectorServer/SetMBeanServerForwarder.java @@ -40,27 +40,16 @@ import com.sun.jmx.remote.security.MBeanServerAccessController; public class SetMBeanServerForwarder { - static final boolean optionalFlag; - static { - Class genericClass = null; + static boolean isPresent(String cn) { try { - genericClass = - Class.forName("javax.management.remote.generic.GenericConnector"); + Class.forName(cn); + return true; } catch (ClassNotFoundException x) { - // NO optional package + return false; } - optionalFlag = (genericClass != null); } - final static String[] mandatoryList = { - "service:jmx:rmi://", "service:jmx:iiop://" - }; - - final static String[] optionalList = { - "service:jmx:jmxmp://" - }; - - public static int test(String[] urls) { + public static int test(String... urls) { int errorCount = 0; for (int i=0;i 0) { - System.err.println("SetMBeanServerForwarder failed: " + - errCount + " error(s) reported."); - System.exit(1); + throw new RuntimeException("SetMBeanServerForwarder failed: " + + errCount + " error(s) reported."); } System.out.println("SetMBeanServerForwarder passed."); } diff --git a/jdk/test/javax/management/remote/mandatory/loading/MissingClassTest.java b/jdk/test/javax/management/remote/mandatory/loading/MissingClassTest.java index b120c8654f7..e70d0adfe6e 100644 --- a/jdk/test/javax/management/remote/mandatory/loading/MissingClassTest.java +++ b/jdk/test/javax/management/remote/mandatory/loading/MissingClassTest.java @@ -70,7 +70,6 @@ import javax.management.remote.JMXConnectorServer; import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXServiceURL; import javax.management.remote.rmi.RMIConnectorServer; -import org.omg.CORBA.MARSHAL; public class MissingClassTest { private static final int NNOTIFS = 50; @@ -84,6 +83,15 @@ public class MissingClassTest { private static final Object unserializableObject = Thread.currentThread(); + private static boolean isInstance(Object o, String cn) { + try { + Class c = Class.forName(cn); + return c.isInstance(o); + } catch (ClassNotFoundException x) { + return false; + } + } + public static void main(String[] args) throws Exception { System.out.println("Test that the client or server end of a " + "connection does not fail if sent an object " + @@ -118,8 +126,7 @@ public class MissingClassTest { if (ok) System.out.println("Test passed"); else { - System.out.println("TEST FAILED"); - System.exit(1); + throw new RuntimeException("TEST FAILED"); } } @@ -133,7 +140,7 @@ public class MissingClassTest { JMXConnectorServer cs; JMXServiceURL url = new JMXServiceURL(proto, null, 0); - Map serverMap = new HashMap(); + Map serverMap = new HashMap<>(); serverMap.put(JMXConnectorServerFactory.DEFAULT_CLASS_LOADER, serverLoader); @@ -151,7 +158,7 @@ public class MissingClassTest { } cs.start(); JMXServiceURL addr = cs.getAddress(); - Map clientMap = new HashMap(); + Map clientMap = new HashMap<>(); clientMap.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER, clientLoader); @@ -174,7 +181,7 @@ public class MissingClassTest { ok = false; } catch (IOException e) { Throwable cause = e.getCause(); - if (cause instanceof MARSHAL) // see CR 4935098 + if (isInstance(cause, "org.omg.CORBA.MARSHAL")) // see CR 4935098 cause = cause.getCause(); if (cause instanceof ClassNotFoundException) { System.out.println("Success: got an IOException wrapping " + @@ -188,7 +195,7 @@ public class MissingClassTest { } System.out.println("Doing queryNames to ensure connection alive"); - Set names = mbsc.queryNames(null, null); + Set names = mbsc.queryNames(null, null); System.out.println("queryNames returned " + names); System.out.println("Provoke exception of unknown class"); @@ -198,7 +205,7 @@ public class MissingClassTest { ok = false; } catch (IOException e) { Throwable wrapped = e.getCause(); - if (wrapped instanceof MARSHAL) // see CR 4935098 + if (isInstance(wrapped, "org.omg.CORBA.MARSHAL")) // see CR 4935098 wrapped = wrapped.getCause(); if (wrapped instanceof ClassNotFoundException) { System.out.println("Success: got an IOException wrapping " + @@ -251,7 +258,7 @@ public class MissingClassTest { ok = false; } catch (IOException e) { Throwable cause = e.getCause(); - if (cause instanceof MARSHAL) // see CR 4935098 + if (isInstance(cause, "org.omg.CORBA.MARSHAL")) // see CR 4935098 cause = cause.getCause(); if (cause instanceof ClassNotFoundException) { System.out.println("Success: got an IOException " + @@ -584,15 +591,13 @@ public class MissingClassTest { try { new ObjectOutputStream(new ByteArrayOutputStream()) .writeObject(tricky); - System.out.println("TEST INCORRECT: tricky notif is " + - "serializable"); - System.exit(1); + throw new RuntimeException("TEST INCORRECT: tricky notif is " + + "serializable"); } catch (NotSerializableException e) { // OK: tricky notif is not serializable } catch (IOException e) { - System.out.println("TEST INCORRECT: tricky notif " + - "serialization check failed"); - System.exit(1); + throw new RuntimeException("TEST INCORRECT: tricky notif " + + "serialization check failed"); } /* Now shuffle an imaginary deck of cards where K, U, T, and @@ -629,12 +634,11 @@ public class MissingClassTest { } if (knownCount != 0 || unknownCount != 0 || trickyCount != 0 || boringCount != 0) { - System.out.println("TEST INCORRECT: Shuffle failed: " + + throw new RuntimeException("TEST INCORRECT: Shuffle failed: " + "known=" + knownCount +" unknown=" + unknownCount + " tricky=" + trickyCount + " boring=" + boringCount + " deal=" + notifList); - System.exit(1); } String notifs = notifList.toString(); System.out.println("Shuffle: " + notifs); @@ -646,10 +650,8 @@ public class MissingClassTest { case 't': n = tricky; break; case 'b': n = boring; break; default: - System.out.println("TEST INCORRECT: Bad shuffle char: " + - notifs.charAt(i)); - System.exit(1); - throw new Error(); + throw new RuntimeException("TEST INCORRECT: Bad shuffle char: " + + notifs.charAt(i)); } sendNotification(n); } diff --git a/jdk/test/javax/management/remote/mandatory/provider/ProviderTest.java b/jdk/test/javax/management/remote/mandatory/provider/ProviderTest.java index cfb3a2988b0..9c7c9f4eea4 100644 --- a/jdk/test/javax/management/remote/mandatory/provider/ProviderTest.java +++ b/jdk/test/javax/management/remote/mandatory/provider/ProviderTest.java @@ -49,13 +49,13 @@ import javax.management.MBeanServer; import provider.JMXConnectorProviderImpl; import provider.JMXConnectorServerProviderImpl; public class ProviderTest { + public static void main(String[] args) throws Exception { System.out.println("Starting ProviderTest"); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); - //First do the test with a protocol handled by Service providers - JMXServiceURL url = - new JMXServiceURL("service:jmx:rmi://"); + // First do the test with a protocol handled by Service providers + JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); dotest(url, mbs); boolean clientCalled = provider.JMXConnectorProviderImpl.called(); @@ -66,16 +66,22 @@ public class ProviderTest { System.out.println("Client provider not called"); if (!serverCalled) System.out.println("Server provider not called"); - System.out.println("Test Failed"); - System.exit(1); + throw new RuntimeException("Test failed - see log for details"); } - //The Service Provider doesn't handle IIOP. Default providers MUST - //be called. - url = - new JMXServiceURL("service:jmx:iiop://"); - - dotest(url, mbs); + // The Service Provider doesn't handle IIOP. Default providers MUST + // be called, which may or may not support IIOP. + url = new JMXServiceURL("service:jmx:iiop://"); + try { + dotest(url, mbs); + } catch (MalformedURLException e) { + try { + Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie"); + e.printStackTrace(System.out); + throw new RuntimeException("MalformedURLException throw but IIOP appears to be supported"); + } catch (ClassNotFoundException expected) { } + System.out.println("MalformedURLException thrown, IIOP transport not supported"); + } // Unsupported protocol. JMXConnectorServer server = null; @@ -87,31 +93,19 @@ public class ProviderTest { JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); - System.out.println("Exception not thrown."); - System.exit(1); - }catch(MalformedURLException e) { + throw new RuntimeException("Exception not thrown."); + } catch (MalformedURLException e) { System.out.println("Expected MalformedURLException thrown."); } - catch(Exception e) { - e.printStackTrace(); - System.out.println("Exception thrown : " + e); - System.exit(1); - } try { client = JMXConnectorFactory.newJMXConnector(url, null); - System.out.println("Exception not thrown."); - System.exit(1); - }catch(MalformedURLException e) { + throw new RuntimeException("Exception not thrown."); + } catch (MalformedURLException e) { System.out.println("Expected MalformedURLException thrown."); } - catch(Exception e) { - e.printStackTrace(); - System.out.println("Exception thrown : " + e); - System.exit(1); - } //JMXConnectorProviderException url = @@ -121,60 +115,34 @@ public class ProviderTest { JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); - System.out.println("Exception not thrown."); - System.exit(1); - }catch(JMXProviderException e) { + throw new RuntimeException("Exception not thrown."); + } catch(JMXProviderException e) { System.out.println("Expected JMXProviderException thrown."); } - catch(Exception e) { - e.printStackTrace(); - System.out.println("Exception thrown : " + e); - System.exit(1); - } try { client = JMXConnectorFactory.newJMXConnector(url, null); - System.out.println("Exception not thrown."); - System.exit(1); + throw new RuntimeException("Exception not thrown."); }catch(JMXProviderException e) { System.out.println("Expected JMXProviderException thrown."); } - catch(Exception e) { - e.printStackTrace(); - System.out.println("Exception thrown : " + e); - System.exit(1); - } System.out.println("Test OK"); - return; } private static void dotest(JMXServiceURL url, MBeanServer mbs) throws Exception { JMXConnectorServer server = null; JMXConnector client = null; - try { - server = - JMXConnectorServerFactory.newJMXConnectorServer(url, - null, - mbs); - }catch(IllegalArgumentException e) { - e.printStackTrace(); - System.exit(1); - } + + server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); server.start(); JMXServiceURL outputAddr = server.getAddress(); System.out.println("Server started ["+ outputAddr+ "]"); - try { - client = - JMXConnectorFactory.newJMXConnector(outputAddr, null); - }catch(IllegalArgumentException e) { - e.printStackTrace(); - System.exit(1); - } + client = JMXConnectorFactory.newJMXConnector(outputAddr, null); client.connect(); System.out.println("Client connected"); diff --git a/jdk/test/javax/management/remote/mandatory/serverError/JMXServerErrorTest.java b/jdk/test/javax/management/remote/mandatory/serverError/JMXServerErrorTest.java index 821f27f2537..c99361269b0 100644 --- a/jdk/test/javax/management/remote/mandatory/serverError/JMXServerErrorTest.java +++ b/jdk/test/javax/management/remote/mandatory/serverError/JMXServerErrorTest.java @@ -120,7 +120,7 @@ public class JMXServerErrorTest { try { cs=JMXConnectorServerFactory.newJMXConnectorServer(jurl,null,kbs); } catch (MalformedURLException m) { - if ("jmxmp".equals(jurl.getProtocol())) { + if ("jmxmp".equals(jurl.getProtocol()) || "iiop".equals(jurl.getProtocol())) { // OK, we may not have this in the classpath... System.out.println("WARNING: Skipping protocol: " + jurl); return;