jdk/test/java/rmi/Naming/LookupIPv6.java
author juh
Tue, 25 Jun 2013 14:41:46 -0700
changeset 18552 005e115dc6ee
parent 14778 5947768d173d
child 22614 2e2f77dc2599
permissions -rw-r--r--
8017326: Cleanup of the javadoc <code> tag in java.security.spec Summary: Convert javadoc <code> and <tt> tags to {@code ...} Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
14778
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    25
 * @summary Ensure that java.rmi.Naming.lookup can handle URLs containing
5947768d173d 8004748: clean up @build tags in RMI tests
smarks
parents: 5506
diff changeset
    26
 *          IPv6 addresses.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @bug 4402708
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @run main/othervm -Djava.net.preferIPv6Addresses=true LookupIPv6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.InetAddress;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.Inet6Address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.rmi.Naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.registry.LocateRegistry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.registry.Registry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class LookupIPv6 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        // use loopback IPv6 address to avoid lengthy socket connection delays
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        String[] urls = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            "rmi://[0000:0000:0000:0000:0000:0000:0000:0001]/foo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            "//[0:0:0:0:0:0:0:1]:88/foo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
            "rmi://[0::0:0:0:1]/foo:bar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
            "//[::1]:88"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        for (int i = 0; i < urls.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                Naming.lookup(urls[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            } catch (MalformedURLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                throw ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                // URLs are bogus, lookups expected to fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        /* Attempt to use IPv6-based URL to look up object in local registry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
         * Since not all platforms support IPv6, this portion of the test may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
         * be a no-op in some cases.  On supporting platforms, the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
         * element of the array returned by InetAddress.getAllByName should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
         * an Inet6Address since this test is run with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
         * -Djava.net.preferIPv6Addresses=true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        InetAddress localAddr = InetAddress.getAllByName(null)[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        if (localAddr instanceof Inet6Address) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            System.out.println("IPv6 detected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            Registry reg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                reg = LocateRegistry.getRegistry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            reg.rebind("foo", reg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            Naming.lookup("rmi://[" + localAddr.getHostAddress() + "]/foo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
}