• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket communication external web server (Apache)

 
Rácz György
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Sorry for my bad english! I have got a big problem... I develop struts web application java 6 with apache tomcat. This web application one most important function is read RSS sites. One RSS site (www.ft.com/rss/world) redirected (statusCode = 302), so I connect this site with Socket and send GET /rss/world HTTP/1.0 User-Agent: Wget/1.9.1 message, respose I give RSS site in XML format. This is work fine in sample java programme, but not in web application.
Simple java program source code:


And here is my web application class code:


When the program execute on while ((str = rd.readLine()) != null) { then nothing happend...no exception but my web app not response!

Please help me!
 
Rácz György
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Coders!

I set up socket.setSoTimeout(2000); then I receive java.net.SocketTimeoutException: Read timed out. The socket connected: true and socket closed: false.

How can I read the socket correctly?
How can I handle SocketTimeoutException?

Please help me!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a reason you are using raw sockets?

Why not use the classes in the standard Java library - see the java.net package for classes like HttpURLConnection. This is a class designed to handle all the tricky socket details for you.

Bill
 
Rácz György
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:Is there a reason you are using raw sockets?

Why not use the classes in the standard Java library - see the java.net package for classes like HttpURLConnection. This is a class designed to handle all the tricky socket details for you.

Bill


Hi Bill!

Here is some line from my NewsAction source code. If statusCode = 301 vagy 302 (site redirect) then I need read RSS xml file with Socket.

How I read redirected site with HttpURLConnection?



Thank you! Please post example source code...

Best regards!
 
Rácz György
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
R�cz Gy�rgy wrote:
William Brogden wrote:Is there a reason you are using raw sockets?

Why not use the classes in the standard Java library - see the java.net package for classes like HttpURLConnection. This is a class designed to handle all the tricky socket details for you.

Bill


Hi Bill!

Here is some line from my NewsAction source code. If statusCode = 301 vagy 302 (site redirect) then I need read RSS xml file with Socket.

How I read redirected site with HttpURLConnection?



Thank you! Please post example source code...

Best regards!



Hi Coders!

I found what is the problem...I copy my source code and create a new thick (not a web app) java program, this java code work fine, I received the RSS XML file. Then I comment the following lines in my new thick java application, and I received same IOException: java.net.SocketTimeoutException: Read timed out exception as my web application. So in Apache webapp I can't write my request to the Socket. I dont know why! Can anybody help me? Why I cannot write to the output socket OutputStream?

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(sorry to disturb, but you can fix your display name in My Profile)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic