LOG.error("Invalid version check URI.", e);
return;
}
CloseableHttpClient http = HttpClients.createDefault();
CloseableHttpResponse response = null;
try {
response = http.execute(get);
if (response.getStatusLine().getStatusCode() != 200) {
LOG.error("Expected version check HTTP status code [200] but got [{}]", response.getStatusLine().getStatusCode());
return;
}
HttpEntity entity = response.getEntity();
StringWriter writer = new StringWriter();
IOUtils.copy(entity.getContent(), writer, Charset.forName("UTF-8"));
String body = writer.toString();
VersionCheckResponse parsedResponse = parse(body);
Version reportedVersion = new Version(parsedResponse.version.major, parsedResponse.version.minor, parsedResponse.version.patch);
LOG.debug("Version check reports current version: " + parsedResponse);
if (reportedVersion.greaterMinor(ServerVersion.VERSION)) {
LOG.debug("Reported version is higher than ours ({}). Writing notification.", ServerVersion.VERSION);
Notification notification = notificationService.buildNow()
.addSeverity(Notification.Severity.NORMAL)
.addType(Notification.Type.OUTDATED_VERSION)
.addDetail("current_version", parsedResponse.toString());
notificationService.publishIfFirst(notification);
} else {
LOG.debug("Reported version is not higher than ours ({}).", ServerVersion.VERSION);
notificationService.fixed(Notification.Type.OUTDATED_VERSION);
}
EntityUtils.consume(entity);
} catch (IOException e) {
LOG.warn("Could not perform version check.", e);
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
LOG.warn("Could not close HTTP connection to version check API.", e);
}
}