Search in sources :

Example 16 with SyndFeedInput

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

the class RssToJsonTest method shouldHaveRawContent.

@Test
public void shouldHaveRawContent() throws Exception {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(getClass().getResource("/dcrainmaker/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());
        assertThat(xcb.string(), containsString("<p>"));
        logger.info(xcb.string());
    }
}
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 SyndFeedInput

use of com.rometools.rome.io.SyndFeedInput 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 18 with SyndFeedInput

use of com.rometools.rome.io.SyndFeedInput 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)

Example 19 with SyndFeedInput

use of com.rometools.rome.io.SyndFeedInput in project books by aidanwhiteley.

the class FeedsControllerTest method checkRssFeedsHasEntries.

@Test
void checkRssFeedsHasEntries() throws Exception {
    // Find the port the test is running on
    String rootUri = this.testRestTemplate.getRootUri();
    String url = rootUri + "/feeds/rss";
    XmlReader reader = new XmlReader(new URL(url));
    SyndFeed feed = new SyndFeedInput().build(reader);
    assertEquals(booksFeedsTitles, feed.getTitle());
    assertTrue(feed.getEntries().size() > 0);
    for (SyndEntry entry : feed.getEntries()) {
        assertFalse(entry.getContents().get(0).getValue().isEmpty());
    }
}
Also used : SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) XmlReader(com.rometools.rome.io.XmlReader) URL(java.net.URL) Test(org.junit.jupiter.api.Test) IntegrationTest(com.aidanwhiteley.books.util.IntegrationTest)

Aggregations

SyndFeedInput (com.rometools.rome.io.SyndFeedInput)19 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)17 XmlReader (com.rometools.rome.io.XmlReader)14 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)9 FeedException (com.rometools.rome.io.FeedException)7 URL (java.net.URL)7 Test (org.junit.Test)6 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)5 IOException (java.io.IOException)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 SyndContent (com.rometools.rome.feed.synd.SyndContent)2 ParsingFeedException (com.rometools.rome.io.ParsingFeedException)2 Result (ddf.catalog.data.Result)2 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Element (org.jdom2.Element)2 InputSource (org.xml.sax.InputSource)2 IntegrationTest (com.aidanwhiteley.books.util.IntegrationTest)1