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 * @summary Ensure that java.rmi.Naming.lookup can handle URLs containing
26 * IPv6 addresses.
27 * @bug 4402708
28 *
29 * @run main/othervm -Djava.net.preferIPv6Addresses=true LookupIPv6
30 */
31
32 import java.net.InetAddress;
33 import java.net.Inet6Address;
34 import java.net.MalformedURLException;
35 import java.rmi.Naming;
36 import java.rmi.registry.LocateRegistry;
37 import java.rmi.registry.Registry;
38
39 public class LookupIPv6 {
40 public static void main(String[] args) throws Exception {
41 // use loopback IPv6 address to avoid lengthy socket connection delays
42 String[] urls = {
43 "rmi://[0000:0000:0000:0000:0000:0000:0000:0001]/foo",
44 "//[0:0:0:0:0:0:0:1]:88/foo",
45 "rmi://[0::0:0:0:1]/foo:bar",
46 "//[::1]:88"
47 };
48 for (int i = 0; i < urls.length; i++) {
49 try {
50 Naming.lookup(urls[i]);
51 } catch (MalformedURLException ex) {
52 throw ex;
53 } catch (Exception ex) {
54 // URLs are bogus, lookups expected to fail
55 }
56 }
57
58 /* Attempt to use IPv6-based URL to look up object in local registry.
59 * Since not all platforms support IPv6, this portion of the test may
60 * be a no-op in some cases. On supporting platforms, the first
61 * element of the array returned by InetAddress.getAllByName should be
62 * an Inet6Address since this test is run with
63 * -Djava.net.preferIPv6Addresses=true.
64 */
65 InetAddress localAddr = InetAddress.getAllByName(null)[0];
66 if (localAddr instanceof Inet6Address) {
67 System.out.println("IPv6 detected");
68 Registry reg;
69 try {
70 reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
71 } catch (Exception ex) {
72 reg = LocateRegistry.getRegistry();
73 }
74 reg.rebind("foo", reg);
75 Naming.lookup("rmi://[" + localAddr.getHostAddress() + "]/foo");
76 }
77 }
78 }
|
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 * @summary Ensure that java.rmi.Naming.lookup can handle URLs containing
26 * IPv6 addresses.
27 * @bug 4402708
28 * @library ../testlibrary
29 * @build TestLibrary
30 * @run main/othervm -Djava.net.preferIPv6Addresses=true LookupIPv6
31 */
32
33 import java.net.InetAddress;
34 import java.net.Inet6Address;
35 import java.net.MalformedURLException;
36 import java.rmi.Naming;
37 import java.rmi.registry.LocateRegistry;
38 import java.rmi.registry.Registry;
39
40 public class LookupIPv6 {
41
42 public static void main(String[] args) throws Exception {
43 // use loopback IPv6 address to avoid lengthy socket connection delays
44 String[] urls = {
45 "rmi://[0000:0000:0000:0000:0000:0000:0000:0001]/foo",
46 "//[0:0:0:0:0:0:0:1]:88/foo",
47 "rmi://[0::0:0:0:1]/foo:bar",
48 "//[::1]:88"
49 };
50 for (int i = 0; i < urls.length; i++) {
51 try {
52 Naming.lookup(urls[i]);
53 } catch (MalformedURLException ex) {
54 throw ex;
55 } catch (Exception ex) {
56 // URLs are bogus, lookups expected to fail
57 }
58 }
59
60 /* Attempt to use IPv6-based URL to look up object in local registry.
61 * Since not all platforms support IPv6, this portion of the test may
62 * be a no-op in some cases. On supporting platforms, the first
63 * element of the array returned by InetAddress.getAllByName should be
64 * an Inet6Address since this test is run with
65 * -Djava.net.preferIPv6Addresses=true.
66 */
67 int port = TestLibrary.getUnusedRandomPort();
68 InetAddress localAddr = InetAddress.getAllByName(null)[0];
69 if (localAddr instanceof Inet6Address) {
70 System.out.println("IPv6 detected");
71 Registry reg;
72 try {
73 reg = LocateRegistry.createRegistry(port);
74 } catch (Exception ex) {
75 reg = LocateRegistry.getRegistry();
76 }
77 reg.rebind("foo", reg);
78 Naming.lookup(String.format("rmi://[%1$s]:%2$s/foo", localAddr.getHostAddress(),port));
79 }
80 }
81 }
|