Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fetcher] Deprecation and removal of ROME Fetcher #276

Closed
PatrickGotthard opened this issue Mar 4, 2016 · 3 comments
Closed

[fetcher] Deprecation and removal of ROME Fetcher #276

PatrickGotthard opened this issue Mar 4, 2016 · 3 comments

Comments

@PatrickGotthard
Copy link
Member

Hi @ALL,

we decided to mark all ROME Fetcher classes as deprecated in version 1.6 and to drop it completely in version 2.0. ROME Fetcher was useful some years ago when internet connections were slow and expensive, because it supports ETags, GZip compression, RFC3229 delta encoding and caching.

Nowadays there are libraries like the well known Apache HttpClient. It supports ETags and GZip compression out-of-the-box, delta encoding seems to be used very rarely and there are also much better caching solutions (like EhCache) compared to our simple file and in-memory based implementations.

In addition, ROME fetcher is not flexible enough for many use-cases because the user has no full control over the underlying HTTP connection and sometimes even new ROME functionalities cannot be used without updating ROME Fetcher too.

Last but not least, the most comprehensive ROME Fetcher implementation (HttpClientFeedFetcher) uses Apache HttpClient in version 3 that has some security vulnerabilities. We are not able to update it to version 4 without breaking backwards compatiblity and simply removing the implementation in version 1.6 was not an option for us.

We hope you support our decision. It will help us to become faster and to concentrate on the core features.

Please give us some feedback, especially when you don't support our decision!

Regards,
Patrick

@PatrickGotthard PatrickGotthard added this to the Version 1.6.0 milestone Mar 4, 2016
@PatrickGotthard PatrickGotthard changed the title Deprecation and removal of ROME Fetcher [fetcher] Deprecation and removal of ROME Fetcher Mar 4, 2016
mishako added a commit that referenced this issue Mar 4, 2016
#276 added deprecation notice to rome-fetcher
@mishako
Copy link
Member

mishako commented Mar 5, 2016

Here is a migration example. This is how you used to retrieve a feed with rome-fetcher:

URL url = new URL("http://stackoverflow.com/feeds/tag?tagnames=rome");
FeedFetcher feedFetcher = new HttpClientFeedFetcher();
SyndFeed feed = feedFetcher.retrieveFeed(url);
System.out.println(feed.getTitle());

This is how you do the same thing with Apache HttpClient 4:

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.5.2</version>
</dependency>
String url = "http://stackoverflow.com/feeds/tag?tagnames=rome";
try (CloseableHttpClient client = HttpClients.createMinimal()) {
  HttpUriRequest request = new HttpGet(url);
  try (CloseableHttpResponse response = client.execute(request);
       InputStream stream = response.getEntity().getContent()) {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(stream));
    System.out.println(feed.getTitle());
  }
}

It's a bit more code, but on the upside, you get to configure every detail of the request.

Edit 1: try-with-resources for http client
Edit 2: renamed method to request

@mishako mishako removed this from the Version 1.6.0 milestone Jul 15, 2016
@mishako mishako closed this as completed Jun 3, 2017
zaza added a commit to zaza/allegro-webapi that referenced this issue Sep 1, 2017
matwood pushed a commit to bibliolabs/rome that referenced this issue May 18, 2018
Certiorem and Propono depend on rome-fetcher which is now deprecated and
will be removed in the next major version (see rometools#276).
@idalv
Copy link

idalv commented Jan 17, 2019

Here is how you could pull a feed with Spring's RestTemple. Hope it helps someone:

        RestTemplate restTemplate = new RestTemplate();
        SyndFeed syndFeed = restTemplate.execute(feedUrl, HttpMethod.GET, null, response -> {
            SyndFeedInput input = new SyndFeedInput();
            try {
                return input.build(new XmlReader(response.getBody()));
            } catch (FeedException e) {
                throw new IOException("Could not parse response", e);
            }
        });

sgothel added a commit to JogAmp/Hungry-Harry that referenced this issue May 14, 2019
See rometools/rome#276

This still has issues w/ empty streams (Premature EOS)
and the code snippet in above issue 276 is to replace
rome's HttpClientFeedFetcher w/ apache's CloseableHttpClient.
However, we are originally using rome's HttpURLFeedFetcher.
@dimi-nk
Copy link

dimi-nk commented Nov 24, 2019

In case this helps anyone, an example using Java's HttpClient:

private static final String FEED_URL = "https://stackoverflow.com/feeds/tag?tagnames=rome";

private static SyndFeed bodyToFeed(InputStream body) {
  try {
    return new SyndFeedInput().build(new XmlReader(body));
  } catch (FeedException | IOException e) {
    throw new CompletionException(e);
  }
}

private static List<String> getEntryTitles(SyndFeed feed) {
  return feed.getEntries().stream().map(SyndEntry::getTitle).collect(toList());
}

public CompletableFuture<List<String>> getTitles() {
  HttpClient client = HttpClient.newHttpClient();
  HttpRequest request = HttpRequest.newBuilder().uri(URI.create(FEED_URL)).build();
  return client
      .sendAsync(request, BodyHandlers.ofInputStream())
      .thenApply(HttpResponse::body)
      .thenApply(RssReader::bodyToFeed)
      .thenApply(RssReader::getEntryTitles)
      .orTimeout(2, SECONDS)
      .exceptionally(
          t -> {
            log.error(format("Could not fetch feed from '%s'", FEED_URL), t);
            return emptyList();
          });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants