From 96c1956f36a5e8b442be41a2d99c0f2d508476ba Mon Sep 17 00:00:00 2001 From: Tomasz Zarna Date: Sat, 2 Sep 2017 00:41:14 +0200 Subject: [PATCH] Fixes #1, do not use deprecated rome fetcher see https://github.com/rometools/rome/issues/276 --- pom.xml | 6 +++ .../allegro/webapi/WebapiChangelogTest.java | 48 ++++++------------- 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index 0eb7d31..6427976 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,12 @@ 1.7.4 test + + org.apache.httpcomponents + httpclient + 4.5.3 + test + diff --git a/src/test/java/com/github/zaza/allegro/webapi/WebapiChangelogTest.java b/src/test/java/com/github/zaza/allegro/webapi/WebapiChangelogTest.java index 3e921b2..8ca7134 100644 --- a/src/test/java/com/github/zaza/allegro/webapi/WebapiChangelogTest.java +++ b/src/test/java/com/github/zaza/allegro/webapi/WebapiChangelogTest.java @@ -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 { @@ -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)); } } }