Path: blob/master/test/jdk/java/rmi/registry/readTest/CodebaseTest.java
41154 views
/*1* Copyright (c) 2017, 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*/2223/* @test24* @bug 7102369 7094468 710059225* @modules java.rmi/sun.rmi.registry26* java.rmi/sun.rmi.server27* java.rmi/sun.rmi.transport28* java.rmi/sun.rmi.transport.tcp29* @library ../../testlibrary30* @build TestLibrary RMIRegistryRunner RegistryVM JavaVM testPkg.* RegistryLookup31* @summary remove java.rmi.server.codebase property parsing from registyimpl32* @run main/othervm CodebaseTest33*/3435import java.io.File;36import java.nio.file.Files;37import java.nio.file.StandardCopyOption;38import java.rmi.registry.Registry;39import java.rmi.registry.LocateRegistry;40import java.rmi.RemoteException;41import java.rmi.server.UnicastRemoteObject;4243public class CodebaseTest {4445public static void main(String args[]) throws Exception {46RegistryVM rmiregistry = null;47JavaVM client = null;48try {49File src = new File(System.getProperty("test.classes", "."), "testPkg");50File dest = new File(System.getProperty("user.dir", "."), "testPkg");51Files.move(src.toPath(), dest.toPath(),52StandardCopyOption.REPLACE_EXISTING);5354File rmiregistryDir =55new File(System.getProperty("user.dir", "."), "rmi_tmp");56rmiregistryDir.mkdirs();57rmiregistry = RegistryVM.createRegistryVMWithRunner(58"RMIRegistryRunner",59" -Djava.rmi.server.useCodebaseOnly=false -Djava.security.manager=allow"60+ " -Duser.dir=" + rmiregistryDir.getAbsolutePath());61rmiregistry.start();62int port = rmiregistry.getPort();6364File srcReadTest = new File(System.getProperty("test.classes", "."),65"RegistryLookup.class");66File destReadTest = new File(System.getProperty("user.dir", "."),67"RegistryLookup.class");68Files.move(srcReadTest.toPath(), destReadTest.toPath(),69StandardCopyOption.REPLACE_EXISTING);7071File codebase = new File(System.getProperty("user.dir", "."));72client = new JavaVM("RegistryLookup",73" -Djava.rmi.server.codebase=" + codebase.toURI().toURL()74+ " -cp ." + File.pathSeparator + System.getProperty("test.class.path"),75Integer.toString(port));76int exit = client.execute();77if (exit == RegistryLookup.EXIT_FAIL) {78throw new RuntimeException("Test Fails");79}80} finally {81if (rmiregistry != null) {82rmiregistry.cleanup();83}84if (client != null) {85client.cleanup();86}87}88}89}909192