Search code examples
javarssrss-reader

Unable to read simple RSS feed


I have a simple code that reads RSS feeds. It used to work OK with the given RSS feed, but for some reason stopped working with the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: Invalid document
at com.rometools.rome.io.WireFeedInput.build(WireFeedInput.java:312)
at com.rometools.rome.io.WireFeedInput.build(WireFeedInput.java:234)
at com.rometools.rome.io.SyndFeedInput.build(SyndFeedInput.java:150)

This is the code:

    URL url  = new URL("http://www.dpreview.com/feeds/reviews/latest");
    XmlReader reader = null;
    try {
        reader = new XmlReader(url);
        SyndFeed feeder = new SyndFeedInput().build(reader);
        System.out.println("Feed Title: "+ feeder.getAuthor());
        for (Iterator i = feeder.getEntries().iterator(); i.hasNext();) {
            SyndEntry syndEntry = (SyndEntry) i.next();
            System.out.println(syndEntry.getTitle());
        }
    } finally {
        if (reader != null)
            reader.close();
    }

Anything I am missing?


Solution

  • Problem with URL. Responds with Object moved to <a href="https://www.dpreview.com/feeds/reviews/latest">here</a>. That is why exception Invalid document.

    That means that XmlReader does not support 304 redirects.

    So if you fix your URL to https instead of http, everything works.

    There was similar issue, which says that, you have to deal with redirects your self.