if (statusCode != HttpStatus.SC_OK) {
String message = "URL access returned " + HttpStatus.getStatusText(statusCode);
log.error(message);
if (attempt >= maxTry) {
log.warn("Error. Maximum attempts count reached.");
throw new APIException(message, statusCode);
}
waitBeforeRetrying();
} else {
InputStream stream = method.getResponseBodyAsStream();
stream = new BufferedInputStream(stream);
Header contentEncoding = method.getResponseHeader("Content-Encoding");
if (contentEncoding != null) {
if (contentEncoding.getValue().equals("gzip")) {
stream = new GZIPInputStream(stream);
}
}
SAXBuilder sxb = new SAXBuilder();
Document document = sxb.build(stream);
traceDocument(document);
root = document.getRootElement();
checkForError(root);
return root;
}
} catch (JDOMParseException e) {
// NOTE: to deal with api.php login action being disabled.
String message = "JDOMParseException: " + e.getMessage();
log.error(message);
if (attempt > maxTry) {
log.warn("Error. Maximum attempts count reached.");
throw e;
}
waitBeforeRetrying();
} catch (JDOMException e) {
String message = "JDOMException: " + e.getMessage();
log.error(message);
if (attempt > maxTry) {
log.warn("Error. Maximum attempts count reached.");
throw new APIException("Error parsing XML result", e);
}
waitBeforeRetrying();
} catch (IOException e) {
String message = "" + e.getClass().getName() + ": " + e.getMessage();
log.error(message);
if (attempt > maxTry) {
log.warn("Error. Maximum attempts count reached.");
throw new APIException("Error accessing MediaWiki", e);
}
waitBeforeRetrying();
} catch (APIException e) {
if (!e.shouldRetry() || (attempt > e.getMaxRetry())) {
throw e;