Search in sources :

Example 41 with NewznabXmlRoot

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());
    }
}
Also used : NewznabXmlError(org.nzbhydra.mapping.newznab.xml.NewznabXmlError) Xml(org.nzbhydra.mapping.newznab.xml.Xml) NewznabXmlRoot(org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot) IndexerAccessException(org.nzbhydra.indexers.exceptions.IndexerAccessException) URI(java.net.URI)

Aggregations

NewznabXmlRoot (org.nzbhydra.mapping.newznab.xml.NewznabXmlRoot)41 Test (org.junit.Test)30 MockResponse (okhttp3.mockwebserver.MockResponse)12 NewznabXmlItem (org.nzbhydra.mapping.newznab.xml.NewznabXmlItem)11 AbstractConfigReplacingTest (org.nzbhydra.tests.AbstractConfigReplacingTest)10 NewznabAttribute (org.nzbhydra.mapping.newznab.xml.NewznabAttribute)8 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 ArrayList (java.util.ArrayList)5 Dispatcher (okhttp3.mockwebserver.Dispatcher)4 NewznabXmlChannel (org.nzbhydra.mapping.newznab.xml.NewznabXmlChannel)4 NzbhydraMockMvcTest (org.nzbhydra.tests.NzbhydraMockMvcTest)4 URI (java.net.URI)3 NewznabResponseBuilder (org.nzbhydra.fortests.NewznabResponseBuilder)3 NewznabParameters (org.nzbhydra.mapping.newznab.NewznabParameters)3 NewznabXmlEnclosure (org.nzbhydra.mapping.newznab.xml.NewznabXmlEnclosure)3 NewznabXmlGuid (org.nzbhydra.mapping.newznab.xml.NewznabXmlGuid)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Matcher (java.util.regex.Matcher)2 NewznabXmlResponse (org.nzbhydra.mapping.newznab.xml.NewznabXmlResponse)2