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 private static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort(); 42 43 public static void main(String[] args) throws Exception { 44 // use loopback IPv6 address to avoid lengthy socket connection delays 45 String[] urls = { 46 "rmi://[0000:0000:0000:0000:0000:0000:0000:0001]/foo", 47 "//[0:0:0:0:0:0:0:1]:88/foo", 48 "rmi://[0::0:0:0:1]/foo:bar", 49 "//[::1]:88" 50 }; 51 for (int i = 0; i < urls.length; i++) { 52 try { 53 Naming.lookup(urls[i]); 54 } catch (MalformedURLException ex) { 55 throw ex; 56 } catch (Exception ex) { 57 // URLs are bogus, lookups expected to fail 58 } 59 } 60 61 /* Attempt to use IPv6-based URL to look up object in local registry. 62 * Since not all platforms support IPv6, this portion of the test may 63 * be a no-op in some cases. On supporting platforms, the first 64 * element of the array returned by InetAddress.getAllByName should be 65 * an Inet6Address since this test is run with 66 * -Djava.net.preferIPv6Addresses=true. 67 */ 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(REGISTRY_PORT); 74 } catch (Exception ex) { 75 reg = LocateRegistry.getRegistry(); 76 } 77 reg.rebind("foo", reg); 78 Naming.lookup("rmi://[" + localAddr.getHostAddress() + "]" + ":" + REGISTRY_PORT + "/foo"); 79 } 80 } 81 } |