blob: 76c4305e4fd202a2d6f9fb848aa6812f5a386ad3 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003 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/*
25 * @test
26 * @bug 4901808
27 * @summary Check that RMI connection ids include client host name
28 * @author Eamonn McManus
29 * @run clean RMIConnectionIdTest
30 * @run build RMIConnectionIdTest
31 * @run main RMIConnectionIdTest
32 */
33
34import java.net.*;
35import javax.management.*;
36import javax.management.remote.*;
37
38public class RMIConnectionIdTest {
39 public static void main(String[] args) throws Exception {
40 System.out.println("Testing that RMI connection id includes " +
41 "client host name");
42 MBeanServer mbs = MBeanServerFactory.createMBeanServer();
43 JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
44 JMXConnectorServer cs =
45 JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
46 cs.start();
47 JMXServiceURL addr = cs.getAddress();
48 JMXConnector cc = JMXConnectorFactory.connect(addr);
49 String connectionId = cc.getConnectionId();
50 System.out.println("Got connection id: " + connectionId);
51 if (!connectionId.startsWith("rmi://")) {
52 System.out.println("TEST FAILED: does not begin with \"rmi://\"");
53 System.exit(1);
54 }
55 String rest = connectionId.substring("rmi://".length());
56 int spaceIndex = rest.indexOf(' ');
57 if (spaceIndex < 0) {
58 System.out.println("TEST FAILED: no space");
59 System.exit(1);
60 }
61 String clientAddr = rest.substring(0, spaceIndex);
62 InetAddress clientInetAddr = InetAddress.getByName(clientAddr);
63 InetAddress localAddr = InetAddress.getLocalHost();
64 System.out.println("InetAddresses: local=" + localAddr + "; " +
65 "connectionId=" + clientInetAddr);
66 if (!localAddr.equals(clientInetAddr)) {
67 System.out.println("TEST FAILS: addresses differ");
68 System.exit(1);
69 }
70 cc.close();
71 cs.stop();
72 System.out.println("Test passed");
73 }
74}