1 /* 2 * Copyright (c) 1999, 2012, 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 /* @test 25 * 26 * @summary HttpSocket functionality test 27 * @author Dana Burns 28 * 29 * @library ../../testlibrary 30 * @build HttpSocketTest HttpSocketTest_Stub TestLibrary 31 * @run main/othervm/policy=security.policy HttpSocketTest 32 */ 33 34 /* 35 * This test assures remote methods can be carried out over RMI. 36 * After setting the RMI runtime socket factory to the http proxy version, 37 * a registry is created, a remote object (an instance of this class) is 38 * registered with it, and then it is exercised. 39 */ 40 41 import java.rmi.Remote; 42 import java.rmi.RemoteException; 43 import java.rmi.Naming; 44 import java.rmi.RMISecurityManager; 45 import java.rmi.registry.LocateRegistry; 46 import java.rmi.registry.Registry; 47 import java.rmi.server.RMISocketFactory; 48 import java.rmi.server.UnicastRemoteObject; 49 import sun.rmi.transport.proxy.RMIHttpToPortSocketFactory; 50 51 interface MyRemoteInterface extends Remote { 52 void setRemoteObject( Remote r ) throws RemoteException; 53 Remote getRemoteObject() throws RemoteException; 54 } 55 56 public class HttpSocketTest extends UnicastRemoteObject 57 implements MyRemoteInterface 58 { 59 private static final String NAME = "HttpSocketTest"; 60 61 public HttpSocketTest() throws RemoteException{} 62 63 private Remote ro; 64 65 public static void main(String[] args) 66 throws Exception 67 { 68 69 Registry registry = null; 70 71 TestLibrary.suggestSecurityManager(null); 72 73 // Set the socket factory. 74 System.err.println("installing socket factory"); 75 RMISocketFactory.setSocketFactory(new RMIHttpToPortSocketFactory()); 76 int registryPort = -1; 77 78 try { 79 System.err.println("Starting registry"); 80 registry = TestLibrary.createRegistryOnUnusedPort(); 81 registryPort = TestLibrary.getRegistryPort(registry); 82 } catch (Exception e) { 83 TestLibrary.bomb(e); 84 } 85 86 try { 87 registry.rebind( NAME, new HttpSocketTest() ); 88 MyRemoteInterface httpTest = 89 (MyRemoteInterface)Naming.lookup("//:" + registryPort + "/" + NAME); 90 httpTest.setRemoteObject( new HttpSocketTest() ); 91 Remote r = httpTest.getRemoteObject(); 92 93 } catch (Exception e) { 94 TestLibrary.bomb(e); 95 } 96 97 98 } 99 100 public void setRemoteObject( Remote ro ) throws RemoteException { 101 this.ro = ro; 102 } 103 104 public Remote getRemoteObject() throws RemoteException { 105 return( this.ro ); 106 } 107 108 }