29 * @author Ann Wollrath 30 * 31 * @library ../../../../testlibrary 32 * @build TestLibrary RMID JavaVM StreamPipe 33 * @build Echo 34 * @build EchoImpl 35 * @build EchoImpl_Stub 36 * @build UseCustomSocketFactory 37 * @run main/othervm/policy=security.policy/timeout=120 UseCustomSocketFactory 38 */ 39 40 import java.io.*; 41 import java.rmi.*; 42 import java.rmi.server.*; 43 import java.rmi.registry.*; 44 45 public class UseCustomSocketFactory { 46 47 public static void main(String[] args) { 48 49 String[] protocol = new String[] { "", "compress", "xor" }; 50 51 System.out.println("\nRegression test for bug 4127826\n"); 52 53 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); 54 55 try { 56 LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); 57 } catch (Exception e) { 58 TestLibrary.bomb("creating registry", e); 59 } 60 61 for (int i = 0; i < protocol.length; i++) { 62 63 System.err.println("test policy: " + 64 TestParams.defaultPolicy); 65 66 JavaVM serverVM = new JavaVM("EchoImpl", 67 "-Djava.security.policy=" + 68 TestParams.defaultPolicy, 69 protocol[i]); 70 System.err.println("\nusing protocol: " + 71 (protocol[i] == "" ? "none" : protocol[i])); 72 73 try { 74 /* spawn VM for EchoServer */ 75 serverVM.start(); 76 77 /* lookup server */ 78 int tries = 8; 79 Echo obj = null; 80 do { 81 try { 82 obj = (Echo) Naming.lookup("//:" + TestLibrary.REGISTRY_PORT + 83 "/EchoServer"); 84 break; 85 } catch (NotBoundException e) { 86 try { 87 Thread.sleep(2000); 88 } catch (Exception ignore) { 89 } 90 continue; 91 } 92 } while (--tries > 0); 93 94 if (obj == null) 95 TestLibrary.bomb("server not bound in 8 tries", null); 96 97 /* invoke remote method and print result*/ 98 System.err.println("Bound to " + obj); 99 byte[] data = ("Greetings, citizen " + 100 System.getProperty("user.name") + "!"). getBytes(); 101 byte[] result = obj.echoNot(data); 102 for (int j = 0; j < result.length; j++) 103 result[j] = (byte) ~result[j]; 104 System.err.println("Result: " + new String(result)); 105 106 } catch (Exception e) { 107 TestLibrary.bomb("test failed", e); 108 109 } finally { 110 serverVM.destroy(); 111 try { 112 Naming.unbind("//:" + TestLibrary.REGISTRY_PORT + 113 "/EchoServer"); 114 } catch (Exception e) { 115 TestLibrary.bomb("unbinding EchoServer", e); 116 117 } 118 } 119 } 120 } 121 } | 29 * @author Ann Wollrath 30 * 31 * @library ../../../../testlibrary 32 * @build TestLibrary RMID JavaVM StreamPipe 33 * @build Echo 34 * @build EchoImpl 35 * @build EchoImpl_Stub 36 * @build UseCustomSocketFactory 37 * @run main/othervm/policy=security.policy/timeout=120 UseCustomSocketFactory 38 */ 39 40 import java.io.*; 41 import java.rmi.*; 42 import java.rmi.server.*; 43 import java.rmi.registry.*; 44 45 public class UseCustomSocketFactory { 46 47 public static void main(String[] args) { 48 49 int registryPort = -1; 50 51 String[] protocol = new String[] { "", "compress", "xor" }; 52 53 System.out.println("\nRegression test for bug 4127826\n"); 54 55 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); 56 57 try { 58 Registry registry = TestLibrary.createRegistryOnUnusedPort(); 59 registryPort = TestLibrary.getRegistryPort(registry); 60 } catch (Exception e) { 61 TestLibrary.bomb("creating registry", e); 62 } 63 64 for (int i = 0; i < protocol.length; i++) { 65 66 System.err.println("test policy: " + 67 TestParams.defaultPolicy); 68 69 JavaVM serverVM = new JavaVM("EchoImpl", 70 "-Djava.security.policy=" + 71 TestParams.defaultPolicy + 72 " -Drmi.registry.port=" + 73 registryPort, 74 protocol[i]); 75 System.err.println("\nusing protocol: " + 76 (protocol[i] == "" ? "none" : protocol[i])); 77 78 try { 79 /* spawn VM for EchoServer */ 80 serverVM.start(); 81 82 /* lookup server */ 83 int tries = 8; 84 Echo obj = null; 85 do { 86 try { 87 obj = (Echo) Naming.lookup("//:" + registryPort + 88 "/EchoServer"); 89 break; 90 } catch (NotBoundException e) { 91 try { 92 Thread.sleep(2000); 93 } catch (Exception ignore) { 94 } 95 continue; 96 } 97 } while (--tries > 0); 98 99 if (obj == null) 100 TestLibrary.bomb("server not bound in 8 tries", null); 101 102 /* invoke remote method and print result*/ 103 System.err.println("Bound to " + obj); 104 byte[] data = ("Greetings, citizen " + 105 System.getProperty("user.name") + "!"). getBytes(); 106 byte[] result = obj.echoNot(data); 107 for (int j = 0; j < result.length; j++) 108 result[j] = (byte) ~result[j]; 109 System.err.println("Result: " + new String(result)); 110 111 } catch (Exception e) { 112 TestLibrary.bomb("test failed", e); 113 114 } finally { 115 serverVM.destroy(); 116 try { 117 Naming.unbind("//:" + registryPort + 118 "/EchoServer"); 119 } catch (Exception e) { 120 TestLibrary.bomb("unbinding EchoServer", e); 121 122 } 123 } 124 } 125 } 126 } |