if (given == null) {
return; // *** EARLY RETURN ***
}
if (given.indexOf('/') >= 0) {
throw new ParameterProblem("Listener override address has a '/' " +
"in it, use just a host or IP, not an URL");
}
final int splt = given.indexOf(':'); // first occurence only
final String host;
final String port;
if (splt >= 0) {
host = given.substring(0, splt).trim();
port = given.substring(splt).trim();
} else {
host = given.trim();
port = null;
}
if (host.length() == 0) {
throw new ParameterProblem("Listener override address " +
"has zero-length hostname, given: \"" + given + "\"");
}
if (port != null && port.length() == 0) {
throw new ParameterProblem("Listener override address " +
"has zero-length port, given: \"" + given + "\"");
}
final String urlString;
if (port == null) {
urlString = "http://" + host;
} else {
urlString = "http://" + host + ":" + port;
}
final String usingHost;
int usingPort = -1;
try {
final URL url = new URL(urlString);
usingHost = url.getHost();
if (port != null) {
usingPort = url.getPort();
}
} catch (MalformedURLException e) {
throw new ParameterProblem("Falied to test validity of listener " +
"override address using given input '" + given + "', " +
"testing with URL constructed from '" + urlString +
"': " + e.getMessage(), e);
}