use of com.rometools.rome.feed.synd.SyndFeed 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;
}
use of com.rometools.rome.feed.synd.SyndFeed in project rssriver by dadoonet.
the class RomeTest method testLeMonde.
@Test
public void testLeMonde() throws Exception {
SyndFeedInput input = new SyndFeedInput();
input.setPreserveWireFeed(true);
SyndFeed feed = input.build(new XmlReader(getClass().getResource("/lemonde/rss.xml")));
assertThat(feed, notNullValue());
assertThat(feed.getEntries().isEmpty(), equalTo(false));
assertThat(feed.originalWireFeed(), notNullValue());
assertThat(feed.originalWireFeed(), instanceOf(Channel.class));
Channel channel = (Channel) feed.originalWireFeed();
assertThat(channel.getTtl(), equalTo(15));
}
use of com.rometools.rome.feed.synd.SyndFeed in project rssriver by dadoonet.
the class RomeTest method testGeoLoc.
@Test
public void testGeoLoc() throws Exception {
SyndFeedInput input = new SyndFeedInput();
input.setPreserveWireFeed(true);
SyndFeed feed = input.build(new XmlReader(getClass().getResource("/reuters/rss.xml")));
assertThat(feed, notNullValue());
assertThat(feed.getEntries().isEmpty(), equalTo(false));
for (Object o : feed.getEntries()) {
assertThat(o, instanceOf(SyndEntryImpl.class));
SyndEntryImpl entry = (SyndEntryImpl) o;
GeoRSSModule geoRSSModule = GeoRSSUtils.getGeoRSS(entry);
assertThat(geoRSSModule, notNullValue());
Position position = geoRSSModule.getPosition();
assertThat(position, notNullValue());
assertThat(position.getLatitude(), equalTo(41.8947384616695));
assertThat(position.getLongitude(), equalTo(12.4839019775391));
}
}
use of com.rometools.rome.feed.synd.SyndFeed 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());
}
}
use of com.rometools.rome.feed.synd.SyndFeed in project rssriver by dadoonet.
the class RssToJsonTest method buildEntry.
private SyndEntryImpl buildEntry() throws FeedException, IOException {
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(getClass().getResource("/reuters/rss.xml")));
return (SyndEntryImpl) feed.getEntries().get(0);
}
Aggregations