Search in sources :

Example 11 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project play-cookbook by spinscale.

the class FeedTest method testThatRss20Works.

@Test
public void testThatRss20Works() throws Exception {
    Response response = GET("/feed/posts.rss2");
    assertIsOk(response);
    assertContentType("application/rss+xml", response);
    assertCharset("utf-8", response);
    SyndFeed feed = getFeed(response);
    assertEquals("rss_2.0", feed.getFeedType());
}
Also used : Response(play.mvc.Http.Response) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) FunctionalTest(play.test.FunctionalTest) Test(org.junit.Test)

Example 12 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project apex-malhar by apache.

the class RomeSyndicationOperator method run.

/**
 * Thread processing of the syndication feeds
 */
@Override
public void run() {
    try {
        while (true) {
            InputStreamReader isr = null;
            try {
                isr = new InputStreamReader(getFeedInputStream());
                SyndFeedInput feedInput = new SyndFeedInput();
                SyndFeed feed = feedInput.build(isr);
                List entries = feed.getEntries();
                List<RomeFeedEntry> nfeedItems = new ArrayList<RomeFeedEntry>();
                boolean oldEntries = false;
                for (int i = 0; i < entries.size(); ++i) {
                    SyndEntry syndEntry = (SyndEntry) entries.get(i);
                    RomeFeedEntry romeFeedEntry = getSerializableEntry(syndEntry);
                    if (!oldEntries) {
                        if (!feedItems.contains(romeFeedEntry)) {
                            outputPort.emit(romeFeedEntry);
                        } else if (orderedUpdate) {
                            oldEntries = true;
                        }
                    }
                    nfeedItems.add(romeFeedEntry);
                }
                feedItems = nfeedItems;
            } catch (Exception e) {
                logger.error(e.getMessage());
            } finally {
                if (isr != null) {
                    try {
                        isr.close();
                    } catch (Exception ce) {
                        logger.error(ce.getMessage());
                    }
                }
            }
            Thread.sleep(interval);
        }
    } catch (InterruptedException ie) {
        logger.error("Interrupted: " + ie.getMessage());
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) InputStreamReader(java.io.InputStreamReader) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 13 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project quickstarts by jboss-switchyard.

the class CamelRSSPollTest method shouldRetrieveGreetings.

@Test
public void shouldRetrieveGreetings() throws Exception {
    _testKit.removeService("PrintService");
    final MockHandler printService = _testKit.registerInOnlyService("PrintService");
    Thread.sleep(10001);
    final LinkedBlockingQueue<Exchange> receivedMessages = printService.getMessages();
    for (Exchange e : receivedMessages) {
        SyndFeed feed = (SyndFeed) e.getMessage().getContent();
        @SuppressWarnings("unchecked") List<SyndEntry> entries = feed.getEntries();
        Assert.assertEquals(feed.getEntries().size(), 1);
        Iterator<SyndEntry> itEntries = entries.iterator();
        while (itEntries.hasNext()) {
            SyndEntry entry = (SyndEntry) itEntries.next();
            Assert.assertTrue(entry.getTitle().equals(SONG_TITLE));
            Assert.assertTrue(entry.getLink().equals(SONG_URL));
            Assert.assertTrue(entry.getDescription().getValue().equals(SONG_DESCRIPTION));
        }
    }
}
Also used : Exchange(org.switchyard.Exchange) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) MockHandler(org.switchyard.test.MockHandler) Test(org.junit.Test)

Example 14 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project jersey by jersey.

the class FeedDownloader method apply.

@Override
@SuppressWarnings("unchecked")
public List<SyndEntry> apply(URL url) {
    try (XmlReader xmlReader = new XmlReader(url)) {
        SyndFeedInput input = new SyndFeedInput();
        SyndFeed feed = input.build(xmlReader);
        return feed.getEntries();
    } catch (Exception e) {
        LOG.warn("An error during downloading and parsing a given feed: " + url, e);
    }
    return Collections.emptyList();
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) XmlReader(com.sun.syndication.io.XmlReader)

Example 15 with SyndFeed

use of com.sun.syndication.feed.synd.SyndFeed in project jersey by jersey.

the class FeedEntriesAtomBodyWriter method writeTo.

@Override
public void writeTo(List<FeedEntry> entries, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    List<SyndEntry> syndEntries = entries.parallelStream().map(entry -> {
        SyndContent description = new SyndContentImpl();
        description.setType(MediaType.TEXT_PLAIN);
        description.setValue(entry.getDescription());
        SyndEntry syndEntry = new SyndEntryImpl();
        syndEntry.setTitle(entry.getTitle());
        syndEntry.setLink(entry.getLink());
        syndEntry.setPublishedDate(entry.getPublishDate());
        syndEntry.setDescription(description);
        return syndEntry;
    }).collect(Collectors.toList());
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("atom_1.0");
    feed.setTitle("Combined Feed");
    feed.setDescription("Combined Feed created by a feed-combiner application");
    feed.setPublishedDate(new Date());
    feed.setEntries(syndEntries);
    writeSyndFeed(entityStream, feed);
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Produces(javax.ws.rs.Produces) Provider(javax.ws.rs.ext.Provider) FeedEntry(org.glassfish.jersey.examples.feedcombiner.model.FeedEntry) Date(java.util.Date) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) LoggerFactory(org.slf4j.LoggerFactory) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) FeedException(com.sun.syndication.io.FeedException) MediaType(javax.ws.rs.core.MediaType) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) OutputStreamWriter(java.io.OutputStreamWriter) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) Collection(java.util.Collection) IOException(java.io.IOException) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) Collectors(java.util.stream.Collectors) SyndContent(com.sun.syndication.feed.synd.SyndContent) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) List(java.util.List) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) Date(java.util.Date)

Aggregations

SyndFeed (com.sun.syndication.feed.synd.SyndFeed)22 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)8 ArrayList (java.util.ArrayList)7 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)6 Test (org.junit.Test)6 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)5 SyndContent (com.sun.syndication.feed.synd.SyndContent)4 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)4 FeedException (com.sun.syndication.io.FeedException)4 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)4 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)4 IOException (java.io.IOException)4 URL (java.net.URL)3 Date (java.util.Date)3 FeedEntryModel (com.gitblit.models.FeedEntryModel)2 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 FeedFetcherCache (com.sun.syndication.fetcher.impl.FeedFetcherCache)2 SyndFeedInfo (com.sun.syndication.fetcher.impl.SyndFeedInfo)2 XmlReader (com.sun.syndication.io.XmlReader)2 InputStream (java.io.InputStream)2