aspose file tools*
The moose likes Servlets and the fly likes Problem grabbing RSS from a website and displaying it from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem grabbing RSS from a website and displaying it from servlet" Watch "Problem grabbing RSS from a website and displaying it from servlet" New topic
Author

Problem grabbing RSS from a website and displaying it from servlet

William Farrugia
Greenhorn

Joined: Apr 30, 2011
Posts: 8
Hi,

I'm having some problems when trying to grab RSS feed from a website and display it from a servlet. My servlet runs perfectly on my development machine at home, but fails with this error on the server (CentOS)



My code is as follows:


The website I'm trying to access is http://www.timesofmalta.com/rss

At home I'm running Tomcat 6.0 and on the server Tomcat 5.

At first I suspected the problem might be policy related. (Happened to me on a different server in the past) so I tried to grant access



But that just didn't work.

Any help appreciated

William
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42634
    
  65
I don't think it's a permission problem - the request clearly goes out, but is considered incorrect by the server (that's what a 400 response means). A "curl http://www.timesofmalta.com/rss" retrieves the feed fine for me, so this is odd.

By the way, the feed is in UTF-8, so unless your platform default encoding is UTF-8 (and it may well not be), new InputStreamReader(u.getInputStream()) will get you into trouble; use new InputStreamReader(u.getInputStream(), "UTF-8") instead.

You could also use the ROME library; it's the standard Java library for dealing with RSS.


Ping & DNS - my free Android networking tools app
William Farrugia
Greenhorn

Joined: Apr 30, 2011
Posts: 8
Hello!

Thanks for your replied. I tried adding UTF-8 but didn't solve the problem. It still works on my platform but it doesn't on the server. However you did put me in the right direction. Convinced the policies were OK, I tried switching off IPTables on the server, and guess what... it worked!

So now I will try and fix the iptables instead.

Thanks a lot for your help

William
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42634
    
  65
You're welcome.

I tried adding UTF-8 but didn't solve the problem.

It wasn't supposed to; that was just an additional problem I noticed with the code that needed to be addressed.
William Farrugia
Greenhorn

Joined: Apr 30, 2011
Posts: 8
Ulf Dittmer wrote:It wasn't supposed to; that was just an additional problem I noticed with the code that needed to be addressed.


Sorry I misunderstood then

I had some 8080 to port 80 redirections that were mistakenly added to the output chain on IP tables. I commented out



and it works.

Thanks and regards

William
 
 
subject: Problem grabbing RSS from a website and displaying it from servlet