public HostAndPort getHttpBindAddress() { return httpBindAddress .requireBracketsForIPv6() .withDefaultPort(GRAYLOG_DEFAULT_PORT); }
public void testRequireBracketsForIPv6() { // Bracketed IPv6 works fine. assertEquals("::1", HostAndPort.fromString("[::1]").requireBracketsForIPv6().getHost()); assertEquals("::1", HostAndPort.fromString("[::1]:80").requireBracketsForIPv6().getHost()); // Non-bracketed non-IPv6 works fine. assertEquals("x", HostAndPort.fromString("x").requireBracketsForIPv6().getHost()); assertEquals("x", HostAndPort.fromString("x:80").requireBracketsForIPv6().getHost()); // Non-bracketed IPv6 fails. try { HostAndPort.fromString("::1").requireBracketsForIPv6(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }
void validate(final String setting, final String input) { HostAndPort hostAndPort = HostAndPort.fromString(input); if (this.requireBracketsForIPv6) { hostAndPort = hostAndPort.requireBracketsForIPv6(); } if (null != this.defaultPort) { hostAndPort.withDefaultPort(this.defaultPort); } if (Strings.isNullOrEmpty(hostAndPort.getHost())) { throw new ConfigException(String.format("'%s'(%s) host cannot be blank or null.", setting, input)); } if (this.portRequired && !hostAndPort.hasPort()) { throw new ConfigException(String.format("'%s'(%s) must specify a port.", setting, input)); } }
HostAndPort hp = HostAndPort.fromString(args[0]) .withDefaultPort(2049) .requireBracketsForIPv6();
public void testRequireBracketsForIPv6() { // Bracketed IPv6 works fine. assertEquals("::1", HostAndPort.fromString("[::1]").requireBracketsForIPv6().getHost()); assertEquals("::1", HostAndPort.fromString("[::1]:80").requireBracketsForIPv6().getHost()); // Non-bracketed non-IPv6 works fine. assertEquals("x", HostAndPort.fromString("x").requireBracketsForIPv6().getHost()); assertEquals("x", HostAndPort.fromString("x:80").requireBracketsForIPv6().getHost()); // Non-bracketed IPv6 fails. try { HostAndPort.fromString("::1").requireBracketsForIPv6(); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { } }