blob: 0a7754a75f30af0f14123a1795e6a68b2d1f1cf5 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001 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 * @bug 4180282
26 * @summary RMI needs a mechanism to dynamically change a VMs RMI
27 * serverHostname. If the java.rmi.server.hostname property is
28 * changed dynamically, newly exported objects should be exported
29 * with the new hostname instead of the value of the
30 * java.rmi.server.hostname property when the first object was exported.
31 *
32 * @author Ann Wollrath
33 *
34 * @build ChangeHostName
35 * @build ChangeHostName_Stub
36 * @run main/othervm ChangeHostName
37 */
38
39import java.net.InetAddress;
40import java.rmi.Remote;
41import java.rmi.RemoteException;
42import java.rmi.server.RemoteObject;
43import java.rmi.server.UnicastRemoteObject;
44
45public class ChangeHostName
46 extends UnicastRemoteObject
47 implements Receiver
48{
49 public ChangeHostName() throws RemoteException {
50 }
51
52 public void receive(Remote obj) {
53 System.err.println("received: " + obj.toString());
54 }
55
56 public static void main(String[] args) throws Exception {
57
58 InetAddress localAddress = InetAddress.getLocalHost();
59 String[] hostlist = new String[] {
60 localAddress.getHostAddress(), localAddress.getHostName() };
61
62 for (int i = 0; i < hostlist.length; i++) {
63
64 System.setProperty("java.rmi.server.hostname", hostlist[i]);
65 Remote impl = new ChangeHostName();
66 System.err.println("\ncreated impl extending URO: " + impl);
67
68 Receiver stub = (Receiver) RemoteObject.toStub(impl);
69 System.err.println("stub for impl: " + stub);
70
71 System.err.println("invoking method on stub");
72 stub.receive(stub);
73
74 UnicastRemoteObject.unexportObject(impl, true);
75 System.err.println("unexported impl");
76
77 if (stub.toString().indexOf(hostlist[i]) >= 0) {
78 System.err.println("stub's ref contains hostname: " +
79 hostlist[i]);
80 } else {
81 throw new RuntimeException(
82 "TEST FAILED: stub's ref doesn't contain hostname: " +
83 hostlist[i]);
84 }
85 }
86 System.err.println("TEST PASSED");
87 }
88}
89
90interface Receiver extends Remote {
91 void receive(Remote obj) throws RemoteException;
92}