Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/transport/httpSocket/HttpSocketTest.java
38828 views
/*1* Copyright (c) 1999, 2012, 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*25* @summary HttpSocket functionality test26* @author Dana Burns27*28* @library ../../testlibrary29* @build TestLibrary HttpSocketTest HttpSocketTest_Stub30* @run main/othervm/policy=security.policy HttpSocketTest31*/3233/*34* This test assures remote methods can be carried out over RMI.35* After setting the RMI runtime socket factory to the http proxy version,36* a registry is created, a remote object (an instance of this class) is37* registered with it, and then it is exercised.38*/3940import java.rmi.Remote;41import java.rmi.RemoteException;42import java.rmi.Naming;43import java.rmi.RMISecurityManager;44import java.rmi.registry.LocateRegistry;45import java.rmi.registry.Registry;46import java.rmi.server.RMISocketFactory;47import java.rmi.server.UnicastRemoteObject;48import sun.rmi.transport.proxy.RMIHttpToPortSocketFactory;4950interface MyRemoteInterface extends Remote {51void setRemoteObject( Remote r ) throws RemoteException;52Remote getRemoteObject() throws RemoteException;53}5455public class HttpSocketTest extends UnicastRemoteObject56implements MyRemoteInterface57{58private static final String NAME = "HttpSocketTest";5960public HttpSocketTest() throws RemoteException{}6162private Remote ro;6364public static void main(String[] args)65throws Exception66{6768Registry registry = null;6970TestLibrary.suggestSecurityManager(null);7172// Set the socket factory.73System.err.println("installing socket factory");74RMISocketFactory.setSocketFactory(new RMIHttpToPortSocketFactory());75int registryPort = -1;7677try {78System.err.println("Starting registry");79registry = TestLibrary.createRegistryOnUnusedPort();80registryPort = TestLibrary.getRegistryPort(registry);81} catch (Exception e) {82TestLibrary.bomb(e);83}8485try {86registry.rebind( NAME, new HttpSocketTest() );87MyRemoteInterface httpTest =88(MyRemoteInterface)Naming.lookup("//:" + registryPort + "/" + NAME);89httpTest.setRemoteObject( new HttpSocketTest() );90Remote r = httpTest.getRemoteObject();9192} catch (Exception e) {93TestLibrary.bomb(e);94}959697}9899public void setRemoteObject( Remote ro ) throws RemoteException {100this.ro = ro;101}102103public Remote getRemoteObject() throws RemoteException {104return( this.ro );105}106107}108109110