use of org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot in project nzbhydra2 by theotherp.
the class NewznabChecker method checkConnection.
public GenericResponse checkConnection(IndexerConfig indexerConfig) {
Xml xmlResponse;
try {
URI uri = getBaseUri(indexerConfig).queryParam("t", "search").build().toUri();
xmlResponse = indexerWebAccess.get(uri, indexerConfig);
logger.debug("Checking connection to indexer {} using URI {}", indexerConfig.getName(), uri);
if (xmlResponse instanceof NewznabXmlError) {
logger.warn("Connection check with indexer {} failed with message: {}", indexerConfig.getName(), ((NewznabXmlError) xmlResponse).getDescription());
return GenericResponse.notOk("Indexer returned message: " + ((NewznabXmlError) xmlResponse).getDescription());
}
NewznabXmlRoot rssRoot = (NewznabXmlRoot) xmlResponse;
if (!rssRoot.getRssChannel().getItems().isEmpty()) {
logger.info("Connection to indexer {} successful", indexerConfig.getName());
return GenericResponse.ok();
} else {
logger.warn("Connection to indexer {} successful but search did not return any results", indexerConfig.getName());
return GenericResponse.notOk("Indexer did not return any results");
}
} catch (IndexerAccessException e) {
logger.warn("Connection check with indexer {} failed with message: {}", indexerConfig.getName(), e.getMessage());
return GenericResponse.notOk(e.getMessage());
}
}
Aggregations