use of com.rometools.rome.feed.synd.SyndEntry in project spring-integration by spring-projects.
the class FeedEntryMessageSourceTests method testEntryHavingBeenUpdatedAfterPublishAndRepeat.
// verifies that when entry has been updated since publish, that is taken into
// account when determining if the feed entry has been seen before
@Test
public void testEntryHavingBeenUpdatedAfterPublishAndRepeat() throws Exception {
ClassPathResource resource = new ClassPathResource("org/springframework/integration/feed/atom.xml");
FeedEntryMessageSource feedEntrySource = new FeedEntryMessageSource(resource, "foo");
feedEntrySource.setBeanName("feedReader");
PropertiesPersistingMetadataStore metadataStore = new PropertiesPersistingMetadataStore();
metadataStore.afterPropertiesSet();
feedEntrySource.setMetadataStore(metadataStore);
feedEntrySource.setBeanFactory(mock(BeanFactory.class));
feedEntrySource.afterPropertiesSet();
SyndEntry entry1 = feedEntrySource.receive().getPayload();
// only 1 entries in the test feed
assertNull(feedEntrySource.receive());
assertEquals("Atom draft-07 snapshot", entry1.getTitle().trim());
assertEquals(1071318569000L, entry1.getPublishedDate().getTime());
assertEquals(1122812969000L, entry1.getUpdatedDate().getTime());
metadataStore.destroy();
metadataStore.afterPropertiesSet();
// now test that what's been read is no longer retrieved
feedEntrySource = new FeedEntryMessageSource(resource, "foo");
feedEntrySource.setBeanName("feedReader");
metadataStore = new PropertiesPersistingMetadataStore();
metadataStore.afterPropertiesSet();
feedEntrySource.setMetadataStore(metadataStore);
feedEntrySource.setBeanFactory(mock(BeanFactory.class));
feedEntrySource.afterPropertiesSet();
assertNull(feedEntrySource.receive());
}
use of com.rometools.rome.feed.synd.SyndEntry in project spring-integration by spring-projects.
the class FeedEntryMessageSourceTests method testReceiveFeedWithEntriesSorted.
@Test
public void testReceiveFeedWithEntriesSorted() throws Exception {
ClassPathResource resource = new ClassPathResource("org/springframework/integration/feed/sample.rss");
FeedEntryMessageSource source = new FeedEntryMessageSource(resource, "foo");
source.setComponentName("feedReader");
source.setBeanFactory(mock(BeanFactory.class));
source.afterPropertiesSet();
Message<SyndEntry> message1 = source.receive();
Message<SyndEntry> message2 = source.receive();
Message<SyndEntry> message3 = source.receive();
long time1 = message1.getPayload().getPublishedDate().getTime();
long time2 = message2.getPayload().getPublishedDate().getTime();
long time3 = message3.getPayload().getPublishedDate().getTime();
assertTrue(time1 < time2);
assertTrue(time2 < time3);
assertNull(source.receive());
}
use of com.rometools.rome.feed.synd.SyndEntry in project muikku by otavanopisto.
the class FeedSynchronizer method updateFeeds.
@Schedule(second = "0", minute = "0", hour = "*", persistent = false)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void updateFeeds() {
Client client = ClientBuilder.newClient();
feedItemDao.deleteAll();
List<Feed> feeds = feedDao.listAll();
for (Feed feed : feeds) {
WebTarget target = client.target(feed.getUrl());
try (InputStream stream = target.request("*").get(InputStream.class)) {
SyndFeedInput input = new SyndFeedInput();
SyndFeed syndFeed = input.build(new XmlReader(stream));
List<SyndEntry> entries = syndFeed.getEntries();
for (SyndEntry entry : entries) {
feedItemDao.create(entry.getTitle(), entry.getLink(), entry.getAuthor(), entry.getDescription() == null ? null : clean(entry.getDescription().getValue()), entry.getPublishedDate(), (String) null, feed);
}
} catch (IOException | IllegalArgumentException | FeedException e) {
logger.warning(String.format("Error while synchronizing feeds: %s", e.getMessage()));
ejbContext.setRollbackOnly();
}
}
}
use of com.rometools.rome.feed.synd.SyndEntry in project onebusaway-application-modules by camsys.
the class AgencyMessagesUpdateAction method execute.
@Override
public String execute() {
_feed = new SyndFeedImpl();
StringBuilder title = new StringBuilder();
title.append("OneBusAway General Notices");
HttpServletRequest request = ServletActionContext.getRequest();
StringBuilder b = new StringBuilder();
b.append("http://");
b.append(request.getServerName());
if (request.getServerPort() != 80)
b.append(":").append(request.getServerPort());
if (request.getContextPath() != null)
b.append(request.getContextPath());
String baseUrl = b.toString();
_feed.setTitle(title.toString());
_feed.setLink(baseUrl);
_feed.setDescription("General Notices");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
// Add Agency Messages
SyndEntry agencyMsgEntry = new SyndEntryImpl();
StatusGroup agencyMsgGroup = _statusProvider.getAgencyMetadataStatus();
if (agencyMsgGroup.getItems().size() == 0) {
agencyMsgEntry = new SyndEntryImpl();
agencyMsgEntry.setTitle("No General Notices");
entries.add(agencyMsgEntry);
} else {
for (StatusItem agencyMsgItem : agencyMsgGroup.getItems()) {
agencyMsgEntry = new SyndEntryImpl();
agencyMsgEntry.setTitle(agencyMsgItem.getTitle());
entries.add(agencyMsgEntry);
}
}
_feed.setEntries(entries);
return SUCCESS;
}
use of com.rometools.rome.feed.synd.SyndEntry in project onebusaway-application-modules by camsys.
the class MonitoringAlertsUpdateAction method execute.
@Override
public String execute() {
_feed = new SyndFeedImpl();
StringBuilder title = new StringBuilder();
title.append("OneBusAway System Monitoring");
HttpServletRequest request = ServletActionContext.getRequest();
StringBuilder b = new StringBuilder();
b.append("http://");
b.append(request.getServerName());
if (request.getServerPort() != 80)
b.append(":").append(request.getServerPort());
if (request.getContextPath() != null)
b.append(request.getContextPath());
String baseUrl = b.toString();
_feed.setTitle(title.toString());
_feed.setLink(baseUrl);
_feed.setDescription("System Monitoring");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
// Add Icinga Alerts
SyndEntry icingaEntry = new SyndEntryImpl();
SyndContent icingaContent = new SyndContentImpl();
StatusGroup icingaGroup = _statusProvider.getIcingaStatus();
StatusGroup icingaProblems = new StatusGroup();
icingaProblems.setTitle(icingaGroup.getTitle());
// Only report items where status is not "OK"
for (StatusItem icingaItem : icingaGroup.getItems()) {
if (icingaItem.getStatus() != StatusItem.Status.OK) {
icingaProblems.addItem(icingaItem);
}
}
if (icingaProblems.getItems().size() == 0) {
icingaEntry = new SyndEntryImpl();
icingaEntry.setTitle("All systems operational");
entries.add(icingaEntry);
} else {
for (StatusItem icingaItem : icingaProblems.getItems()) {
icingaEntry = new SyndEntryImpl();
icingaEntry.setTitle(icingaItem.getTitle());
icingaContent = new SyndContentImpl();
icingaContent.setValue(icingaItem.getStatus() + ": " + icingaItem.getDescription());
icingaEntry.setDescription(icingaContent);
entries.add(icingaEntry);
}
}
_feed.setEntries(entries);
return SUCCESS;
}
Aggregations