Search in sources :

Example 16 with SyndEntry

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());
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) BeanFactory(org.springframework.beans.factory.BeanFactory) PropertiesPersistingMetadataStore(org.springframework.integration.metadata.PropertiesPersistingMetadataStore) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 17 with SyndEntry

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());
}
Also used : SyndEntry(com.rometools.rome.feed.synd.SyndEntry) BeanFactory(org.springframework.beans.factory.BeanFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 18 with SyndEntry

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();
        }
    }
}
Also used : InputStream(java.io.InputStream) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) FeedException(com.rometools.rome.io.FeedException) XmlReader(com.rometools.rome.io.XmlReader) IOException(java.io.IOException) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) SyndFeedInput(com.rometools.rome.io.SyndFeedInput) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Feed(fi.otavanopisto.muikku.plugins.feed.model.Feed) TransactionAttribute(javax.ejb.TransactionAttribute) Schedule(javax.ejb.Schedule)

Example 19 with SyndEntry

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl)

Example 20 with SyndEntry

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StatusItem(org.onebusaway.enterprise.webapp.actions.status.model.StatusItem) SyndContent(com.rometools.rome.feed.synd.SyndContent) StatusGroup(org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndContentImpl(com.rometools.rome.feed.synd.SyndContentImpl) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndFeedImpl(com.rometools.rome.feed.synd.SyndFeedImpl)

Aggregations

SyndEntry (com.rometools.rome.feed.synd.SyndEntry)45 ArrayList (java.util.ArrayList)23 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)22 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)18 SyndContent (com.rometools.rome.feed.synd.SyndContent)15 SyndFeedImpl (com.rometools.rome.feed.synd.SyndFeedImpl)14 SyndContentImpl (com.rometools.rome.feed.synd.SyndContentImpl)13 SyndFeedInput (com.rometools.rome.io.SyndFeedInput)9 FeedException (com.rometools.rome.io.FeedException)7 Test (org.junit.Test)7 XmlReader (com.rometools.rome.io.XmlReader)6 URL (java.net.URL)6 Date (java.util.Date)5 StatusGroup (org.onebusaway.enterprise.webapp.actions.status.model.StatusGroup)5 StatusItem (org.onebusaway.enterprise.webapp.actions.status.model.StatusItem)5 IOException (java.io.IOException)4 BeanFactory (org.springframework.beans.factory.BeanFactory)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 SyndFeedOutput (com.rometools.rome.io.SyndFeedOutput)3 Post (it.vige.rubia.model.Post)3