Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
Fixes #1, do not use deprecated rome fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
zaza committed Sep 1, 2017
1 parent 16ce555 commit 96c1956
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -76,6 +76,12 @@
<version>1.7.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
Expand Down
Expand Up @@ -3,22 +3,22 @@
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.net.URL;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.junit.Test;

import com.rometools.fetcher.FeedFetcher;
import com.rometools.fetcher.FetcherEvent;
import com.rometools.fetcher.FetcherException;
import com.rometools.fetcher.FetcherListener;
import com.rometools.fetcher.impl.FeedFetcherCache;
import com.rometools.fetcher.impl.HashMapFeedInfoCache;
import com.rometools.fetcher.impl.HttpURLFeedFetcher;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.XmlReader;

public class WebapiChangelogTest {

Expand All @@ -32,34 +32,16 @@ private Date lastTimeSourcesGenerated() throws ParseException {
return new SimpleDateFormat("yyyy-MM-dd").parse("2017-08-21");
}

private Date latestChangelogEntryPublished()
throws IllegalArgumentException, IOException, FeedException, FetcherException {
private Date latestChangelogEntryPublished() throws IllegalArgumentException, IOException, FeedException {
return fetchFeed("http://allegro.pl/rss.php/webapi?all=0").getEntries().iterator().next().getPublishedDate();
}

/*
* https://github.com/rometools/rome-fetcher/blob/master/src/test/java/com/rometools/fetcher/samples/FeedReader.java
*/
private SyndFeed fetchFeed(String url)
throws IllegalArgumentException, IOException, FeedException, FetcherException {
URL feedUrl = new URL(url);
FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance();
FeedFetcher fetcher = new HttpURLFeedFetcher(feedInfoCache);
FetcherEventListenerImpl listener = new FetcherEventListenerImpl();
fetcher.addFetcherEventListener(listener);
return fetcher.retrieveFeed(feedUrl);
}

static class FetcherEventListenerImpl implements FetcherListener {
@Override
public void fetcherEvent(final FetcherEvent event) {
final String eventType = event.getEventType();
if (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) {
System.err.println("\tEVENT: Feed Polled. URL = " + event.getUrlString());
} else if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals(eventType)) {
System.err.println("\tEVENT: Feed Retrieved. URL = " + event.getUrlString());
} else if (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals(eventType)) {
System.err.println("\tEVENT: Feed Unchanged. URL = " + event.getUrlString());
private SyndFeed fetchFeed(String url) throws IllegalArgumentException, IOException, FeedException {
try (CloseableHttpClient client = HttpClients.createMinimal()) {
HttpUriRequest request = new HttpGet(url);
try (CloseableHttpResponse response = client.execute(request);
InputStream stream = response.getEntity().getContent()) {
return new SyndFeedInput().build(new XmlReader(stream));
}
}
}
Expand Down

0 comments on commit 96c1956

Please sign in to comment.