Search in sources :

Example 1 with SyndFeed

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

the class HttpClientWithTimeoutFeedFetcher method getFeed.

private SyndFeed getFeed(SyndFeedInfo syndFeedInfo, String urlStr, HttpMethod method, int statusCode) throws IOException, HttpException, FetcherException, FeedException {
    if (statusCode == HttpURLConnection.HTTP_NOT_MODIFIED && syndFeedInfo != null) {
        fireEvent(FetcherEvent.EVENT_TYPE_FEED_UNCHANGED, urlStr);
        return syndFeedInfo.getSyndFeed();
    }
    SyndFeed feed = retrieveFeed(urlStr, method);
    fireEvent(FetcherEvent.EVENT_TYPE_FEED_RETRIEVED, urlStr, feed);
    return feed;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed)

Example 2 with SyndFeed

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

the class HttpClientWithTimeoutFeedFetcher method retrieveFeed.

/**
	 * @see com.sun.syndication.fetcher.FeedFetcher#retrieveFeed(java.net.URL)
	 */
@Override
public SyndFeed retrieveFeed(URL feedUrl) throws IllegalArgumentException, IOException, FeedException, FetcherException {
    if (feedUrl == null) {
        throw new IllegalArgumentException("null is not a valid URL");
    }
    // TODO Fix this
    //System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    HttpClient client = new HttpClient();
    HttpConnectionManager conManager = client.getHttpConnectionManager();
    conManager.getParams().setParameter("http.connection.timeout", 3000);
    conManager.getParams().setParameter("http.socket.timeout", 3000);
    if (getCredentialSupplier() != null) {
        client.getState().setAuthenticationPreemptive(true);
        // TODO what should realm be here?
        Credentials credentials = getCredentialSupplier().getCredentials(null, feedUrl.getHost());
        if (credentials != null) {
            client.getState().setCredentials(null, feedUrl.getHost(), credentials);
        }
    }
    System.setProperty("httpclient.useragent", "Openfire Admin Console: v" + XMPPServer.getInstance().getServerInfo().getVersion().getVersionString());
    String urlStr = feedUrl.toString();
    FeedFetcherCache cache = getFeedInfoCache();
    if (cache != null) {
        // retrieve feed
        HttpMethod method = new GetMethod(urlStr);
        method.addRequestHeader("Accept-Encoding", "gzip");
        try {
            if (isUsingDeltaEncoding()) {
                method.setRequestHeader("A-IM", "feed");
            }
            // get the feed info from the cache
            // Note that syndFeedInfo will be null if it is not in the cache
            SyndFeedInfo syndFeedInfo = cache.getFeedInfo(feedUrl);
            if (syndFeedInfo != null) {
                method.setRequestHeader("If-None-Match", syndFeedInfo.getETag());
                if (syndFeedInfo.getLastModified() instanceof String) {
                    method.setRequestHeader("If-Modified-Since", (String) syndFeedInfo.getLastModified());
                }
            }
            method.setFollowRedirects(true);
            int statusCode = client.executeMethod(method);
            fireEvent(FetcherEvent.EVENT_TYPE_FEED_POLLED, urlStr);
            handleErrorCodes(statusCode);
            SyndFeed feed = getFeed(syndFeedInfo, urlStr, method, statusCode);
            syndFeedInfo = buildSyndFeedInfo(feedUrl, urlStr, method, feed, statusCode);
            cache.setFeedInfo(new URL(urlStr), syndFeedInfo);
            // the feed may have been modified to pick up cached values
            // (eg - for delta encoding)
            feed = syndFeedInfo.getSyndFeed();
            return feed;
        } finally {
            method.releaseConnection();
        }
    } else {
        // cache is not in use
        HttpMethod method = new GetMethod(urlStr);
        try {
            method.setFollowRedirects(true);
            int statusCode = client.executeMethod(method);
            fireEvent(FetcherEvent.EVENT_TYPE_FEED_POLLED, urlStr);
            handleErrorCodes(statusCode);
            return getFeed(null, urlStr, method, statusCode);
        } finally {
            method.releaseConnection();
        }
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SyndFeedInfo(com.sun.syndication.fetcher.impl.SyndFeedInfo) FeedFetcherCache(com.sun.syndication.fetcher.impl.FeedFetcherCache) URL(java.net.URL)

Example 3 with SyndFeed

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

the class HttpClientWithTimeoutFeedFetcher method buildSyndFeedInfo.

/**
     * @param feedUrl
     * @param urlStr
     * @param method
     * @param feed
     * @return SyndFeedInfo
     * @throws MalformedURLException
     */
private SyndFeedInfo buildSyndFeedInfo(URL feedUrl, String urlStr, HttpMethod method, SyndFeed feed, int statusCode) throws MalformedURLException {
    SyndFeedInfo syndFeedInfo;
    syndFeedInfo = new SyndFeedInfo();
    // this may be different to feedURL because of 3XX redirects
    syndFeedInfo.setUrl(new URL(urlStr));
    syndFeedInfo.setId(feedUrl.toString());
    Header imHeader = method.getResponseHeader("IM");
    if (imHeader != null && imHeader.getValue().indexOf("feed") >= 0 && isUsingDeltaEncoding()) {
        FeedFetcherCache cache = getFeedInfoCache();
        if (cache != null && statusCode == 226) {
            // client is setup to use http delta encoding and the server supports it and has returned a delta encoded response
            // This response only includes new items
            SyndFeedInfo cachedInfo = cache.getFeedInfo(feedUrl);
            if (cachedInfo != null) {
                SyndFeed cachedFeed = cachedInfo.getSyndFeed();
                // set the new feed to be the orginal feed plus the new items
                feed = combineFeeds(cachedFeed, feed);
            }
        }
    }
    Header lastModifiedHeader = method.getResponseHeader("Last-Modified");
    if (lastModifiedHeader != null) {
        syndFeedInfo.setLastModified(lastModifiedHeader.getValue());
    }
    Header eTagHeader = method.getResponseHeader("ETag");
    if (eTagHeader != null) {
        syndFeedInfo.setETag(eTagHeader.getValue());
    }
    syndFeedInfo.setSyndFeed(feed);
    return syndFeedInfo;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeedInfo(com.sun.syndication.fetcher.impl.SyndFeedInfo) FeedFetcherCache(com.sun.syndication.fetcher.impl.FeedFetcherCache) URL(java.net.URL)

Example 4 with SyndFeed

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

the class FeedEntriesAtomBodyWriterTest method testWriteTo.

@Test
public void testWriteTo() throws Exception {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    testedClass.writeTo(feedEntries(), null, null, null, null, null, outputStream);
    SyndFeedInput input = new SyndFeedInput();
    InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    SyndFeed feed = input.build(new InputSource(inputStream));
    feed.setFeedType("atom_1.0");
    feed.setTitle("Combined Feed");
    feed.setDescription("Combined Feed created by a feed-combiner application");
    assertEquals("atom_1.0", feed.getFeedType());
    assertEquals("Combined Feed", feed.getTitle());
    assertEquals("Combined Feed created by a feed-combiner application", feed.getDescription());
    @SuppressWarnings("unchecked") List<SyndEntry> entries = feed.getEntries();
    assertEquals(2, entries.size());
    for (SyndEntry entry : entries) {
        if (TITLES[0].equals(entry.getTitle())) {
            assertEquals(entry.getLink(), LINKS[0]);
            assertEquals(entry.getTitle(), TITLES[0]);
            assertEquals(entry.getDescription().getValue(), DESCS[0]);
            assertEquals(entry.getPublishedDate().toString(), DATE.toString());
        } else {
            assertEquals(entry.getLink(), LINKS[1]);
            assertEquals(entry.getTitle(), TITLES[1]);
            assertEquals(entry.getDescription().getValue(), DESCS[1]);
            assertEquals(entry.getPublishedDate().toString(), DATE.toString());
        }
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 5 with SyndFeed

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

the class RssEndpoint method createExchange.

@Override
public Exchange createExchange(Object feed, Object entry) {
    Exchange exchange = createExchangeWithFeedHeader(feed, RssConstants.RSS_FEED);
    SyndFeed newFeed;
    try {
        newFeed = (SyndFeed) ((SyndFeed) feed).clone();
        newFeed.setEntries(Arrays.asList(entry));
    } catch (CloneNotSupportedException e) {
        LOG.debug("Could not create a new feed. This exception will be ignored.", e);
        newFeed = null;
    }
    exchange.getIn().setBody(newFeed);
    return exchange;
}
Also used : Exchange(org.apache.camel.Exchange) SyndFeed(com.sun.syndication.feed.synd.SyndFeed)

Aggregations

SyndFeed (com.sun.syndication.feed.synd.SyndFeed)89 ArrayList (java.util.ArrayList)28 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)25 TestDefinition (com.github.redhatqe.polarize.metadata.TestDefinition)16 ImplementsNitrateTest (com.redhat.qe.auto.tcms.ImplementsNitrateTest)16 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)16 Test (org.testng.annotations.Test)16 Test (org.junit.Test)11 SkipException (org.testng.SkipException)11 BugzillaAPIException (com.redhat.qe.auto.bugzilla.BugzillaAPIException)10 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)10 URL (java.net.URL)10 FeedException (com.sun.syndication.io.FeedException)9 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)9 IOException (java.io.IOException)9 Date (java.util.Date)9 HashMap (java.util.HashMap)8 ConsumerCert (rhsm.data.ConsumerCert)8 XmlReader (com.sun.syndication.io.XmlReader)7 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)6