Search in sources :

Example 16 with XmlReader

use of com.rometools.rome.io.XmlReader in project rssriver by dadoonet.

the class RssToJsonTest method shouldParseRss.

@Test
public /* this test should be moved somewhere else */
void shouldParseRss() throws Exception {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(getClass().getResource("/reuters/rss.xml")));
    assertThat(feed.getEntries().size(), greaterThan(0));
    for (Object o : feed.getEntries()) {
        SyndEntryImpl message = (SyndEntryImpl) o;
        XContentBuilder xcb = toJson(message, null, null, true);
        assertThat(xcb, notNullValue());
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) XmlReader(com.rometools.rome.io.XmlReader) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test)

Example 17 with XmlReader

use of com.rometools.rome.io.XmlReader in project rssriver by dadoonet.

the class RssRiver method getFeed.

private SyndFeed getFeed(String url) {
    try {
        URL feedUrl = new URL(url);
        URLConnection openConnection = feedUrl.openConnection();
        openConnection.addRequestProperty("User-Agent", "RSS River for Elasticsearch (https://github.com/dadoonet/rssriver)");
        SyndFeedInput input = new SyndFeedInput();
        input.setPreserveWireFeed(true);
        SyndFeed feed = input.build(new XmlReader(openConnection));
        return feed;
    } catch (MalformedURLException e) {
        logger.error("RSS Url is incorrect : [{}].", url);
    } catch (IllegalArgumentException e) {
        logger.error("Feed from [{}] is incorrect.", url);
    } catch (FeedException e) {
        logger.error("Can not parse feed from [{}].", url);
    } catch (IOException e) {
        logger.error("Can not read feed from [{}].", url);
    }
    return null;
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) MalformedURLException(java.net.MalformedURLException) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) FeedException(com.rometools.rome.io.FeedException) XmlReader(com.rometools.rome.io.XmlReader) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection)

Aggregations

XmlReader (com.rometools.rome.io.XmlReader)17 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)16 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)14 URL (java.net.URL)9 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)6 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)5 Test (org.junit.Test)5 FeedException (com.rometools.rome.io.FeedException)4 ParsingFeedException (com.rometools.rome.io.ParsingFeedException)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 Reader (java.io.Reader)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 IntegrationTest (com.aidanwhiteley.books.util.IntegrationTest)1 GeoRSSModule (com.rometools.modules.georss.GeoRSSModule)1 Position (com.rometools.modules.georss.geometries.Position)1 Channel (com.rometools.rome.feed.rss.Channel)1 SyndContent (com.rometools.rome.feed.synd.SyndContent)1 SyndEnclosure (com.rometools.rome.feed.synd.SyndEnclosure)1 Feed (fi.otavanopisto.muikku.plugins.feed.model.Feed)1