J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2005 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | import java.rmi.registry.LocateRegistry; |
| 25 | import java.rmi.registry.Registry; |
| 26 | import javax.rmi.ssl.SslRMIClientSocketFactory; |
| 27 | |
| 28 | public class RmiRegistrySslTest { |
| 29 | |
| 30 | static final String ok = "OK: Found jmxrmi entry in RMIRegistry!"; |
| 31 | static final String ko = "KO: Did not find jmxrmi entry in RMIRegistry!"; |
| 32 | static final String ko2 = "KO: Did not get expected exception!"; |
| 33 | static final String okException = "OK: Got expected exception!"; |
| 34 | static final String koException = "KO: Got unexpected exception!"; |
| 35 | |
| 36 | public static void main(String args[]) throws Exception { |
| 37 | |
| 38 | System.out.println("RmiRegistry lookup..."); |
| 39 | |
| 40 | String testID = System.getProperty("testID"); |
| 41 | |
| 42 | if ("Test1".equals(testID)) { |
| 43 | try { |
| 44 | Registry registry = LocateRegistry.getRegistry(4444); |
| 45 | String[] list = registry.list(); |
| 46 | if ("jmxrmi".equals(list[0])) { |
| 47 | System.out.println(ok); |
| 48 | } else { |
| 49 | System.out.println(ko); |
| 50 | throw new IllegalArgumentException(ko); |
| 51 | } |
| 52 | } catch (Exception e) { |
| 53 | System.out.println(koException); |
| 54 | e.printStackTrace(System.out); |
| 55 | throw e; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if ("Test2".equals(testID)) { |
| 60 | try { |
| 61 | Registry registry = LocateRegistry.getRegistry(4444); |
| 62 | String[] list = registry.list(); |
| 63 | throw new IllegalArgumentException(ko2); |
| 64 | } catch (Exception e) { |
| 65 | System.out.println(okException); |
| 66 | e.printStackTrace(System.out); |
| 67 | return; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if ("Test3".equals(testID)) { |
| 72 | try { |
| 73 | Registry registry = LocateRegistry.getRegistry( |
| 74 | null, 4444, new SslRMIClientSocketFactory()); |
| 75 | String[] list = registry.list(); |
| 76 | if ("jmxrmi".equals(list[0])) { |
| 77 | System.out.println(ok); |
| 78 | } else { |
| 79 | System.out.println(ko); |
| 80 | throw new IllegalArgumentException(ko); |
| 81 | } |
| 82 | } catch (Exception e) { |
| 83 | System.out.println(koException); |
| 84 | e.printStackTrace(System.out); |
| 85 | throw e; |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |