Path: blob/master/test/jdk/sun/management/jmxremote/bootstrap/RmiRegistrySslTestApp.java
41153 views
/*1* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.rmi.registry.LocateRegistry;24import java.rmi.registry.Registry;25import javax.rmi.ssl.SslRMIClientSocketFactory;26import jdk.test.lib.Utils;272829public class RmiRegistrySslTestApp {3031static final String ok = "OK: Found jmxrmi entry in RMIRegistry!";32static final String ko = "KO: Did not find jmxrmi entry in RMIRegistry!";33static final String ko2 = "KO: Did not get expected exception!";34static final String okException = "OK: Got expected exception!";35static final String koException = "KO: Got unexpected exception!";3637public static void main(String args[]) throws Exception {3839System.out.println("RmiRegistry lookup...");4041String testID = System.getProperty("testID");42int port = Integer.parseInt(System.getProperty("test.rmi.port"));4344if ("Test1".equals(testID)) {45try {46Registry registry = LocateRegistry.getRegistry(port);47String[] list = registry.list();48if ("jmxrmi".equals(list[0])) {49System.out.println(ok);50} else {51System.out.println(ko);52throw new IllegalArgumentException(ko);53}54} catch (Exception e) {55System.out.println(koException);56e.printStackTrace(System.out);57throw e;58}59}6061if ("Test2".equals(testID)) {62try {63Registry registry = LocateRegistry.getRegistry(port);64String[] list = registry.list();65throw new IllegalArgumentException(ko2);66} catch (Exception e) {67System.out.println(okException);68e.printStackTrace(System.out);69return;70}71}7273if ("Test3".equals(testID)) {74try {75Registry registry = LocateRegistry.getRegistry(76null, port, new SslRMIClientSocketFactory());77String[] list = registry.list();78if ("jmxrmi".equals(list[0])) {79System.out.println(ok);80} else {81System.out.println(ko);82throw new IllegalArgumentException(ko);83}84} catch (Exception e) {85System.out.println(koException);86e.printStackTrace(System.out);87throw e;88}89}90}91}929394