| Author |
Socket communication external web server (Apache)
|
Rácz György
Greenhorn
Joined: Nov 12, 2008
Posts: 19
|
|
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
Joined: Nov 12, 2008
Posts: 19
|
|
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
Joined: Mar 22, 2000
Posts: 12266
|
|
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
|
Java Resources at www.wbrogden.com
|
 |
Rácz György
Greenhorn
Joined: Nov 12, 2008
Posts: 19
|
|
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
Joined: Nov 12, 2008
Posts: 19
|
|
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
Joined: Nov 24, 2005
Posts: 14670
|
|
|
(sorry to disturb, but you can fix your display name in My Profile)
|
[My Blog]
All roads lead to JavaRanch
|
 |
 |
|
|
subject: Socket communication external web server (Apache)
|
|
|