1

I'm doing project using struts1. I'm fetching RSS feeds using ROME but it fails for two conditions:

  1. When my firewall forbidden rss url (response code 403)
  2. When I insert incorrect rss url

To avoid such conditions what should I do?

Peter Svensson
  • 6,105
  • 1
  • 31
  • 31
Coder Guru
  • 513
  • 3
  • 18
  • 37

3 Answers3

0

About 403
Some feeds seems have some protection (for DDOS) So based on user Agent (in your case "Java") they deny you to read the feed So you have to set your own user agent (like the firefox user agent), before opening connection like this

 System.setProperty("http.agent", USER_AGENT);
 URLConnection openConnection = url.openConnection();
 is = url.openConnection().getInputStream();
 if ("gzip".equals(openConnection.getContentEncoding())) {
     is = new GZIPInputStream(is);
 }
 InputSource source = new InputSource(is);
 input = new SyndFeedInput();
 syndicationFeed = input.build(source);
 XmlReader reader = new XmlReader(url);
 syndicationFeed = input.build(reader);

My current USER_AGENT String is
"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0";

Christ-OFF
  • 434
  • 7
  • 21
0

Just catch the exceptions and handle them.

Kai
  • 38,985
  • 14
  • 88
  • 103
0

There are some situations you simply cannot avoid.

You can't avoid network outages, you can't avoid incorrectly typed URLs.

What you can do, however, is check if network is reachable, and whether the URL is typed correctly or not.

You should catch the exceptions and provide meaningful error messages to the user.

Mahmoud Hanafy
  • 7,958
  • 12
  • 47
  • 62