1 /* 2 * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 4115696 26 27 * @summary synopsis: cannot use socket factories with Activatable objects 28 * @author Ann Wollrath 29 * 30 * @library ../../../../testlibrary 31 * @build Echo 32 * @build EchoImpl 33 * @build EchoImpl_Stub 34 * @build UseCustomSocketFactory 35 * @run main/othervm/policy=security.policy/timeout=360 UseCustomSocketFactory 36 */ 37 38 import java.io.*; 39 import java.rmi.*; 40 import java.rmi.activation.*; 41 import java.rmi.server.*; 42 import java.rmi.registry.*; 43 44 public class UseCustomSocketFactory { 45 46 final static int REGISTRY_PORT = 2006; 47 static String[] protocol = new String[] { "", "compress", "xor" }; 48 49 public static void main(String[] args) { 50 51 System.out.println("\nRegression test for bug 4115696\n"); 52 53 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); 54 55 try { 56 LocateRegistry.createRegistry(REGISTRY_PORT); 57 } catch (Exception e) { 58 TestLibrary.bomb("creating registry", e); 59 } 60 61 RMID rmid = null; 62 63 try { 64 rmid = RMID.createRMID(true); 65 rmid.addArguments(new String[] { 66 "-C-Djava.security.policy=" + 67 TestParams.defaultGroupPolicy + 68 " -C-Djava.security.manager=java.rmi.RMISecurityManager "}); 69 rmid.start(); 70 71 Echo[] echo = spawnAndTest(); 72 reactivateAndTest(echo); 73 } catch (IOException e) { 74 TestLibrary.bomb("creating rmid", e); 75 } finally { 76 if (rmid != null) 77 rmid.destroy(); 78 } 79 } 80 81 private static Echo[] spawnAndTest() { 82 83 System.err.println("\nCreate Test-->"); 84 85 Echo[] echo = new Echo[protocol.length]; 86 87 for (int i = 0; i < protocol.length; i++) { 88 89 JavaVM serverVM = new JavaVM("EchoImpl", 90 "-Djava.security.policy=" + 91 TestParams.defaultPolicy, 92 protocol[i]); 93 94 System.err.println("\nusing protocol: " + 95 (protocol[i] == "" ? "none" : protocol[i])); 96 97 try { 98 /* spawn VM for EchoServer */ 99 serverVM.start(); 100 101 /* lookup server */ 102 int tries = 12; // need enough tries for slow machine. 103 echo[i] = null; 104 do { 105 try { 106 echo[i] = (Echo) Naming.lookup("//:" + REGISTRY_PORT + 107 "/EchoServer"); 108 break; 109 } catch (NotBoundException e) { 110 try { 111 Thread.sleep(2000); | 1 /* 2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 * @bug 4115696 26 27 * @summary synopsis: cannot use socket factories with Activatable objects 28 * @author Ann Wollrath 29 * 30 * @library ../../../../testlibrary 31 * @build Echo 32 * @build EchoImpl 33 * @build EchoImpl_Stub 34 * @build UseCustomSocketFactory 35 * @build TestLibrary 36 * @run main/othervm/policy=security.policy/timeout=360 UseCustomSocketFactory 37 */ 38 39 import java.io.*; 40 import java.rmi.*; 41 import java.rmi.activation.*; 42 import java.rmi.server.*; 43 import java.rmi.registry.*; 44 45 public class UseCustomSocketFactory { 46 static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort(); 47 48 static String[] protocol = new String[] { "", "compress", "xor" }; 49 50 public static void main(String[] args) { 51 52 System.out.println("\nRegression test for bug 4115696\n"); 53 54 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); 55 56 try { 57 LocateRegistry.createRegistry(REGISTRY_PORT); 58 } catch (Exception e) { 59 TestLibrary.bomb("creating registry", e); 60 } 61 62 RMID rmid = null; 63 64 try { 65 rmid = RMID.createRMID(true); 66 rmid.addArguments(new String[] { 67 "-C-Djava.security.policy=" + 68 TestParams.defaultGroupPolicy + 69 " -C-Djava.security.manager=java.rmi.RMISecurityManager "}); 70 rmid.start(); 71 72 Echo[] echo = spawnAndTest(rmid.getPort()); 73 reactivateAndTest(echo); 74 } catch (IOException e) { 75 TestLibrary.bomb("creating rmid", e); 76 } finally { 77 if (rmid != null) 78 rmid.destroy(); 79 } 80 } 81 82 private static Echo[] spawnAndTest(int rmidPort) { 83 84 System.err.println("\nCreate Test-->"); 85 86 Echo[] echo = new Echo[protocol.length]; 87 88 for (int i = 0; i < protocol.length; i++) { 89 JavaVM serverVM = new JavaVM("EchoImpl", 90 "-Djava.security.policy=" + 91 TestParams.defaultPolicy + 92 " -Drmi.registry.port=" + 93 REGISTRY_PORT + 94 " -Djava.rmi.activation.port=" + 95 rmidPort, 96 protocol[i]); 97 98 System.err.println("\nusing protocol: " + 99 (protocol[i] == "" ? "none" : protocol[i])); 100 101 try { 102 /* spawn VM for EchoServer */ 103 serverVM.start(); 104 105 /* lookup server */ 106 int tries = 12; // need enough tries for slow machine. 107 echo[i] = null; 108 do { 109 try { 110 echo[i] = (Echo) Naming.lookup("//:" + REGISTRY_PORT + 111 "/EchoServer"); 112 break; 113 } catch (NotBoundException e) { 114 try { 115 Thread.sleep(2000); |