syndFeedInfo = new SyndFeedInfo(); syndFeedInfo.setUrl(new URL(urlStr)); syndFeedInfo.setId(feedUrl.toString()); final SyndFeed cachedFeed = cachedInfo.getSyndFeed(); syndFeedInfo.setLastModified(lastModifiedHeader.getValue()); syndFeedInfo.setETag(eTagHeader.getValue()); syndFeedInfo.setSyndFeed(feed);
public DeltaSyndFeedInfo(final SyndFeedInfo backingFeedInfo) { setETag(backingFeedInfo.getETag()); setId(backingFeedInfo.getId()); setLastModified(backingFeedInfo.getLastModified()); setSyndFeed(backingFeedInfo.getSyndFeed()); }
/** * <p> * Set appropriate HTTP headers, including conditional get and gzip encoding headers * </p> * * @param connection A URLConnection * @param syndFeedInfo The SyndFeedInfo for the feed to be retrieved. May be null * @param userAgent the name of the user-agent to be placed in HTTP-header. */ protected void setRequestHeaders(final URLConnection connection, final SyndFeedInfo syndFeedInfo, final String userAgent) { if (syndFeedInfo != null) { // set the headers to get feed only if modified // we support the use of both last modified and eTag headers if (syndFeedInfo.getLastModified() != null) { final Object lastModified = syndFeedInfo.getLastModified(); if (lastModified instanceof Long) { connection.setIfModifiedSince((Long) syndFeedInfo.getLastModified()); } } if (syndFeedInfo.getETag() != null) { connection.setRequestProperty("If-None-Match", syndFeedInfo.getETag()); } } // header to retrieve feed gzipped connection.setRequestProperty("Accept-Encoding", "gzip"); connection.addRequestProperty("User-Agent", userAgent); if (isUsingDeltaEncoding()) { connection.addRequestProperty("A-IM", "feed"); } }
public void callback(final String callbackPath, final SyndFeed feed) { if (!callbackPath.startsWith(callbackPrefix)) { throw new HttpStatusCodeException(404, "Not a valid callback prefix.", new Exception(callbackPath + " doesnt start with " + callbackPrefix)); } final String id = callbackPath.substring(callbackPrefix.length()); LOG.debug("Got callback for {}", id); final Subscription s = dao.findById(id); if (s == null) { throw new HttpStatusCodeException(404, "Not a valid callback.", null); } validateLink(feed, s.getSourceUrl()); SyndFeedInfo info = null; URL url = null; try { url = new URL(s.getSourceUrl()); info = cache.getFeedInfo(url); } catch (final MalformedURLException ex) { LOG.error("Malformed URL", ex); } if (info == null) { info = new SyndFeedInfo(); info.setId(s.getId()); info.setUrl(url); } info.setLastModified(System.currentTimeMillis()); info.setSyndFeed(feed); cache.setFeedInfo(url, info); s.getCallback().onNotify(s, info); }
@Override public SyndFeed retrieveFeed(URL feedUrl) throws IOException, FeedException, com.rometools.fetcher.FetcherException { Assert.notNull(feedUrl, "feedUrl must not be null"); URLConnection connection = feedUrl.openConnection(); com.rometools.fetcher.impl.SyndFeedInfo syndFeedInfo = new com.rometools.fetcher.impl.SyndFeedInfo(); this.refreshFeedInfo(feedUrl, syndFeedInfo, connection); return syndFeedInfo.getSyndFeed(); }
method.setRequestHeader("If-None-Match", syndFeedInfo.getETag()); final Object lastModifiedHeader = syndFeedInfo.getLastModified(); if (lastModifiedHeader instanceof String) { method.setRequestHeader("If-Modified-Since", (String) lastModifiedHeader); feed = syndFeedInfo.getSyndFeed();
/** * Gets a filtered version of the SyndFeed that only has entries that were changed in the last * setSyndFeed() call. * * @return */ @Override public synchronized SyndFeed getSyndFeed() { try { final SyndFeed feed = (SyndFeed) super.getSyndFeed().clone(); final List<SyndEntry> changedEntries = new ArrayList<SyndEntry>(); final List<SyndEntry> entries = feed.getEntries(); for (final SyndEntry entry : entries) { if (changedMap.containsKey(entry.getUri())) { changedEntries.add(entry); } } feed.setEntries(changedEntries); return feed; } catch (final CloneNotSupportedException ex) { throw new RuntimeException(ex); } }
/** * Overrides super class method to update changedMap and entryTagsMap for tracking changed * entries. * * @param feed */ @Override public final synchronized void setSyndFeed(final SyndFeed feed) { super.setSyndFeed(feed); changedMap.clear(); final List<SyndEntry> entries = feed.getEntries(); for (final SyndEntry entry : entries) { final String currentEntryTag = computeEntryTag(entry); final String previousEntryTag = entryTagsMap.get(entry.getUri()); if (previousEntryTag == null || !currentEntryTag.equals(previousEntryTag)) { // Entry has changed changedMap.put(entry.getUri(), Boolean.TRUE); } entryTagsMap.put(entry.getUri(), currentEntryTag); } }
try { SyndFeedInfo feedInfo = feedCache.getFeedInfo(new URL(newSub.getFeedURL())); if(feedInfo.getLastModified() != null) { long lastUpdatedLong = (Long) feedInfo.getLastModified(); if (lastUpdatedLong != 0) { newSub.setLastUpdated(new Date(lastUpdatedLong));
public void callback(final String callbackPath, final SyndFeed feed) { if (!callbackPath.startsWith(callbackPrefix)) { throw new HttpStatusCodeException(404, "Not a valid callback prefix.", new Exception(callbackPath + " doesnt start with " + callbackPrefix)); } final String id = callbackPath.substring(callbackPrefix.length()); LOG.debug("Got callback for {}", id); final Subscription s = dao.findById(id); if (s == null) { throw new HttpStatusCodeException(404, "Not a valid callback.", null); } validateLink(feed, s.getSourceUrl()); SyndFeedInfo info = null; URL url = null; try { url = new URL(s.getSourceUrl()); info = cache.getFeedInfo(url); } catch (final MalformedURLException ex) { LOG.error("Malformed URL", ex); } if (info == null) { info = new SyndFeedInfo(); info.setId(s.getId()); info.setUrl(url); } info.setLastModified(System.currentTimeMillis()); info.setSyndFeed(feed); cache.setFeedInfo(url, info); s.getCallback().onNotify(s, info); }
syndFeedInfo = new SyndFeedInfo(); retrieveAndCacheFeed(feedUrl, syndFeedInfo, httpConnection); } else { return syndFeedInfo.getSyndFeed(); } finally { httpConnection.disconnect();
private SyndFeed getFeed(final SyndFeedInfo syndFeedInfo, final String urlStr, final HttpMethod method, final 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(); } final SyndFeed feed = retrieveFeed(urlStr, method); fireEvent(FetcherEvent.EVENT_TYPE_FEED_RETRIEVED, urlStr, feed); return feed; }
/** * Overrides super class method to update changedMap and entryTagsMap for tracking changed * entries. * * @param feed */ @Override public final synchronized void setSyndFeed(final SyndFeed feed) { super.setSyndFeed(feed); changedMap.clear(); final List<SyndEntry> entries = feed.getEntries(); for (final SyndEntry entry : entries) { final String currentEntryTag = computeEntryTag(entry); final String previousEntryTag = entryTagsMap.get(entry.getUri()); if (previousEntryTag == null || !currentEntryTag.equals(previousEntryTag)) { // Entry has changed changedMap.put(entry.getUri(), Boolean.TRUE); } entryTagsMap.put(entry.getUri(), currentEntryTag); } }
protected void resetFeedInfo(final URL orignalUrl, final SyndFeedInfo syndFeedInfo, final HttpURLConnection connection) throws IllegalArgumentException, IOException, FeedException { syndFeedInfo.setUrl(connection.getURL()); syndFeedInfo.setId(orignalUrl.toString()); syndFeedInfo.setLastModified(connection.getLastModified()); syndFeedInfo.setETag(connection.getHeaderField("ETag")); final SyndFeed cachedFeed = cachedInfo.getSyndFeed(); syndFeedInfo.setSyndFeed(syndFeed); } finally { IO.close(inputStream);
private void refreshFeedInfo(URL feedUrl, com.rometools.fetcher.impl.SyndFeedInfo syndFeedInfo, URLConnection connection) throws IOException, FeedException { // need to always set the URL because this may have changed due to 3xx redirects syndFeedInfo.setUrl(connection.getURL()); // the ID is a persistent value that should stay the same // even if the URL for the feed changes (eg, by 3xx redirects) syndFeedInfo.setId(feedUrl.toString()); // This will be 0 if the server doesn't support or isn't setting the last modified header syndFeedInfo.setLastModified(connection.getLastModified()); // get the contents InputStream inputStream = null; try { inputStream = connection.getInputStream(); SyndFeed syndFeed = this.readFeedFromStream(inputStream, connection); syndFeedInfo.setSyndFeed(syndFeed); } finally { try { inputStream.close(); } catch (Exception e) { // ignore } } }
public DeltaSyndFeedInfo(final SyndFeedInfo backingFeedInfo) { setETag(backingFeedInfo.getETag()); setId(backingFeedInfo.getId()); setLastModified(backingFeedInfo.getLastModified()); setSyndFeed(backingFeedInfo.getSyndFeed()); }
syndFeedInfo = new SyndFeedInfo(); retrieveAndCacheFeed(feedUrl, syndFeedInfo, httpConnection); } else { return syndFeedInfo.getSyndFeed(); } finally { httpConnection.disconnect();
/** * Gets a filtered version of the SyndFeed that only has entries that were changed in the last * setSyndFeed() call. * * @return */ @Override public synchronized SyndFeed getSyndFeed() { try { final SyndFeed feed = (SyndFeed) super.getSyndFeed().clone(); final List<SyndEntry> changedEntries = new ArrayList<SyndEntry>(); final List<SyndEntry> entries = feed.getEntries(); for (final SyndEntry entry : entries) { if (changedMap.containsKey(entry.getUri())) { changedEntries.add(entry); } } feed.setEntries(changedEntries); return feed; } catch (final CloneNotSupportedException ex) { throw new RuntimeException(ex); } }