blob: 6f26b9b55548eb923fb4e246e149e4b718d9db82 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1999-2006 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 *
26 * @summary HttpSocket functionality test
27 * @author Dana Burns
28 *
29 * @library ../../testlibrary
30 * @build HttpSocketTest HttpSocketTest_Stub
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
41import java.rmi.Remote;
42import java.rmi.RemoteException;
43import java.rmi.Naming;
44import java.rmi.RMISecurityManager;
45import java.rmi.registry.LocateRegistry;
46import java.rmi.registry.Registry;
47import java.rmi.server.RMISocketFactory;
48import java.rmi.server.UnicastRemoteObject;
49import sun.rmi.transport.proxy.RMIHttpToPortSocketFactory;
50
51interface MyRemoteInterface extends Remote {
52 void setRemoteObject( Remote r ) throws RemoteException;
53 Remote getRemoteObject() throws RemoteException;
54}
55
56public class HttpSocketTest extends UnicastRemoteObject
57 implements MyRemoteInterface
58{
59
60 private static final String NAME = "HttpSocketTest";
61 private static final String REGNAME =
62 "//:" + TestLibrary.REGISTRY_PORT + "/" + NAME;
63
64 public HttpSocketTest() throws RemoteException{}
65
66 private Remote ro;
67
68 public static void main(String[] args)
69 throws Exception
70 {
71
72 Registry registry = null;
73
74 TestLibrary.suggestSecurityManager(null);
75
76 // Set the socket factory.
77 System.err.println("installing socket factory");
78 RMISocketFactory.setSocketFactory(new RMIHttpToPortSocketFactory());
79
80 try {
81
82 System.err.println("Starting registry");
83 registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT);
84
85 } catch (Exception e) {
86 TestLibrary.bomb(e);
87 }
88
89 try {
90
91 registry.rebind( NAME, new HttpSocketTest() );
92 MyRemoteInterface httpTest =
93 (MyRemoteInterface)Naming.lookup( REGNAME );
94 httpTest.setRemoteObject( new HttpSocketTest() );
95 Remote r = httpTest.getRemoteObject();
96
97 } catch (Exception e) {
98 TestLibrary.bomb(e);
99 }
100
101
102 }
103
104 public void setRemoteObject( Remote ro ) throws RemoteException {
105 this.ro = ro;
106 }
107
108 public Remote getRemoteObject() throws RemoteException {
109 return( this.ro );
110 }
111
112}
113
114
115
116
117