1 8 9 package test.javax.management.remote.rmi; 10 11 import java.net.MalformedURLException ; 12 import java.util.HashMap ; 13 import java.util.Map ; 14 15 import javax.management.remote.JMXConnectorFactory ; 16 import javax.management.remote.JMXConnectorServer ; 17 import javax.management.remote.JMXConnectorServerFactory ; 18 import javax.management.remote.JMXServiceURL ; 19 import javax.naming.Context ; 20 21 import mx4j.tools.naming.CosNamingService; 22 23 26 public class RMIIIOPConnectorTest extends RMIConnectorTestCase 27 { 28 private CosNamingService naming; 29 30 public RMIIIOPConnectorTest(String s) 31 { 32 super(s); 33 } 34 35 public JMXServiceURL createJMXConnectorServerAddress() throws MalformedURLException 36 { 37 return new JMXServiceURL ("iiop", "localhost", 0); 38 } 39 40 public void startNaming() throws Exception 41 { 42 naming = new CosNamingService(getNamingPort()); 43 naming.start(); 44 Thread.sleep(5000); 45 } 46 47 public void stopNaming() throws Exception 48 { 49 naming.stop(); 50 naming = null; 51 Thread.sleep(5000); 52 } 53 54 public int getNamingPort() 55 { 56 return 1100; 57 } 58 59 public Map getEnvironment() 60 { 61 HashMap env = new HashMap (); 62 env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"); 63 env.put(Context.PROVIDER_URL, "iiop://localhost:" + getNamingPort()); 64 return env; 66 } 67 68 public void testInvalidProvidedORB() throws Exception 69 { 70 Map environment = new HashMap (); 71 environment.put("java.naming.corba.orb", new Object ()); 72 73 JMXServiceURL url = new JMXServiceURL ("iiop", null, 0, "/jndi/iiop://localhost:" + getNamingPort() + "/jmx"); 74 JMXConnectorServer connectorServer = null; 75 try 76 { 77 startNaming(); 78 79 connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, newMBeanServer()); 80 connectorServer.start(); 81 82 JMXConnectorFactory.connect(url, environment); 83 fail(); 84 } 85 catch (IllegalArgumentException ignored) 86 { 87 } 88 finally 89 { 90 if (connectorServer != null) connectorServer.stop(); 91 stopNaming(); 92 } 93 } 94 } 95 | Popular Tags |