in src/main/java/com/cisco/gerrit/plugins/slack/client/WebhookClient.java [135:171]
private HttpURLConnection openConnection(String webhookUrl) {
try {
HttpURLConnection connection;
if (StringUtils.isNotBlank(config.getProxyHost())) {
LOGGER.info("Connecting via proxy");
if (StringUtils.isNotBlank(config.getProxyUsername())) {
Authenticator authenticator;
authenticator =
new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication(
config.getProxyUsername(), config.getProxyPassword().toCharArray()));
}
};
Authenticator.setDefault(authenticator);
}
Proxy proxy;
proxy =
new Proxy(
Proxy.Type.HTTP,
new InetSocketAddress(config.getProxyHost(), config.getProxyPort()));
connection = (HttpURLConnection) new URL(webhookUrl).openConnection(proxy);
} else {
LOGGER.info("Connecting directly");
connection = (HttpURLConnection) new URL(webhookUrl).openConnection();
}
return connection;
} catch (MalformedURLException e) {
throw new RuntimeException("Unable to create webhook URL: " + webhookUrl, e);
} catch (IOException e) {
throw new RuntimeException(
"Error opening connection to Slack URL: [" + e.getMessage() + "].", e);
}
}