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