Index: impl/src/main/java/com/sun/enterprise/mgmt/ClusterManager.java =================================================================== --- impl/src/main/java/com/sun/enterprise/mgmt/ClusterManager.java (revision 1731) +++ impl/src/main/java/com/sun/enterprise/mgmt/ClusterManager.java (working copy) @@ -538,7 +538,7 @@ if (bindInterfaceAddress != null && !bindInterfaceAddress.equals("")) { InetAddress inetAddress = null; try { - inetAddress = InetAddress.getByName( bindInterfaceAddress ); + inetAddress = NetworkUtility.resolveBindInterfaceName( bindInterfaceAddress ); if( inetAddress instanceof Inet6Address ) { bindInterfaceEndpointAddress = TCP_SCHEME + "[" + bindInterfaceAddress + "]" + PORT; } else { Index: impl/src/main/java/com/sun/enterprise/mgmt/transport/NetworkUtility.java =================================================================== --- impl/src/main/java/com/sun/enterprise/mgmt/transport/NetworkUtility.java (revision 1731) +++ impl/src/main/java/com/sun/enterprise/mgmt/transport/NetworkUtility.java (working copy) @@ -400,10 +400,11 @@ // allow loopback address. only work on a single machine. used for development. //if( anAddr.isLoopbackAddress() || anAddr.isAnyLocalAddress() ) // continue; - if (firstInetAddressV6 == null && anAddr instanceof Inet6Address) + if (firstInetAddressV6 == null && anAddr instanceof Inet6Address) { firstInetAddressV6 = anAddr; - else if (firstInetAddressV4 == null && anAddr instanceof Inet4Address) + } else if (firstInetAddressV4 == null && anAddr instanceof Inet4Address) { firstInetAddressV4 = anAddr; + } if (firstInetAddressV6 != null && firstInetAddressV4 != null) break; } @@ -670,25 +671,8 @@ public static boolean isBindAddressValid(String addressString) { ServerSocket socket = null; try { - InetAddress ia = null; - try { - ia = Inet4Address.getByName(addressString); - } catch (Exception e) { - if (LOG.isLoggable(Level.FINE)) { - LOG.log(Level.FINE, "in isBindAddressValid(" + addressString + "): Inet4Address.getByName(" + - addressString + ")", e); - } else { - LOG.log(Level.INFO, "in isBindAddressValid(" + addressString + "): Inet4Address.getByName(" + - addressString + ") handled exception " + e.getClass().getSimpleName()); - } - } + InetAddress ia = resolveBindInterfaceName(addressString); - if (ia == null) { - // check if address string is a network interface. - NetworkInterface netInt = NetworkInterface.getByName(addressString); - ia = getNetworkInetAddress(netInt, false); - } - // calling ServerSocket with null for ia means to use any local address that is available. // thus, if ia is not non-null at this point, must return false here. if (ia == null) { @@ -722,41 +706,60 @@ public static InetAddress resolveBindInterfaceName(String addressString) { InetAddress ia = null; + NetworkInterface ni = null; + + if (LOG.isLoggable(Level.FINE)) { + LOG.fine("enter NetworkUtility.resolveBindInterfaceName(" + addressString + ")"); + } + + // due GLASSFISH-18047, check if addressString is a network interface before checking + // if it is a host name or ip address. try { + ni = NetworkInterface.getByName(addressString); + } catch (Throwable ignored) { + if (LOG.isLoggable(Level.FINE)) { + LOG.log(Level.FINE, + "resolveBindInterfaceName: call to NetworkInterface.getByName ignoring thrown exception", + ignored); + } + } + + if (ni != null) { try { - ia = Inet4Address.getByName(addressString); - } catch (Exception e) { + ia = getNetworkInetAddress(ni, getPreferIpv6Addresses()); + } catch (Throwable ignored) { + if (LOG.isLoggable(Level.FINE)) { + LOG.log(Level.FINE, "resolveBindInterfaceName: call to getNetworkAddress ignoring thrown exception", + ignored); + } } if (ia == null) { try { - ia = Inet6Address.getByName(addressString); - } catch (Exception e) { - } - - // if ia is still null, check if address string is a network interface name. - if (ia == null) { - NetworkInterface netInt = NetworkInterface.getByName(addressString); - if (netInt != null) { - try { - ia = getNetworkInetAddress(netInt, false); // get IPv4 - } catch (IOException ioe) { - } - if (ia == null) { - try { - ia = getNetworkInetAddress(netInt, true); // get IPv6 - } catch (IOException ioe) { - } - } + ia = getNetworkInetAddress(ni, ! getPreferIpv6Addresses()); + } catch(Throwable ignored) { + if (LOG.isLoggable(Level.FINE)) { + LOG.log(Level.FINE, + "resolveBindInterfaceName: call to NetworkUtility.getNetworkAddress ignoring thrown exception", + ignored); } } } - return ia; - } catch (Exception e) { - LOG.log(Level.WARNING, "resolveBindInterfaceName", e); - LOG.log(Level.WARNING, "netutil.validate.bind.address.exception", - new Object[]{addressString, e.toString()}); - return null; } + if (ia == null) { + try { + ia = InetAddress.getByName(addressString); + } catch (Throwable ignored) { + if (LOG.isLoggable(Level.FINE)) { + LOG.log(Level.FINE, + "resolveBindInterfaceName: call to InetAddress.getByName ignoring thrown exception", + ignored); + } + } + } + if (LOG.isLoggable(Level.FINE)) { + LOG.fine("return NetworkUtility.resolveBindInterfaceName(" + addressString + ")=" + ia); + } + return ia; } public static void main( String[] args ) throws IOException { @@ -765,7 +768,8 @@ boolean preferIPv6Addrs = Boolean.parseBoolean(preferIPv6PropertyValue); System.out.println( "AllLocalAddresses() = " + getAllLocalAddresses() ); System.out.println( "getFirstNetworkInterface() = " +getFirstNetworkInterface() ); - System.out.println( "getFirstInetAddress(preferIPv6Addresses:" + preferIPv6Addrs + ")=" + getFirstInetAddress(preferIPv6Addrs)); + System.out.println( "getFirstInetAddress(preferIPv6Addresses:" + preferIPv6Addrs + ")=" + + getFirstInetAddress(preferIPv6Addrs)); System.out.println( "getFirstInetAddress()=" + getFirstInetAddress()); System.out.println( "getFirstInetAddress( true ) = " + getFirstInetAddress( true ) ); InetAddress ia = getFirstInetAddress(false); Index: impl/src/main/java/com/sun/enterprise/mgmt/transport/grizzly/GrizzlyNetworkManager.java =================================================================== --- impl/src/main/java/com/sun/enterprise/mgmt/transport/grizzly/GrizzlyNetworkManager.java (revision 1731) +++ impl/src/main/java/com/sun/enterprise/mgmt/transport/grizzly/GrizzlyNetworkManager.java (working copy) @@ -154,23 +154,7 @@ try { InetAddress inetAddr = null; NetworkInterface ni = null; - try { - inetAddr = InetAddress.getByName(host); - } catch (UnknownHostException he) { - ni = NetworkInterface.getByName(host); - if (ni != null) { - try { - inetAddr = NetworkUtility.getNetworkInetAddress(ni, false); - } catch (IOException ignore) {} - if (inetAddr == null) { - try { - inetAddr = NetworkUtility.getNetworkInetAddress(ni, true); - } catch (IOException ignore) {} - } - } else { - shoalLogger.log(Level.WARNING, "grizzlynetmgr.invalidbindaddr", new Object[]{he.getLocalizedMessage()}); - } - } + inetAddr = NetworkUtility.resolveBindInterfaceName(host); if (ni == null) { ni = NetworkInterface.getByInetAddress(inetAddr); } @@ -178,6 +162,7 @@ networkInterfaceName = ni.getName(); } if (inetAddr != null) { + String oldhost = host; host = inetAddr.getHostAddress(); properties.put(BIND_INTERFACE_ADDRESS.toString(), host); } Index: impl/src/main/java/com/sun/enterprise/mgmt/transport/grizzly/grizzly1_9/GrizzlyNetworkManager1_9.java =================================================================== --- impl/src/main/java/com/sun/enterprise/mgmt/transport/grizzly/grizzly1_9/GrizzlyNetworkManager1_9.java (revision 1731) +++ impl/src/main/java/com/sun/enterprise/mgmt/transport/grizzly/grizzly1_9/GrizzlyNetworkManager1_9.java (working copy) @@ -120,7 +120,7 @@ InetAddress localInetAddress = null; if( host != null ) { - localInetAddress = InetAddress.getByName( host ); + localInetAddress = NetworkUtility.resolveBindInterfaceName(host); } ThreadPoolConfig threadPoolConfig = new ThreadPoolConfig("GMS-GrizzlyControllerThreadPool-Group-" + groupName, corePoolSize,