1 /* 2 * Copyright (c) 2005, 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 import java.rmi.registry.LocateRegistry; 25 import java.rmi.registry.Registry; 26 import javax.rmi.ssl.SslRMIClientSocketFactory; 27 import jdk.test.lib.Utils; 28 29 30 public class RmiRegistrySslTestApp { 31 32 static final String ok = "OK: Found jmxrmi entry in RMIRegistry!"; 33 static final String ko = "KO: Did not find jmxrmi entry in RMIRegistry!"; 34 static final String ko2 = "KO: Did not get expected exception!"; 35 static final String okException = "OK: Got expected exception!"; 36 static final String koException = "KO: Got unexpected exception!"; 37 38 public static void main(String args[]) throws Exception { 39 40 System.out.println("RmiRegistry lookup..."); 41 42 String testID = System.getProperty("testID"); 43 int port = Integer.parseInt(System.getProperty("test.rmi.port")); 44 45 if ("Test1".equals(testID)) { 46 try { 47 Registry registry = LocateRegistry.getRegistry(port); 48 String[] list = registry.list(); 49 if ("jmxrmi".equals(list[0])) { 50 System.out.println(ok); 51 } else { 52 System.out.println(ko); 53 throw new IllegalArgumentException(ko); 54 } 55 } catch (Exception e) { 56 System.out.println(koException); 57 e.printStackTrace(System.out); 58 throw e; 59 } 60 } 61 62 if ("Test2".equals(testID)) { 63 try { 64 Registry registry = LocateRegistry.getRegistry(port); 65 String[] list = registry.list(); 66 throw new IllegalArgumentException(ko2); 67 } catch (Exception e) { 68 System.out.println(okException); 69 e.printStackTrace(System.out); 70 return; 71 } 72 } 73 74 if ("Test3".equals(testID)) { 75 try { 76 Registry registry = LocateRegistry.getRegistry( 77 null, port, new SslRMIClientSocketFactory()); 78 String[] list = registry.list(); 79 if ("jmxrmi".equals(list[0])) { 80 System.out.println(ok); 81 } else { 82 System.out.println(ko); 83 throw new IllegalArgumentException(ko); 84 } 85 } catch (Exception e) { 86 System.out.println(koException); 87 e.printStackTrace(System.out); 88 throw e; 89 } 90 } 91 } 92 }