use of io.confluent.ksql.util.KsqlServerException in project ksql by confluentinc.
the class KsqlRestConfig method sanitizeInterNodeListener.
/**
* Used to sanitize the first `listener` config.
*
* <p>It will:
* <ul>
* <li>resolve any auto-port assignment to the actual port the server is listening on</li>
* <li>potentially, replace the host with localhost. This can be useful where the first
* listener is a wildcard address, e.g. {@code 0.0.0.0}/li>
* </ul>
*
* @param listener the URL to sanitize
* @param portResolver the function to call to resolve the port.
* @param replaceHost flag indicating if the host in the URL should be replaced with localhost.
* @return the sanitized URL.
*/
private static URL sanitizeInterNodeListener(final URL listener, final Function<URL, Integer> portResolver, final boolean replaceHost) {
final String host = replaceHost ? getLocalHostName() : listener.getHost();
final int port = listener.getPort() == 0 ? portResolver.apply(listener) : listener.getPort();
try {
return new URL(listener.getProtocol(), host, port, "");
} catch (final MalformedURLException e) {
throw new KsqlServerException("Resolved first listener to malformed URL", e);
}
}
Aggregations