@Test public void testAddressFormat() { String s1 = ConsulServerUtils.fixIPv6Address("fc00:ec:cd::242:ac11:c"); assertThat(s1).isEqualTo("[fc00:ec:cd:0:0:242:ac11:c]"); String s2 = ConsulServerUtils.fixIPv6Address("[fc00:ec:cd::242:ac11:c]"); assertThat(s2).isEqualTo("[fc00:ec:cd:0:0:242:ac11:c]"); String s3 = ConsulServerUtils.fixIPv6Address("192.168.0.1"); assertThat(s3).isEqualTo("192.168.0.1"); String s4 = ConsulServerUtils.fixIPv6Address("projects.spring.io"); assertThat(s4).isEqualTo("projects.spring.io"); String s5 = ConsulServerUtils.fixIPv6Address("veryLongHostName"); assertThat(s5).isEqualTo("veryLongHostName"); }
public static String fixIPv6Address(String address) { try { InetAddress inetAdr = InetAddress.getByName(address); if (inetAdr instanceof Inet6Address) { return "[" + inetAdr.getHostName() + "]"; } return address; } catch (UnknownHostException e) { log.debug("Not InetAddress: " + address + " , resolved as is."); return address; } }
ConsulServerUtils { public static String fixIPv6Address(String address) { try { InetAddress inetAdr = InetAddress.getByName(address); if (inetAdr instanceof Inet6Address) { return "[" + inetAdr.getHostName() + "]"; } return address; } catch (UnknownHostException e) { log.debug("Not InetAddress: " + address + " , resolved as is."); return address; } } }
ConsulServerUtils { public static String fixIPv6Address(String address) { try { InetAddress inetAdr = InetAddress.getByName(address); if (inetAdr instanceof Inet6Address) { return "[" + inetAdr.getHostName() + "]"; } return address; } catch (UnknownHostException e) { log.debug("Not InetAddress: " + address + " , resolved as is."); return address; } } private  ConsulServerUtils(); }
ConsulServerUtils { public static String fixIPv6Address(String address) { try { InetAddress inetAdr = InetAddress.getByName(address); if (inetAdr instanceof Inet6Address) { return "[" + inetAdr.getHostName() + "]"; } return address; } catch (UnknownHostException e) { log.debug("Not InetAddress: " + address + " , resolved as is."); return address; } } private  ConsulServerUtils(); static String findHost(HealthService healthService); static String fixIPv6Address(String address); }
ConsulServerUtils { public static String fixIPv6Address(String address) { try { InetAddress inetAdr = InetAddress.getByName(address); if (inetAdr instanceof Inet6Address) { return "[" + inetAdr.getHostName() + "]"; } return address; } catch (UnknownHostException e) { log.debug("Not InetAddress: " + address + " , resolved as is."); return address; } } private  ConsulServerUtils(); static String findHost(HealthService healthService); static String fixIPv6Address(String address);  }