Search in sources :

Example 1 with ParameterException

use of com.github.joschi.jadconfig.ParameterException in project graylog2-server by Graylog2.

the class HttpConfiguration method getDefaultHttpUri.

private URI getDefaultHttpUri(String path) {
    final HostAndPort bindAddress = getHttpBindAddress();
    final URI publishUri;
    final InetAddress inetAddress = toInetAddress(bindAddress.getHost());
    if (inetAddress != null && Tools.isWildcardInetAddress(inetAddress)) {
        final InetAddress guessedAddress;
        try {
            guessedAddress = Tools.guessPrimaryNetworkAddress(inetAddress instanceof Inet4Address);
            if (guessedAddress.isLoopbackAddress()) {
                LOG.debug("Using loopback address {}", guessedAddress);
            }
        } catch (Exception e) {
            LOG.error("Could not guess primary network address for \"http_publish_uri\". Please configure it in your Graylog configuration.", e);
            throw new ParameterException("No http_publish_uri.", e);
        }
        try {
            publishUri = new URI(getUriScheme(), null, guessedAddress.getHostAddress(), bindAddress.getPort(), path, null, null);
        } catch (URISyntaxException e) {
            throw new RuntimeException("Invalid http_publish_uri.", e);
        }
    } else {
        try {
            publishUri = new URI(getUriScheme(), null, getHttpBindAddress().getHost(), getHttpBindAddress().getPort(), path, null, null);
        } catch (URISyntaxException e) {
            throw new RuntimeException("Invalid http_publish_uri.", e);
        }
    }
    return publishUri;
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Inet4Address(java.net.Inet4Address) ParameterException(com.github.joschi.jadconfig.ParameterException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) InetAddress(java.net.InetAddress) ParameterException(com.github.joschi.jadconfig.ParameterException) URISyntaxException(java.net.URISyntaxException) ValidationException(com.github.joschi.jadconfig.ValidationException) UnknownHostException(java.net.UnknownHostException)

Aggregations

ParameterException (com.github.joschi.jadconfig.ParameterException)1 ValidationException (com.github.joschi.jadconfig.ValidationException)1 HostAndPort (com.google.common.net.HostAndPort)1 Inet4Address (java.net.Inet4Address)1 InetAddress (java.net.InetAddress)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1