This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes HttpURLConnection.connect() times out, while wget works fine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HttpURLConnection.connect() times out, while wget works fine" Watch "HttpURLConnection.connect() times out, while wget works fine" New topic
Author

HttpURLConnection.connect() times out, while wget works fine

Ruben Matthews
Greenhorn

Joined: Jan 05, 2009
Posts: 26
Hello Java friends

I have a problem where an application I am working on is throwing the following exception "java.net.ConnectException: Connection timed out" after trying to connect() to a URI.



This small test case outputs

YEEEEHAAAAH
test1

and then stalls....



I tried to "wget" the url from the box the application is running on and that works fine. It returns 200 OK. So, the url is accessible, but still connect() times out.

Any clue why?
Ruben Matthews
Greenhorn

Joined: Jan 05, 2009
Posts: 26
I just talked to our network admin and he explained to me it is caused by the fact that the application (tomcat) is not going through the proxy. Problem is solved.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Well done solving it, and thank you for giving a solution; it will be helpful if anybody else has a similar problem ever.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

It's a good thing URL has an openConnection(Proxy) method


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HttpURLConnection.connect() times out, while wget works fine
 
Similar Threads
Problem while using HttpURLConnection
POSTing from applet to servlet
Connection timed out when server is present in a far off place
client request to server using HttpURLConnection
Socket communication external web server (Apache)