in api/src/main/java/org/apache/livy/LivyClientBuilder.java [123:171]
public LivyClient build() {
String uriStr = config.getProperty(LIVY_URI_KEY);
if (uriStr == null) {
throw new IllegalArgumentException("URI must be provided.");
}
URI uri;
try {
uri = new URI(uriStr);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid URI.", e);
}
LivyClient client = null;
if (CLIENT_FACTORIES.isEmpty()) {
throw new IllegalStateException("No LivyClientFactory implementation was found.");
}
for (LivyClientFactory factory : CLIENT_FACTORIES) {
try {
client = factory.createClient(uri, config);
} catch (Exception e) {
if (!(e instanceof RuntimeException)) {
e = new RuntimeException(e);
}
throw (RuntimeException) e;
}
if (client != null) {
break;
}
}
if (client == null) {
// Redact any user information from the URI when throwing user-visible exceptions that might
// be logged.
if (uri.getUserInfo() != null) {
try {
uri = new URI(uri.getScheme(), "[redacted]", uri.getHost(), uri.getPort(), uri.getPath(),
uri.getQuery(), uri.getFragment());
} catch (URISyntaxException e) {
// Shouldn't really happen.
throw new RuntimeException(e);
}
}
throw new IllegalArgumentException(String.format(
"URI '%s' is not supported by any registered client factories.", uri));
}
return client;
}